android studio升级3.0版本,问题处理

问题1:编译版本与构建版本修改

compileSdkVersion : 26,
buildToolsVersion : “26.0.2”,
gradle版本:
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
classpath ‘com.android.tools.build:gradle:3.0.0’

问题2:apk名称配置调整,build有一个outputFileName ,直接配置

Error:(120, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
<a href="openFile:D:\Android\workspace_zhy\qufish_office\app\build.gradle">Open File</a>

这里写图片描述

            //输出apk配置
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        // 输出apk名称
                        def fileName
                        if (variant.buildType.zipAlignEnabled) {
                            //正式版本
                            fileName =  "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
                        } else {
                            fileName = "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
                        }
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
                }
            }

调整后

            applicationVariants.all {
                outputs.all {
                    // 输出apk名称
                    def newApkName
                    if (buildType.zipAlignEnabled) {
                        newApkName = "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
                    } else {
                        newApkName = "XX_${defaultConfig.versionName}_${packageTime()}_${buildType.name}.apk"
                    }
                    outputFileName = newApkName
                }
            }

问题3:如果你有配置多渠道包,会报错dimension

//android{}内
flavorDimensions "color"
productFlavors {
        baidu {
//每个渠道多家一个这个配置
            dimension "color"
...
        }
}

问题4:

compile ‘com.android.support:multidex:1.0.1’

仓库位置调整到google,需要在配置仓库的地方加入google()(报错的时候直接点击下也可以自动添加这个仓库),另外multidex的版本号升级到1.0.2

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        google()
    }
}

问题5:

Information:Gradle tasks [:pickerview:generateDebugSources, :pickerview:generateDebugAndroidTestSources, :pickerview:mockableAndroidJar, :zhxflib:generateDebugSources, :zhxflib:generateDebugAndroidTestSources, :zhxflib:mockableAndroidJar, :wigetlib:generateDebugSources, :wigetlib:generateDebugAndroidTestSources, :wigetlib:mockableAndroidJar, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
D:\zhihuixinfanWorkerSpace\ZhiHuiXinFan\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
Error:(12) error: unknown element found.
Error:(12) unknown element found.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ‘:app:processDebugResources’.
Failed to execute aapt
Information:BUILD FAILED in 8s
Information:6 errors
Information:0 warnings
Information:See complete output in console

解决方法:

在项目的gradle.properties中:
android.enableAapt2=false

展开阅读全文

没有更多推荐了,返回首页