Hello Tello Pilot!
Join our DJI Tello community & remove this banner.
Sign up

Connecting to DJI Android SDK using Unity.

kandabi

New member
Joined
Apr 20, 2020
Messages
2
Reaction score
0
Hey everyone, :)

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, and that I'm not the only one struggling to get them both working at the same :confused:
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 and launch the game, It would simply crash on startup (no gradle or compile errores).


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:

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

The necessary attachBaseContext override:
Java:
import com.secneo.sdk.Helper;
public class MApplication extends Application {

    @Override
    protected void attachBaseContext(Context paramContext) {
        super.attachBaseContext(paramContext);
        Helper.install(MApplication.this);
    }
}


Gradle build:
Java:
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 -
XML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kandabi.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! ?
 
Looks like it can't find com.secneo.sdk.Helper but I don't know how to fix it as I haven't used the DJI SDK before.

Yep, but com.secneo.sdk.Helper is inside the dji-sdk, the only reason It does not recognize it is because of Unity, as It has no problems recognizing that class if the plugin was loaded outside of unity..
 

New Posts

Members online

No members online now.

Forum statistics

Threads
5,700
Messages
39,967
Members
17,060
Latest member
Clubfooted

New Posts