老项目gradle2.3.3升级4.0,一步一个坑

项目用了androidannotations,最近怎么构建都构建不成功,去官网一看说是

AndroidAnnotations is deprecated. No more development will be taking place.

Thanks for all your support!

唉,版本号永远停留在4.8.0了。
人家没有修改看来就是自己的问题,项目16年构建的,gradle还是2.3,狠狠心升个级吧就。

1.去除apt

apt "org.androidannotations:androidannotations:$AAVersion"
修改成
annotationProcessor "org.androidannotations:androidannotations:$AAVersion

去除app gradle里面的

apply plugin: 'android-apt'

apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
        resourcePackageName 'com.zhaomi.wisdomstudy'
}

去除project gradle里面的

 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

2.Could not HEAD 'http://dl.bintray.com/populov/maven/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.72/kotlin-stdlib-jdk8-1.3.72.pom'. Received status code 502 from server: Bad Gateway

把project gradle里面的

 maven { url "http://dl.bintray.com/populov/maven" }

注释,添加了阿里云的代理,走代理

maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }

3.Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=xiaomiDebug, filters=[], versionCode=232, versionName=2.3.3.1}} 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')) {
            def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.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')) {
            def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
            outputFileName = fileName
        }
    }
}

4.The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.

在manifest里面

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="29"
    tools:overrideLibrary="com.huawei.android.hms.base,com.huawei.android.hms.push , cn.jpush.android.thirdpush.meizu" />

去掉minsdkVersion和targetSdkVersion这两行

5.All flavors must now belong to a named flavor dimension.

app gradle里面的defaultConfig{}里加入

flavorDimensions "versionCode"

6.Failed to parse XML in /Users/zp_lxy/Desktop/project///app/src/main/AndroidManifest.xml
ParseError at [row,col]:[37,5]

定位一下发现是因为之前在manifest里面用的注释方式是“//”,现在不支持了,修改下

7.> Task :app:compileXiaomiDebugJavaWithJavac
The following annotation processors are not incremental: androidannotations-4.6.0.jar (org.androidannotations:androidannotations:4.6.0).
Make sure all annotation processors are incremental to improve your build speed.

在 app gradle里面

javaCompileOptions {
    annotationProcessorOptions {
        arguments = [
                "androidManifestFile": "$projectDir/src/main/AndroidManifest.xml".toString()
        ]
    }
}

再编译没有问题,运行成功。

猜你喜欢

转载自blog.csdn.net/u010055598/article/details/125479683