Android Gradle 更新到 3.4.1 问题记录
ps:有些问题是都会出现的,一些是项目自身导致的可忽略
1、多渠道打包会出现问题
属性不能用的问题
groovy.lang.GroovyRuntimeException: Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=xiaomiDebug, filters=[], versionCode=3256, versionName=6.2.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
outputFile这个属性不能用了
3.0以前一般都这样写
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为news_v1.0_2017-01-15_wandoujia.apk
def fileName = "news_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
属性不能用了就要修改一下,这里要改两个地方
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为news_v1.0_2017-01-15_wandoujia.apk
def fileName = "news_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
outputFileName = fileName
}
}
}
完事你可能还会出现
打包维度不统一的问题
All flavors must now belong to a named flavor dimension
这个只需要在 defaultConfig {}里面添加上统一的维度就行了
efaultConfig {
flavorDimensions "xxx"
}
2、之后就是提示你修改 complie 、testCompile、apt、等等
WARNING: Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.
最后还有几个自身项目中导致的问题
1 、Cannot create variant ‘android-aidl’ after configuration’:xxxxxxxx:debugApiElements’ has been resolved
这个是因为一个module 里面有
classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
用dofist{}包起来就好了
doFirst {
classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
}
2 、Failed to transform file ‘xxxxx.jar’ to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars}
你所依赖的jar包或者其他第三方库不存在或者不正确。这个错误其很简单,就是你引用的jar包路径错了、版本错了或者不存在,检查一下改改就行了