升级到 Android Studio 3.0 + Gradle 4.1 遇到的一些坑及解决方案
16lz
2021-01-23
问题一:
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
解决方案一:
https://stackoverflow.com/questions/44239235/android-gradle-3-0-0-alpha2-plugin-cannot-set-the-value-of-read-only-property
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 } }}
更多相关文章
- Error: Failed to find 'ANDROID_HOME' environment variable.解
- Fragment与FragmentActivity间的数据通讯详细解决方案
- Android Sync 同步 源码问题解决方案
- android中出现javax.net.ssl.SSLPeerUnverifiedException的解决
- Android数据库升级解决方案
- Android无法访问本地服务器(localhost)的解决方案
- android SDK升级连接不上服务器解决方案(安装SDK)
- Android (Android Studio)adb启动失败 无法启动adb 解决方案
- android 程序退出解决方案