Connecting to DJI Android SDK using Unity

I’ve been trying to integrate a blank unity project to the DJI SDK using a native plugin (aar file), and I’ve been struggling the past week trying to get it to work, It seems that the DJI mobile sdk does not play well with unity.

I’ve followed the official documentation and managed to create a plugin that succesfully connects to the SDK, the issue is if I would use Unity to recompile that plugin ( placing it inside assets/android folder ) upon launching the game, It would simply crash on startup (no gradle or compile errores).

https://developer.dji.com/mobile-sdk/documentation/application-development-workflow/workflow-integrate.html

According to the docs, I must override the attachBaseContext() method to add the Helper.install(MApplication.this); line of code.

Doing so results in the following error:

2020-04-20 12:19:32.727 6473-6473/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myplugin.DroneGame, PID: 6473
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/secneo/sdk/Helper;
at com.myplugin.droneplugin.MApplication.attachBaseContext(MApplication.java:13)
at android.app.Application.attach(Application.java:215)

The necessary attachBaseContext override:


public class MApplication extends Application {
 @ 
protected void attachBaseContext(Context paramContext) {
super.attachBaseContext(paramContext);
Helper.install(MApplication.this);
}
}```

Gradle build:

```csharp
apply plugin: 'com.android.library'
    android {
        compileSdkVersion 29
        buildToolsVersion "28.0.3"
 
        defaultConfig {
            minSdkVersion 23
            targetSdkVersion 29
            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', 'x86', 'arm64-v8a'
            }
        }
 
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.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"
            exclude 'META-INF/rxjava.properties'
        }
    }
 
    dependencies {
        compileOnly files ('libs/unity-classes.jar')
        compile ('com.dji:dji-sdk:4.11.2')
        provided ('com.dji:dji-sdk-provided:4.11.2')
    }

Android Manifest -

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.myplugin.droneplugin">
 
        <!-- Permissions and features -->
        <uses-permission android:name="android.permission.BLUETOOTH" />
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
        <uses-permission android:name="android.permission.VIBRATE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
        <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-feature android:name="android.hardware.camera" />
        <uses-feature android:name="android.hardware.camera.autofocus" />
        <uses-feature
            android:name="android.hardware.usb.host"
            android:required="false" />
        <uses-feature
            android:name="android.hardware.usb.accessory"
            android:required="true" />
        <!-- Permissions and features -->
 
        <application
            android:name=".MApplication"
            android:allowBackup="true"
            android:supportsRtl="true">
 
            <!-- DJI SDK -->
            <uses-library android:name="com.android.future.usb.accessory" />
            <uses-library android:name="org.apache.http.legacy" android:required="false" />
            <meta-data
                android:name="com.dji.sdk.API_KEY"
                android:value="------" />
            <activity
                android:name="dji.sdk.sdkmanager.DJIAoaControllerActivity"
                android:theme="@android:style/Theme.Translucent" >
                <intent-filter>
                    <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
                </intent-filter>
                <meta-data
                    android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
                    android:resource="@xml/accessory_filter" />
            </activity>
            <!-- DJI SDK -->
 
            <activity android:name=".Controller"
                android:configChanges="orientation"
                android:screenOrientation="portrait">
            </activity>
        </application>
    </manifest>

Gradle and Android Manifest file have been set up correctly I believe, I’d really appreciate if you could help me out as I’m pretty stumped right now!

Hi
I have a project to develop an application using AR Foundation in Unity 3D, and I would like to get the data from the sensors of a DJI UAV, using the DJI Mobile SDK, but I am not getting it. I saw that you are already in a much more advanced stage of knowledge than I am.

I would like help with this project, if it really can be implemented.

Thanks for listening.