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包路径错了、版本错了或者不存在,检查一下改改就行了

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值