dji-sdk / Mobile-SDK-Android

DJI Mobile SDK for Android: http://developer.dji.com/mobile-sdk/
Other
980 stars 579 forks source link

ClassNotFoundException: Didn't find class "dji.log.DJILog" #1177

Open vancuong0429 opened 1 year ago

vancuong0429 commented 1 year ago

I have created custom UXKeys, When I run with proguard, It crashes when calling UXKeys.addNewKeyClass(CustomKeys::class.java) My code in application:

override fun onCreate() {
        super.onCreate()
        GlobalPreferencesManager.initialize(AppGlobalPreferences(this))
        UXKeys.addNewKeyClass(CustomKeys::class.java)
  }

I set up multiDexEnabled My version:

implementation ('com.dji:dji-sdk:4.16.1')
compileOnly ('com.dji:dji-sdk-provided:4.16.1')
implementation 'com.github.dji-sdk:Mobile-UXSDK-Beta-Android:v0.5.1'

My log error: Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Ldji/log/DJILog; at dji.ux.beta.core.communication.UXKeys.initializeKeyValueTypes(UXKeys.java:67) at dji.ux.beta.core.communication.UXKeys.addNewKeyClass(UXKeys.java:79) at com.abc.djidrone.MyApplication.onCreate(MyApplication.kt:88) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6097) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1791) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:7000) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

DJI-William commented 1 year ago

It must be something wrong with the minified. What happens if you disable the minified option in build.gradle file? Try the proguard-rules.pro files in our sample.

vancuong0429 commented 1 year ago

If I disable minifyEnabled, it still works, Only problem with minifyEnabled = true, but not always. I logged this issue on firebase log, it's not much but quite a few of my users. My config release:

buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
}

I follow proguard-rules.pro link sample

DJI-William commented 1 year ago

Don't shirnkResources, it will cause some crashes.

vancuong0429 commented 1 year ago

so, I only need to set shrinkResources = false? I will try and check the report on firebase Thanks @DJI-William

vancuong0429 commented 1 year ago

Hi @DJI-William D I updated the config:

buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
            //applicationIdSuffix '.debug'
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

but sometimes until the crash. Log crash on firebase: Caused by java.lang.ClassNotFoundException: Didn't find class "dji.log.DJILog" on path: DexPathList[[zip file "/system/framework/com.android.future.usb.accessory.jar", zip file "/data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/base.apk", zip file "/data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/split_config.armeabi_v7a.apk", zip file "/data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/split_config.pt.apk", zip file "/data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/lib/arm, /data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/base.apk!/lib/armeabi-v7a, /data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/split_config.armeabi_v7a.apk!/lib/armeabi-v7a, /data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/split_config.pt.apk!/lib/armeabi-v7a, /data/app/com.acb.djidrone-86KN3YVpxlAtHeoFSCQrQg==/split_config.xxhdpi.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]