dji-sdk / Mobile-SDK-Android

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

Mobile SDK , Android 13 , Class not found exception #1242

Closed zohaib1313 closed 1 year ago

zohaib1313 commented 1 year ago

<<PlatformException(java.lang.NoClassDefFoundError: Failed resolution of: Ldji/sdk/sdkmanager/DJISDKManager$SDKManagerCallback;, NoClassDefFoundError, Cause: java.lang.ClassNotFoundException>>

I am facing issue in flutter application where , i have integrated dji mobile sdk "[sdk_releases/4.16.4]".

same code works on all devices from android version 9 to android version 12, but in android 13 facing class not found exception. also using the same progurad rule file as in sample app.

??????????????????????????? below is my build.gradle file ???????????????????????????

group 'com.agrilift.dji.dji_agrilift_plugin' version "1.0-SNAPSHOT" buildscript { ext.kotlin_version = "1.7.0" repositories { google() mavenCentral() }

dependencies {
    classpath "com.android.tools.build:gradle:7.2.2"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}

}

rootProject.allprojects { repositories { google() mavenCentral() } }

apply plugin: "com.android.library" apply plugin: "kotlin-android" apply plugin: "kotlinx-serialization"

android { compileSdkVersion 31 useLibrary "org.apache.http.legacy"

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = "1.8"
}

sourceSets {
    main.java.srcDirs += "src/main/kotlin"
}

defaultConfig {
    minSdkVersion 24
    targetSdkVersion 31

    multiDexEnabled true

    ndk {
        // On x86 devices that run Android API 23 or above, if the application is targeted with API 23 or
        // above, FFmpeg lib might lead to runtime crashes or warnings.
      //  abiFilters "armeabi-v7a", "arm64-v8a"
        abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'

    }

   // consumerProguardFiles "dji-proguard-rules.pro"
}

buildTypes {
    release {
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
    debug {
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
}

packagingOptions {
    doNotStrip "*/*/libdjivideo.so"
    doNotStrip "*/*/libSDKRelativeJNI.so"
    doNotStrip "*/*/libFlyForbid.so"
    doNotStrip "*/*/libduml_vision_bokeh.so"
    doNotStrip "*/*/libyuv2.so"
    doNotStrip "*/*/libGroudStation.so"
    doNotStrip "*/*/libFRCorkscrew.so"
    doNotStrip "*/*/libUpgradeVerify.so"
    doNotStrip "*/*/libFR.so"
    doNotStrip "*/*/libDJIFlySafeCore.so"
    doNotStrip "*/*/libdjifs_jni.so"
    doNotStrip "*/*/libsfjni.so"
    doNotStrip "*/*/libDJICommonJNI.so"
    doNotStrip "*/*/libDJICSDKCommon.so"
    doNotStrip "*/*/libDJIUpgradeCore.so"
    doNotStrip "*/*/libDJIUpgradeJNI.so"
    doNotStrip "*/*/libDJIWaypointV2Core.so"
    doNotStrip "*/*/libAMapSDK_MAP_v6_9_2.so"
    doNotStrip "*/*/libDJIMOP.so"
    doNotStrip "*/*/libDJISDKLOGJNI.so"

    pickFirst "lib/*/libstlport_shared.so"
    pickFirst "lib/*/libRoadLineRebuildAPI.so"
    pickFirst "lib/*/libGNaviUtils.so"
    pickFirst "lib/*/libGNaviMapex.so"
    pickFirst "lib/*/libGNaviData.so"
    pickFirst "lib/*/libGNaviMap.so"
    pickFirst "lib/*/libGNaviSearch.so"
    pickFirst "lib/*/libDJIFlySafeCore.so"
    pickFirst "lib/*/libdjifs_jni.so"
    pickFirst "lib/*/libsfjni.so"

    exclude "META-INF/proguard/okhttp3.pro"
    exclude "META-INF/rxjava.properties"
    exclude "assets/location_map_gps_locked.png"
    exclude "assets/location_map_gps_3d.png"
}

}

dependencies { implementation('com.dji:dji-sdk:4.16.4', { /**

///////stack trace/////

2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: PlatformException(java.lang.NoClassDefFoundError: Failed resolution of: Ldji/sdk/sdkmanager/DJISDKManager$SDKManagerCallback;, NoClassDefFoundError, Cause: java.lang.ClassNotFoundException: Didn't find class "dji.sdk.sdkmanager.DJISDKManager$SDKManagerCallback" on path: DexPathList[[zip file "/data/app/nPwV3_GUw5_n2PYIfH_f1Q==/com.agriliftuser.app-l-SqInxdycJbNMVoUtqjsg==/base.apk"],nativeLibraryDirectories=[/data/app/nPwV3_GUw5_n2PYIfH_f1Q==/com.agriliftuser.app-l-SqInxdycJbNMVoUtqjsg==/lib/arm64, /data/app/~~nPwV3_GUw5_n2PYIfH_f1Q==/com.agriliftuser.app-l-SqInxdycJbNMVoUtqjsg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]], Stacktrace: java.lang.NoClassDefFoundError: Failed resolution of: Ldji/sdk/sdkmanager/DJISDKManager$SDKManagerCallback; 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:39) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at java.lang.reflect.Method.invoke(Native Method) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister.registerGeneratedPlugins(GeneratedPluginRegister.java:80) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at io.flutter.embedding.android.FlutterActivity.configureFlutterEngine(FlutterActivity.java:1133) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at com.agriliftuser.app.MainActivity.configureFlutterEngine(MainActivity.kt:26) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:206) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:495) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.Activity.performCreate(Activity.java:8591) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.Activity.performCreate(Activity.java:8570) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) 2023-08-21 20:27:15.666 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.os.Handler.dispatchMessage(Handler.java:106) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.os.Looper.loopOnce(Looper.java:226) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.os.Looper.loop(Looper.java:313) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at android.app.ActivityThread.main(ActivityThread.java:8757) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at java.lang.reflect.Method.invoke(Native Method) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: Caused by: java.lang.ClassNotFoundException: Didn't find class "dji.sdk.sdkmanager.DJISDKManager$SDKManagerCallback" on path: DexPathList[[zip file "/data/app/nPwV3_GUw5_n2PYIfH_f1Q==/com.agriliftuser.app-l-SqInxdycJbNMVoUtqjsg==/base.apk"],nativeLibraryDirectories=[/data/app/nPwV3_GUw5_n2PYIfH_f1Q==/com.agriliftuser.app-l-SqInxdycJbNMVoUtqjsg==/lib/arm64, /data/app/~~nPwV3_GUw5_n2PYIfH_f1Q==/com.agriliftuser.app-l-SqInxdycJbNMVoUtqjsg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]] 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) 2023-08-21 20:27:15.667 30773-30847 flutter com.agriliftuser.app I Interceptor: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Sugar666666tang commented 1 year ago

这是来自QQ邮箱的自动回复邮件。   您好,您的邮件我已收到。

dji-dev commented 1 year ago

Agent comment from yating.liao in Zendesk ticket #89501:

I think you can try the latest version of MSDK V4. Here is the repository address and release notes.:https://github.com/dji-sdk/Mobile-SDK-Android/tree/sdk_releases/4.17-alpha We have made this version compatible with Android 13.

°°°

zohaib1313 commented 1 year ago

@dji-dev it still gives the same error.

dji-dev commented 1 year ago

Agent comment from yating.liao in Zendesk ticket #89501:

Based on the configuration file you provided, the targetSdkVersion is set to 31, which corresponds to Android 12. Have you made any modifications to this information? If you have made modifications but are still experiencing the same issue, could you provide us with a minimal project that reproduces this problem reliably?

°°°

zohaib1313 commented 1 year ago

I have tested with targetSdkVersion to 33 , but the class not found exception is there still, i have tried upgrading the dji mobile sdk also, but no luck.

I am trying to use this sdk in flutter application where i have created own custom plugin, which works fine below android 13.

dji-dev commented 1 year ago

Agent comment from yating.liao in Zendesk ticket #89501:

We have not tested with Flutter, but we have tested the samples of MSDK 5.5 or 4.17-a1 on an Android 13 device and did not encounter the same issue. Would you experience the same problem when running the sample on the same device?

°°°

zohaib1313 commented 1 year ago

No , native app works but in flutter it doesnot load ,ndk libraries on android 13 only. i.e Helper.install does not work on andorid13 flutter.

orenagiv commented 1 year ago

Hey @zohaib1313 I'm also working on it per the issue you opened on the DJI Flutter Package project: https://github.com/DragonX-cloud/dji_flutter_plugin/issues/22

Trying the Alpha version.

orenagiv commented 1 year ago

Hey @zohaib1313

Alpha version didn’t resolve it. it’s something else. I’ll update soon.

orenagiv commented 1 year ago

Hey @zohaib1313

I got it to work on Android 13.

I'll post a new branch on the dji_flutter_plugin repo soon so you may test too.

orenagiv commented 1 year ago

Hey @zohaib1313 I've posted my update with details here: https://github.com/DragonX-cloud/dji_flutter_plugin/issues/22

orenagiv commented 1 year ago

Hey @dji-dev Please note I could only get it to run with targetSdk 31. But with 33 it doesn't work (I'm referring specifically to the "Register" functionality as a start):

DJISDKManager.getInstance().registerApp(djiPluginContext, object: SDKManagerCallback {
  ...  
})

Note: I'm using the 4.17-a1 SDK version.

You can find an example project in the DJI Flutter Plugin repo: https://github.com/DragonX-cloud/dji_flutter_plugin

The specific Android Example project is here: https://github.com/DragonX-cloud/dji_flutter_plugin/tree/main/example/android

dji-dev commented 1 year ago

Agent comment from yating.liao in Zendesk ticket #89501:

It seems like the issue has been resolved, is that correct?

°°°

orenagiv commented 1 year ago

Hi @dji-dev Actually, it is not :)

Although we can target SDK 31 - we need to be able to compile with the latest stable of Android SDK which is 33.

dji-dev commented 1 year ago

Agent comment from yating.liao in Zendesk ticket #89501:

Actually, the sample of 4.17-a1 runs fine when the targetSDKVersion is set to 33. Have you identified the possible cause of this issue?

°°°

zohaib1313 commented 1 year ago

@dji-dev @orenagiv issue is related to ndk libraries not being load in Android13+ when using as a plugin for flutter, i figured out if I call Helper.install which actually loads ndk libraries in Flutter activity then it gives class not found exception, but if I call this method in FlutterApplication then it works fine.(have tested a flight too).

This will work:

class MyClass : FlutterApplication() { override fun onCreate() { super.onCreate() MultiDex.install(this) com.secneo.sdk.Helper.install(this) } }

orenagiv commented 1 year ago

Thanks @zohaib1313 ! Did you use the latest Flutter Plugin version? And also updated the targetSdk to 33 in both the build.gradle of the Example App as well as the plugin itself?

If you can create a pull request with your changes on the Flutter plugin - that would be great! 🙂

dji-dev commented 1 year ago

Agent comment from yating.liao in Zendesk ticket #89501:

com.secneo.sdk.Helper.install(this) is indeed the key to using MSDK. Thank you for the information provided by zohaib1313.

°°°