Crash Resolution after APP Accesses Open Source Plugin Dokit

Posted by TimC on Fri, 18 Feb 2022 00:42:58 +0100

Introduction to Dokit

  1. DoraemonKit can quickly enable your business test code to be managed and accepted uniformly here.
  2. DoraemonKit has many commonly used tools built in to avoid duplicate implementations. With one access, you will have a powerful collection of tools.
  3. With dokit platform, with interface Mock, health check-up, file synchronization assistant, you can easily collaborate with others, greatly improving the efficiency of research and development process

Android Application Access

1.Gradle dependency
dependencies {
...
debugImplementation 'com.didichuxing.doraemonkit:dokitx:3.3.5'
releaseImplementation 'com.didichuxing.doraemonkit:dokitx-no-op:3.3.5'
...
}
2. Initialization
  • Initialize when App starts.
import android.app.Application;

import com.didichuxing.doraemonkit.DoraemonKit;

public class AndroidApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        //pId can be used in https://www.dokit.cn/ Log in and get after console adds an application
        DoraemonKit.install(this, "xxxxxx4a09c833656de5ecxxxxxxxxx");
    }
}
3. Traffic monitoring and other AOP functions (optional)
  • AOP includes the following functions: 1) Longitude and latitude simulation of Baidu, Tencent and Golden Maps 2)UrlConnection, Okhttp package and subsequent interface hook functions 3)App startup time statistics 4) Slow function 5) Big picture
  • Build in the project. Add a classpath to the gradle.
buildscript {
    dependencies {
        ...
        classpath 'com.didichuxing.doraemonkit:dokitx-plugin:3.3.5'
        ...
    }
}
  • Build in app. Add plugin to gradle.
apply plugin: 'com.didi.dokit'
  • Plug-in configuration options: add to build of app module. The gradle file is at the same level as android {}
    dokitExt {
      //General Settings
      comm {
          //Map Latitude and Longitude Switch
          gpsSwitch true
          //Network Switch
          networkSwitch true
          //Big picture switch
          bigImgSwitch true
          //webView js package
          webViewSwitch true
      }
    
      slowMethod {
          //Call Stack Mode Configuration
          stackMethod {
              //Functions with a default value of less than 5ms are not shown on the call stack
              thresholdTime 10
              //Call Stack Function Entry
              enterMethods = ["com.didichuxing.doraemondemo.MainDebugActivity.test1"]
              //Blacklist granularity minimum to class not supported to method at this time
              methodBlacklist = ["com.facebook.drawee.backends.pipeline.Fresco"]
          }
          //Normal mode configuration
          normalMethod {
              //Functions with a default value of 500ms or less will not be printed in the console at run time
              thresholdTime 500
              //Package name required for Function Instrumentation
              packageNames = ["com.wch.dokit"]
              //Package name & class name not required for Function Instrumentation
              methodBlacklist = ["com.didichuxing.doraemondemo.dokit"]
          }
      }
    }
    
  • The strategy and methodSwitch configuration items have been deprecated, and the new configuration switches are located in the gradle in the project root directory. In properties, the configuration is as follows:
    // dokit global configuration
    // Plug-in switch
    DOKIT_PLUGIN_SWITCH=true
    // DOKIT reads tripartite library meetings and booster conflicts If booster is also integrated in your project, change the switch to false is recommended
    DOKIT_THIRD_LIB_SWITCH=true
    // Plugin Log
    DOKIT_LOG_SWITCH=true
    // The fully qualified name of the custom Webview is primarily for h5 js packages and data mock s
    DOKIT_WEBVIEW_CLASS_NAME=com/didichuxing/doraemonkit/widget/webview/MyWebView
    // dokit slow function switch
    DOKIT_METHOD_SWITCH=true
    // dokit function call stack level
    DOKIT_METHOD_STACK_LEVEL=4
    // 0: Default mode Print function call stack needs to add specified entries Default is application onCreate and attachBaseContext
    // 1: Time-consuming global business code function insertion for printing a function while running in normal mode
    DOKIT_METHOD_STRATEGY=0
    
4. Install after compilation has passed
  • Huawei enjoys 8 devices (Android 8), Android apps import dokit plugins to compile, crash after opening and report the following error
2021-01-08 11:21:48.002 13696-13696/test.xdja.com.testdemov3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: test.xdja.com.testdemov3, PID: 13696
java.lang.RuntimeException: Unable to instantiate application test.xdja.com.testdemov3.AndroidApplication: 
java.lang.ClassNotFoundException: Didn't find class "test.xdja.com.testdemov3.AndroidApplication" 
on path: DexPathList[[zip file "/data/app/test.xdja.com.testdemov3-EtvgXQ5acPFVjPhPky2zyQ==/base.apk"],
nativeLibraryDirectories=[/data/app/test.xdja.com.testdemov3-EtvgXQ5acPFVjPhPky2zyQ==/lib/arm64, 
/data/app/test.xdja.com.testdemov3-EtvgXQ5acPFVjPhPky2zyQ==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /product/lib64]]
  • Huawei MatePad Device (Android 10), Android App introduced dokit plugin compilation, crashed after opening and reported the following error
2021-01-08 11:33:29.643 19241-19241/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: test.xdja.com.testdemov3, PID: 19241
java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method
 at okhttp3.internal.Util.<clinit>(Util.java:87)
 at okhttp3.internal.Util.immutableList(Util.java:234)
 at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:124)
 at com.didichuxing.doraemonkit.util.DoraemonStatisticsUtil.uploadUserInfo(DoraemonStatisticsUtil.java:54)
 at com.didichuxing.doraemonkit.DoraemonKitReal.install(DoraemonKitReal.kt:174)
 at com.didichuxing.doraemonkit.DoraemonKit.install(DoraemonKit.kt:58)
 at com.didichuxing.doraemonkit.DoraemonKit.install(DoraemonKit.kt:24)
 at test.xdja.com.testdemov3.AndroidApplication.onCreate(AndroidApplication.java:13)
 at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1202)
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7351)
 at android.app.ActivityThread.access$2400(ActivityThread.java:308)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2295)
5. Solving the above problems
  • Based on the error information related to Huawei Enjoy 8 devices, attempts have been made such as adjusting the dokit version, adding okhttp3, and adjusting DoraemonKit. The introduction of install, the addition of multiDexEnabled true, adjusting the location of the Application, and so on, did not resolve the direct crash of open applications.
  • According to Huawei MatePad device error information, it is normal to try to add the following configuration and enjoy 8 devices in Huawei.
    compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
  • Reason analysis: The dokit plug-in uses new features of Java8, which prevents the application from running without adding the above configuration

Topics: Android