问题一:
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=commonDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. Open File
解决方案一:
I used this code
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//输出apk名称为:应用名.apk
def fileName = "xxx.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
**Use all() instead of each()
Use outputFileName instead of output.outputFile if you change only file name (that is your case)**
Example from the guide:
// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "xxx.apk"
}
}
问题二:
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
解决方案二:
http://blog.csdn.net/syif88/article/details/75009663
大致是说,Plugin 3.0.0之后有一种自动匹配消耗库的机制,便于debug variant 自动消耗一个库,然后就是必须要所有的flavor 都属于同一个维度。
为了避免flavor 不同产生误差的问题,应该在所有的库模块都使用同一个foo尺寸。
但是我们从中已经知道解决方案了:
在主 app 的 build.gradle 里面的
defaultConfig {
targetSdkVersion:***
minSdkVersion :***
versionCode:***
versionName :***
//版本名后面加句话,意思是flavor dimension 它的维度就是该版本号,
//这样维度就是都是统一的了
**flavorDimensions "versionCode"**
}
问题三:
Error:Execution failed for task ':youyoubao:javaPreCompileCommonDebug'.
> 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-compiler-8.6.0.jar (com.jakewharton:butterknife-compiler:8.6.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.
解决方案三:
在 app 下的 build.gradle 的 defaultConfig 中加一句话:
defaultConfig {
...
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
}