Android Studio has recently upgraded the Bumblebee version, some error correction records of old projects moved to new projects

Introduction
AS has never been upgraded. Recently, I was forced to terminate it because the gradle version was too low when I was doing some attempts. The project structure is also very different. Create a new project with the same package name, move the old project to the new project, and start changing gradle, changing references, and changing the manifest file after moving.

When running the old project before, the report

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`.

This is a question of jdk version selection, just choose jdk11 for File—Settings—Build—Build Tools—Gradle.


When app\build.gradle was developed as root, it used C++ to realize the logic of interacting with the screen and compiled it into a so file. In order to be compatible with this part of the phone, it is necessary to add two configurations of ndk and sourceSets, otherwise it will tell that it cannot find so The strange thing is that the old version of AS does not need to add 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)

The next step is to move the implementation fileTree (include: ['*.jar'], dir: 'libs') and third parties such as gson and okhttp, and nothing else needs to be moved.

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'
}


There are several warnings in the previously added permissions of main\AndroidManifest.xml , press Alt+Enter and prompt to add

tools:ignore="ProtectedPermissions"

After the addition, it is OK, because the permission to change the system settings is generally only available to the system APP, so the compiler will have a warning, and the warning will be ignored after adding this.

Applications after Android P require encrypted connections by default, which means that Android P will prohibit apps from using all unencrypted connections. Therefore, Android devices running Android P system will not be able to transmit traffic in clear code in the future, and need to use the following The first generation (Transport Layer Security) transport layer security protocol, if the application uses http network requests of unencrypted plaintext traffic, it will cause the application to fail to make network requests, https will not be affected. Similarly, if the application is nested webview, webview can only use https requests. Android Nougat and Oreo are not affected. Using HttpUrlConnection to make http requests in Android P will cause the following exception

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

Appears when using OKHttp request

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

Solution: From "Android higher version networking failure error: Cleartext HTTP traffic to xxx not permitted solution https://blog.csdn.net/gengkui9897/article/details/82863966"
1, APP uses https request instead.
2. TargetSdkVersion drops below 27.
3. Change the network security configuration:
create an xml folder under the res folder, and then create a network_security_config.xml file, the content of which is as follows:

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

Next, add the following attributes to the application tag under the AndroidManifest.xml file:

 android:networkSecurityConfig="@xml/network_security_config"

4. Insert directly into the tag of the AndroidManifest.xml configuration file

    android:usesCleartextTraffic="true"

After changing the reference and
upgrading Bumblebee, some reference methods have also changed. There are quite a lot of them. It used to start with android, but now it starts with androidx. For details, you can go here to check "support migrate androidx, or androidx rollback androidx comparison https:// blog.csdn.net/frank7023/article/details/124426681》

Guess you like

Origin blog.csdn.net/frank7023/article/details/124430415