Android Studio最近升级了大黄蜂版,旧项目搬到新项目的一些纠错记录

引言
AS一直也没升级,最近在做一些尝试的时候因为gradle版本太低而被迫终止,所幸升级了算了,升完级后旧项目自然运行不了,AS版本差异太大,断代严重,导致项目结构差异也非常大,直接新建个包名一致的项目,将旧项目搬到新项目中,搬完后就开始改gradle,改引用,改清单文件。

之前运行旧项目时,报

Unable to start the daemon process. The project uses Gradle 4.6 which is incompatible with Java 11 or newer.
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

这是jdk版本选择的问题,File—Settings—Build—Build Tools—Gradle选jdk11就好。

app\build.gradle
当初root开发时,用C++实现了和屏幕交互的逻辑,编成了so文件,为了兼容这部分手机,就要加ndk和sourceSets这两块配置,否则就告知找不到so文件,奇怪的是旧版AS就不需要加ndk。

android {
    defaultConfig {
        ndk{
            abiFilters "armeabi"
        }
    }
    sourceSets.main { jniLibs.srcDirs = ['libs']; }
}
get PatchStore::createDisableExceptionQarthFile method fail.
E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/-5iJvy2PSAdbDsylEPznshQ==/base.apk"],nativeLibraryDirectories=[/data/app/-5iJvy2PSAdbDsylEPznshQ==/lib/arm64, /system/lib64, /product/lib64]]] couldn't find "App.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
        at java.lang.System.loadLibrary(System.java:1672)
        at .main..<clinit>(.java:57)
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50)
        at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1127)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1175)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6688)
        at android.app.ActivityThread.access$2000(ActivityThread.java:273)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2020)
        at android.os.Handler.dispatchMessage(Handler.java:112)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

接着就是把implementation fileTree(include: [‘*.jar’], dir: ‘libs’)和gson、okhttp等第三方搬过来了,其它都不需要搬过来。

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    //以下就是从旧项目中搬过来的
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.okhttp3:okhttp:3.2.0'
    implementation 'com.alibaba:fastjson:1.2.73'
}

main\AndroidManifest.xml
以前添加的权限中有几个警告,按Alt+回车后提示加

tools:ignore="ProtectedPermissions"

加完后就OK了,因为改变系统设置的权限一般只有系统APP才有,所以编译器会有警告,加上这个后就忽略掉警告了。

Android P以后的应用程序要求默认使用加密连接,意味着 Android P 将禁止 App 使用所有未加密的连接,因此运行 Android P 系统的安卓设备无论是接收或者发送流量,未来都不能明码传输,需要使用下一代(Transport Layer Security)传输层安全协议,如果应用使用的是非加密的明文流量的http网络请求,则会导致该应用无法进行网络请求,https则不会受影响,同样地,如果应用嵌套了webview,webview也只能使用https请求。而 Android Nougat 和 Oreo 则不受影响。在Android P 使用HttpUrlConnection进行http请求会出现以下异常

 W/System.err: java.io.IOException: Cleartext HTTP traffic to **** not permitted

使用OKHttp请求则出现

java.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security policy

解决方法:来自《Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法https://blog.csdn.net/gengkui9897/article/details/82863966》
1,APP改用https请求。
2,targetSdkVersion 降到27以下。
3,更改网络安全配置:
在res文件夹下创建一个xml文件夹,然后创建一个network_security_config.xml文件,文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

接着,在AndroidManifest.xml文件下的application标签增加以下属性:

 android:networkSecurityConfig="@xml/network_security_config"

4,在AndroidManifest.xml配置文件的标签中直接插入

    android:usesCleartextTraffic="true"

改引用
升级大黄蜂后,一些引用的方式也变了,还挺多的,之前是android打头,现在是androidx打头,具体可以去这里查看《support 迁移androidx,或androidx回退androidx 对比https://blog.csdn.net/frank7023/article/details/124426681》

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖人称-杰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值