今天收到了Android Studio3.0更新推送,在升级过程中遇到几个问题,在这里把问题和解决方法记录下,方便要升级的童鞋。如果还有童鞋遇到不同的问题,也可以评论下我做下记录
1.gradle打包,自定义apk名称代码报错(Cannot set the value of read-only property 'outputFile' )
-
报错
Error:(56, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. <a href="openFile:D:\eclipseCode\ipay-android\xinlebao\build.gradle">Open File</a>
-
解决 :修改文件名代码请这样写
android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = "xinlebao_${defaultConfig.versionName}_${releaseTime()}.apk" } }
2. AAPT2 编译报错 AAPT2 error
-
报错
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
-
解决:在gradle.properties中关闭APPT2 编译
android.enableAapt2=false
-
注:如果是eclipse转到as上的项目,可能没有gradle.properties文件,请在项目根目录中手动创建
PS:有童鞋评论说这个问题如何一劳永逸的解决。我查了下资料,as3.0默认使用appt2对图片进行编译,这个问题可能是由于.9图的格式不规范导致,编译后,确定下哪张.9图的问题,最后再用draw9patch编辑保存下即可,当然你也可以选择关闭appt编译。这个问题不是针对所有项目的,而是会出现在.9图有问题的项目中
3.apt插件问题(Error:Cannot choose between the following configurations of project :mylibrary:)
-
报错:
Error:Cannot choose between the following configurations of project :mylibrary: - debugApiElements - debugRuntimeElements - releaseApiElements - releaseRuntimeElements All of them match the consumer attributes:
-
解决
//1.在project的build.gradle中删除 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' //2.在module的build.gradle中删除 apply plugin: 'android-apt' //3.将module的build.gradle文件中的dependency apt 'com.jakewharton:butterknife-compiler:8.1.0' //改为 annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
其他使用apt的依赖,也要这样更改
4.Android Studio3.0 preview已知bug(Error:Unable to find method 'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;'. Possible causes for this unexpected error)
- 报错
Error:Unable to find method 'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;'. Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
- 解决
- 尝试升级kotlin版本,不过该问题可能存在于preview版本中
//在build.gradle文件中将kotlin版本从
ext.kotlin_version = '1.1.2-3'
//改为
ext.kotlin_version = '1.1.2-4'
2.尝试降低Butterknife的版本
//将Butterknife的版本降级为8.4.0
compile 'com.jakewharton:butterknife:8.4.0'
网友评论
android.applicationVariants.all { variant ->
if (variant.getBuildType().name == "debug") {
task "configDevice2${variant.name.capitalize()}" (type: Exec){
dependsOn variant.install
group = 'nameofyourtaskgroup'
description = 'Describe your task here.'
def adb = android.getAdbExe().toString()
def mypermission = 'android.permission.WRITE_EXTERNAL_STORAGE '
commandLine "$adb shell pm grant ${variant.applicationId} $mypermission".split(' ')
}
variant.testVariant.connectedInstrumentTest.dependsOn "configDevice2${variant.name.capitalize()}"
}
}
求助。。。网上都说把 outputs.each 改成outputs.all就好了,可是我没有这个代码啊,粘贴添加进去也还是同样的错 ,谢谢大神
这个问你 加了android.enableAapt2=false 也没有用 还是报错 Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.AaptException