Notice of Run MSDK

2022-09-27
No Rating

This chapter introduces how to integrate the MSDK package and UXSDK open source framework from the MSDK V5 Sample to an empty project. The User needs to follow or check the below instructions based on your own android version.

New empty project

  1. At the start page of the Android Studio, choose New Project > Phone and Tablet > Empty Activity
  2. Complete the configuration.
    • Name:My Application
    • Package name:com.dji.myapplication
    • Minimum SDK:API 23:Android 6.0 (Marshmallow)

Import the install function

  1. New MyApplication.java file.
  2. Please refer to the DJIAllApplicationopen in new window of our MSDK V5 Sample to edit.
package com.dji.myapplication;

import android.app.Application;
import android.content.Context;

public class MyApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        com.secneo.sdk.Helper.install(this);
    }
}

Modify the build.gradle(Project)

Add the following code under the repositories label of allprojects.

maven { url 'https://s3.amazonaws.com/repo.commonsware.com' }

Modify the build.gradle(Module)

  1. Add the dependency package of the MSDK aircraft in dependencies.
implementation 'com.dji:dji-sdk-v5-aircraft:{sdkVersion}'
compileOnly 'com.dji:dji-sdk-v5-aircraft-provided:{sdkVersion}'

Statement:

  • dji-sdk-v5-aircraft: Aircraft main package, which provides support for MSDK to control the aircraft.
  • dji-sdk-v5-aircraft-provided: Aircraft compilation package, which provides interfaces related to the aircraft package.
  1. Add the packagingOptions and configurations in android.
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"
    exclude 'META-INF/rxjava.properties'
    exclude 'assets/location_map_gps_locked.png'
    exclude 'assets/location_map_gps_3d.png'
}
configurations {
    cleanedAnnotations
    implementation.exclude group: 'org.jetbrains' , module:'annotations'
}
  1. Copy the content of sample.pro fileopen in new window to the proguard-rules file in your project.

Modify the AndroidManifest.xml file

  1. Please refer to the AndroidManifest.xmlopen in new window of our MSDK V5 Sample to add the permissions that SDK needs.
<uses-permission android:name="android.permission.BLUETOOTH" /><!--Bluetooth permission, which is needed in the bluetooth scenario.-->
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /><!--Bluetooth permission, which is needed in the bluetooth scenario.-->
<uses-permission android:name="android.permission.VIBRATE" /><!--UX vibration permission, which is needed in some vibration notice.-->
<uses-permission android:name="android.permission.INTERNET" /><!--Network permission, which is used for SDK network access.-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><!--Network state permission, which is used for SDK network state listening.-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><!--Location permission, which is used for SDK location confirmation.-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><!--Network state permission, which is used for SDK network state listening.-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><!--Location permission, which is used for SDK location confirmation.-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /><!--Network state permission, which is used for SDK network state listening.-->
<uses-permission android:name="android.permission.RECORD_AUDIO" /><!--Used for audio recording of Sample-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!--Used for reading scenario of SDK-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><!--Used for reading scenario of SDK-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" /><!-- Used for SDK to read the configuration of phone.-->
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/><!--Used when SDK is seriously abnormal.-->
  1. Please refer to the AndroidManifest.xmlopen in new window of our MSDK V5 Sample to add the related permissions of USB for connecting the remote controller.
<uses-feature
    android:name="android.hardware.usb.host"
    android:required="false"/>
<uses-feature
    android:name="android.hardware.usb.accessory"
    android:required="true"/>
  1. Add the statement of Myapplication under application label, which needs to be loaded when starting.
<application
    android:name="com.dji.myapplication.MyApplication"
  1. Please refer to the AndroidManifest.xmlopen in new window of our MSDK V5 Sample to add SDK API KEY. The user should use the package of AndroidManifest.xml in project to apply appkeyopen in new window on the developer website. Then replace the X in following by appkey.

    In this guide, package="com.dji.myapplication". When apply the appkey, bundle identifier should be filled in com.dji.myapplication.
<meta-data
    android:name="com.dji.sdk.API_KEY"
    android:value="X"/>
  1. Add the intent-filter and the meta-data under activity label.
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
    android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
    android:resource="@xml/accessory_filter" />

Add the init function of MSDK

Modify the MainActivity.java file.

package com.dji.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import dji.v5.common.error.IDJIError;
import dji.v5.common.register.DJISDKInitEvent;
import dji.v5.manager.SDKManager;
import dji.v5.manager.interfaces.SDKManagerCallback;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "myApp";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        registerApp();
    }

    private void registerApp() {
        SDKManager.getInstance().init(this, new SDKManagerCallback() {

            @Override
            public void onRegisterSuccess() {
                Log.e(TAG, "myApp onRegisterSuccess");
            }

            @Override
            public void onRegisterFailure(IDJIError error) {
                Log.e(TAG, "myApp onRegisterFailure");
            }

            @Override
            public void onProductDisconnect(int productId) {
                Log.e(TAG, "myApp onProductDisconnect");
            }

            @Override
            public void onProductConnect(int productId) {
                Log.e(TAG, "myApp onProductConnect");
            }

            @Override
            public void onProductChanged(int productId) {
                Log.e(TAG, "myApp onProductChanged");
            }

            @Override
            public void onInitProcess(DJISDKInitEvent event, int totalProcess) {
                Log.e(TAG, "myApp onInitProcess");
                if (event == DJISDKInitEvent.INITIALIZE_COMPLETE) {
                    Log.e(TAG, "myApp start registerApp");
                    SDKManager.getInstance().registerApp();
                }
            }

            @Override
            public void onDatabaseDownloadProgress(long current, long total) {
                Log.e(TAG, "myApp onDatabaseDownloadProgress ");
            }
        });
    }
}
configurations {
    cleanedAnnotations
    implementation.exclude group: 'org.jetbrains' , module:'annotations'
}
  1. Copy the content of sample.pro fileopen in new window to the proguard-rules file in your project.

Modify the AndroidManifest.xml file

  1. Please refer to the AndroidManifest.xmlopen in new window of our MSDK V5 Sample to add the permissions that SDK needs.
<uses-permission android:name="android.permission.BLUETOOTH" /><!--Bluetooth permission, which is needed in the bluetooth scenario.-->
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /><!--Bluetooth permission, which is needed in the bluetooth scenario.-->
<uses-permission android:name="android.permission.VIBRATE" /><!--UX vibration permission, which is needed in some vibration notice.-->
<uses-permission android:name="android.permission.INTERNET" /><!--Network permission, which is used for SDK network access.-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><!--Network state permission, which is used for SDK network state listening.-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><!--Location permission, which is used for SDK location confirmation.-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><!--Network state permission, which is used for SDK network state listening.-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><!--Location permission, which is used for SDK location confirmation.-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /><!--Network state permission, which is used for SDK network state listening.-->
<uses-permission android:name="android.permission.RECORD_AUDIO" /><!--Used for audio recording of Sample-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!--Used for reading scenario of SDK-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><!--Used for reading scenario of SDK-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" /><!-- Used for SDK to read the configuration of phone.-->
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/><!--Used when SDK is seriously abnormal.-->
  1. Please refer to the AndroidManifest.xmlopen in new window of our MSDK V5 Sample to add the related permissions of USB for connecting the remote controller.

Import the Open Source Framework of UXSDK

  1. Copy the UXSDK project(android-sdk-v5-uxsdkopen in new window) to the path of your project.

  2. Cancel all the configurations of the former project in build.gradle file and declare the imports directly. For example, the content of android and dependecies should be localized.

  3. Please refer to the AndroidManifest.xmlopen in new window of our MSDK V5 Sample to add SDK API KEY. The user should use the package of AndroidManifest.xml in project to apply appkeyopen in new window on the developer website. Then replace the X in following by appkey.

    In this guide, package="com.dji.myapplication". When apply the appkey, bundle identifier should be filled in com.dji.myapplication.

<meta-data
    android:name="com.dji.sdk.API_KEY"
    android:value="X"/>
  1. Add the intent-filter and the meta-data under activity label.
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
    android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
    android:resource="@xml/accessory_filter" />

Add the init function of MSDK

Modify the MainActivity.java file.

package com.dji.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import dji.v5.common.error.IDJIError;
import dji.v5.common.register.DJISDKInitEvent;
import dji.v5.manager.SDKManager;
import dji.v5.manager.interfaces.SDKManagerCallback;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "myApp";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        registerApp();
    }

    private void registerApp() {
        SDKManager.getInstance().init(this, new SDKManagerCallback() {

            @Override
            public void onRegisterSuccess() {
                Log.e(TAG, "myApp onRegisterSuccess");
            }

            @Override
            public void onRegisterFailure(IDJIError error) {
                Log.e(TAG, "myApp onRegisterFailure");
            }

            @Override
            public void onProductDisconnect(int productId) {
                Log.e(TAG, "myApp onProductDisconnect");
            }

            @Override
            public void onProductConnect(int productId) {
                Log.e(TAG, "myApp onProductConnect");
            }

            @Override
            public void onProductChanged(int productId) {
                Log.e(TAG, "myApp onProductChanged");
            }

            @Override
            public void onInitProcess(DJISDKInitEvent event, int totalProcess) {
                Log.e(TAG, "myApp onInitProcess");
                if (event == DJISDKInitEvent.INITIALIZE_COMPLETE) {
                    Log.e(TAG, "myApp start registerApp");
                    SDKManager.getInstance().registerApp();
                }
            }

            @Override
            public void onDatabaseDownloadProgress(long current, long total) {
                Log.e(TAG, "myApp onDatabaseDownloadProgress ");
            }
        });
    }
}

Import the Open Source Framework of UXSDK

  1. Copy the UXSDK project(android-sdk-v5-uxsdkopen in new window) to the path of your project.

  2. Cancel all the configurations of the former project in build.gradle file and declare the imports directly. For example, the content of android and dependecies should be localized.

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)

    resourcePrefix "uxsdk_"
    defaultConfig {
        minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions{
        jvmTarget = JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation deps.annotation
    implementation deps.appcompat
    implementation deps.multidex
    implementation deps.legacySupport
    implementation deps.recyclerview
    implementation deps.okio
    implementation deps.wire
    implementation deps.constraintLayout
    implementation deps.lifecycleJava8
    implementation deps.lifecycleRuntime
    implementation deps.lifecycleProcess
    implementation deps.media
    implementation deps.kotlinLib
    implementation deps.ktxCore
    implementation deps.rx3Android
    implementation deps.rx3Java

    api deps.maplibreAnotation
    api deps.maplibreTurf
    api deps.maplibreSdk
    api deps.amap3DMap
    api deps.amapSearch

    api deps.playservicesplaces
    api deps.playservicesmaps
    api deps.playserviceslocation
    api deps.playservicesbase

    compileOnly deps.aircraftProvided
    compileOnly deps.aircraft

    api files("../android-sdk-v5-as/libs/map/DJI-Mapkit-Amap.aar")
    api files("../android-sdk-v5-as/libs/map/DJI-Mapkit-Core.aar")
    api files("../android-sdk-v5-as/libs/map/DJI-Mapkit-Maplibre.aar")
    api files("../android-sdk-v5-as/libs/map/DJI-Mapkit-Google.aar")
}
  1. Add module dependency in settings.gradle.
include ':uxsdk'// uxsdk module
project(':uxsdk').projectDir = new File(rootProject.projectDir, '../android-sdk-v5-uxsdk')
  1. Synchronize your project.

    api deps.playservicesplaces api deps.playservicesmaps api deps.playserviceslocation api deps.playservicesbase

If you are not starting from an empty project, please add the following inspection items.

Check buildTypes in "build.gradle" file on your project app

Please make sure shrinkResources is false to avoid resource compression.

Press to check and refer to "build.gradle" fileopen in new window.

Current content of buildTypes is shown below:

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '../../android-sdk-v5-as/proguard-relative/sample.pro'
        }
        debug {
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '../../android-sdk-v5-as/proguard-relative/sample.pro'
        }
    }

Check android in "build.gradle" file on your project app

Please make sure “arm64-v8a” platform is specified. ”armeabi-v7a“ is not supported currently.

Press to check and refer to "build.gradle" fileopen in new window.

The current content of android is shown below:

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)

    defaultConfig {
        applicationId "com.dji.sampleV5.aircraft"
        minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
        versionCode 1
        versionName "1.0"
        manifestPlaceholders["API_KEY"] = project.AIRCRAFT_API_KEY

        ndk {
            abiFilters 'arm64-v8a'
        }
    }