打开并运行一个陈旧的Android项目代码

407 阅读2分钟

因为各种原因我司有很多陈旧的Android项目代码,收到任务要求打出来app。代码是17.18年写的,很多连androidx都没用上,不少包也停止维护了,项目代码本身好几年没人维护,一打开果然各种报错,记录一下。

1、gradle 我使用Android Studio Giraffe 2022.3.1 Patch 3,为了省事,将所有项目的gradle同一替换为本地包 gradle下载自:Index of /gradle/ (tencent.com)

//grdale版本
distributionUrl=file:///E:/Android/gradle/gradle-7.5-all.zip
//插件版本
classpath 'com.android.tools.build:gradle:7.2.0'

2、指定国内镜像

allprojects {
    repositories {
        // 改为阿里云的镜像地址
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public' }
        //github插件地址jitpack 地址发生了变化
        maven { url 'https://www.jitpack.io' }
    }
}

记录jitpack下库无法下载的情况_jitpack 镜像-CSDN博客 Jcenter服务即将关闭,改用mavenCentral - 知乎 (zhihu.com)

3、部分代码使用github插件报错,提示jitpack not working PKIX path building failed为认证问题,需要指定jdk版本为studio自带的

android studio设置jdk版本项目设置和全局设置(保姆级图文)_android studio 配置jdk-CSDN博客

image.png

无标题.png

4、Warning:Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and-CSDN博客 解决方法是,在 app 的 Gradle 中: compile 改为 implementation androidTestCompile 改为 androidTestImplementation testCompile 改为 testImplementation 这样替换了过时的,再重新编译即可。

5、Android打包报错:Lint found fatal errors while assembling a release target._lintoptions { checkreleasebuilds false // or, if y-CSDN博客 Aborting build since new baseline file was created

6、import com.google.zxing.Result 报错 我引入的插件zxing版本是

implementation 'com.mylhyl:zxingscanner:1.6.0'
修改为
implementation 'com.mylhyl:zxingscanner:2.2.0'

7、高德地图报错 体现在com.amap.api.services.core相关的包找不到 //高德地图更换为更古早的版本

implementation 'com.amap.api:3dmap:5.6.0'//map3d
implementation 'com.amap.api:search:5.5.0'
implementation 'com.amap.api:location:3.7.0'//定位包

参考文档:mylhyl/Android-Zxing: android google zxing 可配置扫描框、线样式 ,生成二维码(文字、联系人) (github.com)

8、okhttp3包找不到 引入了不维护的com.zhy:okhttputils,改为使用本地包依然报错 Android 使用本地jar包_mob64ca12e732bb的技术博客_51CTO博客 额外引入了 square/okhttp: Square’s meticulous HTTP client for the JVM, Android, and GraalVM. (github.com)

implementation("com.squareup.okhttp3:okhttp:4.12.0")

报错 /gradle/caches/modules-2/files-2.1/com.squareup.okhttp3/okhttp/4.12.0/2f4525d4a200e97e1b87449c2cd9bd2e25b7e8cd/okhttp-4.12.0.jar!/META-INF/okhttp.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

更改为

implementation("com.squareup.okhttp3:okhttp:3.9.1")

9、lint提示

lint {
    baseline = file("lint-baseline.xml")
}
Execution failed for task ':app:lintVitalRelease'.
 lintOptions {
  checkReleaseBuilds false
  abortOnError false
  }

Execution failed for task ‘:app:lintVitalRelease‘._execution failed for task ':app:lintvitalrelease'.-CSDN博客

10、java.lang.ExceptionInInitializerError (no error message) java.lang.ExceptionInInitializerError异常原因及解决方法-CSDN博客

11、Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.

12、Failed to find Platform SDK with path: platforms;android-25 导入安卓项目遇到问题:Failed to find Platform SDK with path: platforms;android-19-CSDN博客

13、implementation project(':refresh-layout') 对应com.scwang.smartrefresh.layout.SmartRefreshLayout 修改为旧版本 implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-14' 参考:SmartRefreshLayout基本使用 - 简书 (jianshu.com)

记录一种带排除的写法

implementation ('com.wdullaer:materialdatetimepicker:4.2.3') {
    exclude group: 'androidx.appcompat'
    exclude group: 'androidx.recyclerview'
}