Search Unity

Connecting to DJI Android SDK using Unity

Discussion in 'Android' started by Deleted User, Apr 20, 2020.

  1. Deleted User

    Deleted User

    Guest

    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-sd...-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:

        import com.secneo.sdk.Helper;

    public class MApplication extends Application {
    [USER=530556]@override[/USER]
    protected void attachBaseContext(Context paramContext) {
    super.attachBaseContext(paramContext);
    Helper.install(MApplication.this);
    }
    }


    Gradle build:

    Code (CSharp):
    1. apply plugin: 'com.android.library'
    2.     android {
    3.         compileSdkVersion 29
    4.         buildToolsVersion "28.0.3"
    5.  
    6.         defaultConfig {
    7.             minSdkVersion 23
    8.             targetSdkVersion 29
    9.             ndk {
    10.                 // On x86 devices that run Android API 23 or above, if the application is targeted with API 23 or
    11.                 // above, FFmpeg lib might lead to runtime crashes or warnings.
    12.                 abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a'
    13.             }
    14.         }
    15.  
    16.         buildTypes {
    17.             release {
    18.                 minifyEnabled false
    19.                 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    20.             }
    21.         }
    22.  
    23.         packagingOptions{
    24.             doNotStrip "*/*/libdjivideo.so"
    25.             doNotStrip "*/*/libSDKRelativeJNI.so"
    26.             doNotStrip "*/*/libFlyForbid.so"
    27.             doNotStrip "*/*/libduml_vision_bokeh.so"
    28.             doNotStrip "*/*/libyuv2.so"
    29.             doNotStrip "*/*/libGroudStation.so"
    30.             doNotStrip "*/*/libFRCorkscrew.so"
    31.             doNotStrip "*/*/libUpgradeVerify.so"
    32.             doNotStrip "*/*/libFR.so"
    33.             doNotStrip "*/*/libDJIFlySafeCore.so"
    34.             doNotStrip "*/*/libdjifs_jni.so"
    35.             doNotStrip "*/*/libsfjni.so"
    36.             exclude 'META-INF/rxjava.properties'
    37.         }
    38.     }
    39.  
    40.     dependencies {
    41.         compileOnly files ('libs/unity-classes.jar')
    42.         compile ('com.dji:dji-sdk:4.11.2')
    43.         provided ('com.dji:dji-sdk-provided:4.11.2')
    44.     }
    45.  
    Android Manifest -

    Code (CSharp):
    1.  
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.         package="com.myplugin.droneplugin">
    4.  
    5.         <!-- Permissions and features -->
    6.         <uses-permission android:name="android.permission.BLUETOOTH" />
    7.         <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    8.         <uses-permission android:name="android.permission.VIBRATE" />
    9.         <uses-permission android:name="android.permission.INTERNET" />
    10.         <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    11.         <uses-permission android:name="android.permission.WAKE_LOCK" />
    12.         <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    13.         <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    14.         <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    15.         <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    16.         <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    17.         <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    18.         <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    19.         <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    20.         <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    21.         <uses-feature android:name="android.hardware.camera" />
    22.         <uses-feature android:name="android.hardware.camera.autofocus" />
    23.         <uses-feature
    24.             android:name="android.hardware.usb.host"
    25.             android:required="false" />
    26.         <uses-feature
    27.             android:name="android.hardware.usb.accessory"
    28.             android:required="true" />
    29.         <!-- Permissions and features -->
    30.  
    31.         <application
    32.             android:name=".MApplication"
    33.             android:allowBackup="true"
    34.             android:supportsRtl="true">
    35.  
    36.             <!-- DJI SDK -->
    37.             <uses-library android:name="com.android.future.usb.accessory" />
    38.             <uses-library android:name="org.apache.http.legacy" android:required="false" />
    39.             <meta-data
    40.                 android:name="com.dji.sdk.API_KEY"
    41.                 android:value="------" />
    42.             <activity
    43.                 android:name="dji.sdk.sdkmanager.DJIAoaControllerActivity"
    44.                 android:theme="@android:style/Theme.Translucent" >
    45.                 <intent-filter>
    46.                     <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
    47.                 </intent-filter>
    48.                 <meta-data
    49.                     android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
    50.                     android:resource="@xml/accessory_filter" />
    51.             </activity>
    52.             <!-- DJI SDK -->
    53.  
    54.             <activity android:name=".Controller"
    55.                 android:configChanges="orientation"
    56.                 android:screenOrientation="portrait">
    57.             </activity>
    58.         </application>
    59.     </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!
     
    Last edited by a moderator: Apr 20, 2020
  2. mfarina_unity

    mfarina_unity

    Joined:
    May 29, 2021
    Posts:
    2
    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.