项目从studio2.0.0升级到studio3.1.2遇到的坑

问题一 : Error:All flavors must now belong to a named flavor dimension. Learn more

我是在项目的build.gradle中使用了productFlavors,结果编译时报了如下错误:

提示:Error:All flavors must now belong to a named flavor dimension.Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html 

原因

这个一个错误,意思是:所有的flavors都必须属于同一个风格。

解决方法:

在主app的build.gradle里面,如下图1-1所示添加代码即可


1-1

就直接解决这个问题。然后app 就可以运行起来了。


问题二: The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.

原因

是这里出问题了 instrumentTest.setRoot(‘tests’) ,你可能在升级 Android Studio 时更新了项目的 gradle 配置,这里的配置中 instrumentTest 已被弃用,不适用于现在的 gradle 版本。

解决办法

用 androidTest 替换 instrumentTest,编译运行即可。


问题三:  DSL element 'DexOptions.incremental' is obsolete and will be removed at the end of 2018.

解决办法

在gradle中将DexOptions如下图1-2所示


1-2

删除或者注释就好!


问题四: androidstudio3.1.2使用butterknife报错

报错提示:

Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.- butterknife-7.0.1.jar

 Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.

解决办法

在app的build中android { ... defaultConfig { ... //添加如下配置就OK了javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } } } ...}如下图1-3所示:

1-3

问题五:  transformDexWithInstantRunDependenciesApkForDebug

好不容易build项目可以通过了,结果Run项目时报这个类型的错误transformDexWithInstantRunDependenciesApkForDebug

这个问题我就查找了半天,后来发现原来是setting里面的设置问题:

Settings--->InstantRun ---->去掉第一个条目的对钩就行了。如下图1-4所示:


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容