Android as升级到最新版本存在的问题(gradle升级)
classpath 'com.android.tools.build:gradle:3.5.3'
distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip
问题一
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[], versionCode=79, versionName=4.4.0}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
原来的:
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为appname-1.0-beta1-xxxx-xx-xx.apk
def fileName = "zhouse-v${defaultConfig.versionName}-${releaseTime()}-${buildType.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名称为appname-1.0-beta1-xxxx-xx-xx.apk
def fileName = "zhouse-v${defaultConfig.versionName}-${releaseTime()}-${variant.buildType.name}.apk"
outputFileName = fileName
}
}
}
问题二
Unable to find method 'org.gradle.api.Task.deleteAllActions()Lorg/gradle/api/Task;'.
问题描述:
ERROR: Gradle DSL method not found: 'deleteAllActions()'
解决办法:
升级 me.tatarka:gradle-retrolambda
//修改前
classpath 'me.tatarka:gradle-retrolambda:3.3.1'
//修改后
classpath 'me.tatarka:gradle-retrolambda:3.7.1'
问题三
ERROR: Unable to resolve dependency for ':@toTest/compileClasspath': Could not resolve project :library.
image.png
问题大致原因:
我在主工程中设置了
buildTypes {
release {
}
debug {
}
toTest {
}
}
如果有其他的module,其它module的build.gradle中也必须包含这个buildtypes,空着也行。否则会报错
刚好我引入了library 库,所以也需要在library 里面加入对应的buildTypes
解决方案:
在library的build.gradle里面加入和主工程相同的buildTypes即可,我直接空着,配置写在主工程啦~¬
buildTypes {
release {
}
debug {
}
toTest {
}
}
网友评论