Android Studio的自带Gradle版本是4.1,插件版本是3.0.0,所以如果你使用的是老版本,就会出现一些小的兼容问题,我们看看报了哪些错误呢:
问题1
Error:(72, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=appDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
outputFile是只读属性,不可以对他进行修改
看一下我的gradle里面的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
这段代码的功能是修改Build命令生成的apk的名称,因为outputFile变成只读属性,所以报错。
修改后:
1 2 3 4 5 6 7 8 9 10 |
|
把each修改为all,然后通过outputFileName修改生成的apk的名称。
如果你提示没有找到all方法或者是未找到outputFileName,你可以先把这个功能注释掉,等其他问题都解决了,再打开就可以解决这个问题了。
问题2
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
所有的flavor属性应当属于同一个命名空间
看着问题似乎有点深奥,其实就是需要我们为flavors设置一个版本,统一使用相同版本的flavors。
1 2 3 4 5 6 7 8 |
|
问题3
有些库不能被正常引用,例如我使用的multidex,在上面的截图中已经提示我们如何解决这个问题
1 2 3 4 5 6 7 8 9 10 |
|
问题4
Error:(2638) error: style attribute '@android:attr/windowEnterAnimation' not found.
提示我们找不到@android:attr/windowEnterAnimation,因为已经不支持@开头使用android自带的属性,我们只要把@符号删掉就可以了。
修改前:
1 2 3 4 |
|
修改后:
1 2 3 4 |
|
问题5
Error:Execution failed for task ':app:javaPreCompileAppDebug'.
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-6.1.0.jar (com.jakewharton:butterknife:6.1.0)
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.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
好多的错误日志啊,其实最关键的只有前两行:
使用注解编译库,需要显示的声明,而我正在使用的butterknife是含有注解编译功能的,但是并没有声明。
解决办法:
1 2 3 4 5 6 7 8 |
|
问题6:
Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error:
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
- 在项目的gradle.properties中:
android.enableAapt2=false
其他的变化
通过刚才的修改,我的工程已经运行起来了,但是发现了Android Studio 3.0 的几个小变化。
变化1
Warning:One of the plugins you are using supports Java 8 language features. To try the support built into the Android plugin, remove the following from your build.gradle:
apply plugin: 'me.tatarka.retrolambda'
从警告上看,希望我移除这个插件,于是我到官网上查看了一下信息:
If Android Studio detects that your project is using Jack, Retrolambda, or DexGuard, the IDE uses Java 8 support provided by those tools instead.
如果Android Studio发现你的工程中使用Jack ,Retrolambda 或DexGuard,编辑器会使用Java8支持,替换这个工具。
因为我使用me.tatarka.retrolambda第三方框架,所以就出现了这个,我们只要删除相关的配置就可以了。
变化2
提示有更高版本你的第三方框架:
上面的截图显示,gson有更高的版本2.8.3,提示我升级gson。这就省去了我们去github上查看是否版本更新的时间,非常的方便。
总结
这就是我今天遇到的问题及解决方案,如果之后有更多问题再补充。
欢迎小伙伴们加入 技术交流群: 168786059
加群请备注(技术交流)