老项目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()
        ]
    }
}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
如果你的 Android 项目没有 Gradle 文件,你需要手动创建一个。你可以按照以下步骤进行操作: 1. 在项目根目录下创建一个名为 build.gradle 的文件。 2. 在 build.gradle 文件中添加以下代码: ``` buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.1.0' } } ``` 3. 在项目的 app 目录下创建一个名为 build.gradle 的文件。 4. 在 app/build.gradle 文件中添加以下代码: ``` apply plugin: 'com.android.application' android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.myapplication" minSdkVersion 21 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' } ``` 5. 然后在 Android Studio 中点击 Sync Now 按钮,这将同步 Gradle 文件并构建项目。 如果你仍然遇到问题,可以尝试清除 Gradle 缓存并重新构建项目。可以通过点击菜单栏中的 File -> Invalidate Caches / Restart 进行操作。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值