引言
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 adle.java.home` in `gradle.properties`.
这是jdk版本选择的问题,File—Settings—Build—Build Tools—Gradle选jdk11就好。
adle
当初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: mainjava.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.wInstance(Native Method)at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50)app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)at android.wApplication(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 flect.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 le.android.material:material:1.4.0'implementation straintlayout:constraintlayout:2.0.4'testImplementation 'junit:junit:4.13.2'androidTestImplementation st.ext:junit:1.1.3'androidTestImplementation st.espresso:espresso-core:3.4.0'//以下就是从旧项目中搬过来的implementation fileTree(include: ['*.jar'], dir: 'libs')implementation le.code.gson:gson:2.8.5'implementation 'com.squareup.okhttp3:okhttp:3.2.0'implementation 'com.alibaba:fastjson:1.2.73'
}
l
以前添加的权限中有几个警告,按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请求会出现以下异常
: java.io.IOException: Cleartext HTTP traffic to **** not permitted
使用OKHttp请求则出现
java.UnknownServiceException: CLEARTEXT communication ** not permitted by network security policy
解决方法:来自《Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法》
1,APP改用https请求。
2,targetSdkVersion 降到27以下。
3,更改网络安全配置:
在res文件夹下创建一个xml文件夹,然后创建一个network_l文件,文件内容如下:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config><base-config cleartextTrafficPermitted="true" />
</network-security-config>
接着,在l文件下的application标签增加以下属性:
android:networkSecurityConfig="@xml/network_security_config"
4,在l配置文件的标签中直接插入
android:usesCleartextTraffic="true"
改引用
升级大黄蜂后,一些引用的方式也变了,还挺多的,之前是android打头,现在是androidx打头,具体可以去这里查看《support 迁移androidx,或androidx回退androidx 对比》
本文发布于:2024-01-28 19:46:29,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064423929836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |