Empty Project Import MSDK
- Suggested Versions
- Obtain a Empty Project Integrated with MSDK
- Create a New Empty Project
- Edit the build.gradle (Project) File
- Edit the build.gradle (Module: app) File
- Edit the AndroidManifest.xml File
- Create a MyApplication.kt File
- Edit the MainActivity.kt File
- Create a activity_main.xml File
- Import UXSDK Open-Source Framework
- Edit the gradle.properties File
- Testing and Debugging
This tutorial explains how to migrate the MSDK package and UXSDK open-source framework from the MSDK V5 Sample to a user's empty project.
Suggested Versions
- Android Studio:
Android Studio Koala | 2024.1.1
- Java Runtime:
17
or11
- Kotlin:
1.8.10
- Gradle:
7.6.2
- Android Gradle Plugin:
7.4.2
- minSdkVersion:
23
- targetSdkVersion:
34
- If using a non-recommended version, please adapt the entire integration process according to the actual version. Android Studio Koala 2024.1.1 comes with Java Runtime 17 integrated by default, which can generally be used directly without any additional configuration.
- Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported. If your app uses Kotlin synthetics for view binding, use this guide to migrate to Jetpack view binding: Migrate from Kotlin synthetics to Jetpack view binding.
Obtain a Empty Project Integrated with MSDK
If you prefer not to manually configure your project following the tutorial below, you can download the [empty project with MSDK integrated],and follow this document to start the final configuration and debugging from the Testing and Debugging section.
Create a New Empty Project
- On the Android Studio launch page, select New Project > Phone and Tablet > Empty Views Activity.
- Complete the configuration according to the image below.
- Name:
MSDKSample
- Package name:
com.example.msdksample
- Minimum SDK:
24
or higher - Build configuration language:
Groovy DSL (build.gradle)
- Name:

Edit the build.gradle (Project) File
Go to build.gradle (Project)
under Gradle Scripts
. Replace all the content with the following code segment, which provides the correct reference library.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
// Suggested Android Gradle Plugin Version
classpath "com.android.tools.build:gradle:7.4.2"
//Suggested Kotlin version
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
// ... (remaining code)
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Edit the build.gradle (Module: app) File
- In the
android
section, configuresdkversion
andndk
indefaultConfig
, and set uppackagingOptions
.
Note the versions:
minSdkVersion
needs to be upgraded to a minimum version number of 23.- MSDK only supports arm64-v8a architecture.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
namespace 'com.example.msdksample'
compileSdkVersion 34 // MSDK supported version
defaultConfig {
applicationId "com.example.msdksample"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'arm64-v8a' // MSDK only supports arm64-v8a architecture
}
// MSDK related so library
packagingOptions {
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
// MSDK related so library
packagingOptions {
doNotStrip "*/*/libconstants.so"
doNotStrip "*/*/libdji_innertools.so"
doNotStrip "*/*/libdjibase.so"
doNotStrip "*/*/libDJICSDKCommon.so"
doNotStrip "*/*/libDJIFlySafeCore-CSDK.so"
doNotStrip "*/*/libdjifs_jni-CSDK.so"
doNotStrip "*/*/libDJIRegister.so"
doNotStrip "*/*/libdjisdk_jni.so"
doNotStrip "*/*/libDJIUpgradeCore.so"
doNotStrip "*/*/libDJIUpgradeJNI.so"
doNotStrip "*/*/libDJIWaypointV2Core-CSDK.so"
doNotStrip "*/*/libdjiwpv2-CSDK.so"
doNotStrip "*/*/libFlightRecordEngine.so"
doNotStrip "*/*/libvideo-framing.so"
doNotStrip "*/*/libwaes.so"
doNotStrip "*/*/libagora-rtsa-sdk.so"
doNotStrip "*/*/libc++.so"
doNotStrip "*/*/libc++_shared.so"
doNotStrip "*/*/libmrtc_28181.so"
doNotStrip "*/*/libmrtc_agora.so"
doNotStrip "*/*/libmrtc_core.so"
doNotStrip "*/*/libmrtc_core_jni.so"
doNotStrip "*/*/libmrtc_data.so"
doNotStrip "*/*/libmrtc_log.so"
doNotStrip "*/*/libmrtc_onvif.so"
doNotStrip "*/*/libmrtc_rtmp.so"
doNotStrip "*/*/libmrtc_rtsp.so"
}
- In
dependencies
, configure the SDK package and modify the other referenced libraries to their corresponding versions.
Note: {$SDK_VERSION} is the latest version of MSDK. To replace the version, refer to Edit the gradle.properties File.
dependencies {
implementation project(":android-sdk-v5-uxsdk")
implementation "com.dji:dji-sdk-v5-aircraft:$SDK_VERSION"
compileOnly "com.dji:dji-sdk-v5-aircraft-provided:$SDK_VERSION"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
Edit the AndroidManifest.xml File
Refer to the AndroidManifest.xml file in the MSDK V5 Sample for the following modifications. Pay attention to the positions between code segments and tags.
- Add the basic permissions required by the SDK. Before that, make sure you understand which Android system permissions are required by MSDK V5 and permission definitions.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
- Add USB-related permissions within the
manifest
tag for connecting to 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"/>
- Add the declaration of the
MyApplication
file within theapplication
tag, which is required for loading at startup.
<application
android:name=".MyApplication"
//... (remaining code)
- Modify the
application
tag attributes with the following code segment to configure the app key.
Visit the developer website to apply for an app key. When applying for the app key, the "Package Name" should be com.example.msdksample
. Add the following code to the application
item, and keep android:name
unchanged and replace your app key in android:value
with the app key you applied for.

<meta-data
android:name="com.dji.sdk.API_KEY"
android:value="your app key"/>
- Configure USB accessory notification within the
activity
tag.
<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" />
Create a MyApplication.kt File
- Create a new
MyApplication.kt
file under thecom.example.msdksample
folder, at the same level asMainActivity.kt
. - Write the following code in the file, which is used to import the SDK decryption and protection package.
Note: Pay attention to the consistency of the package name: com.example.msdksample
package com.example.msdksample
import android.app.Application
import android.content.Context
import android.util.Log
import dji.v5.common.error.IDJIError
import dji.v5.common.register.DJISDKInitEvent
import dji.v5.manager.SDKManager
import dji.v5.manager.interfaces.SDKManagerCallback
class MyApplication : Application() {
private val TAG = this::class.simpleName
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
com.cySdkyc.clx.Helper.install(this)
}
override fun onCreate() {
super.onCreate()
SDKManager.getInstance().init(this,object:SDKManagerCallback{
override fun onInitProcess(event: DJISDKInitEvent?, totalProcess: Int) {
Log.i(TAG, "onInitProcess: ")
if (event == DJISDKInitEvent.INITIALIZE_COMPLETE) {
SDKManager.getInstance().registerApp()
}
}
override fun onRegisterSuccess() {
Log.i(TAG, "onRegisterSuccess: ")
}
override fun onRegisterFailure(error: IDJIError?) {
Log.i(TAG, "onRegisterFailure: ")
}
override fun onProductConnect(productId: Int) {
Log.i(TAG, "onProductConnect: ")
}
override fun onProductDisconnect(productId: Int) {
Log.i(TAG, "onProductDisconnect: ")
}
override fun onProductChanged(productId: Int)
{
Log.i(TAG, "onProductChanged: ")
}
override fun onDatabaseDownloadProgress(current: Long, total: Long) {
Log.i(TAG, "onDatabaseDownloadProgress: ${current/total}")
}
})
}
}
Edit the MainActivity.kt File
- Delete the
ui
folder in the same directory asMainActivity.kt
. - Replace the content of the
MainActivity.kt
file with the following code.
Note: Pay attention to the consistency of the package name: com.example.msdksample
package com.example.msdksample
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Create a activity_main.xml File
- In the app > src > main > res directory, create a new
layout
folder and create a newactivity_main.xml
file in the folder. - Replace the content of the
activity_main.xml
file with the following code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
- In the app > src > main > res > values directory, replace the content of the
themes.xml
file with the following code.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.MSDKSample" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>
<style name="Theme.MSDKSample" parent="Base.Theme.MSDKSample" />
</resources>
Import UXSDK Open-Source Framework
Copy the entire UXSDK project (android-sdk-v5-uxsdk) to the root directory of the
MyApplication
project path, at the same level as theapp
folder.Edit the
gradle.properties
file, adding the following code to configure the correct version.
#buildconfig
ANDROID_MIN_SDK_VERSION=23 //DJI MSDK supported version
ANDROID_TARGET_SDK_VERSION=34 //DJI MSDK supported version
ANDROID_COMPILE_SDK_VERSION=34 //DJI MSDK supported version
- Create a new
dependencies.gradle
file in the same directory asbuild.gradle (project)
and import the contents of dependencies.gradle into it. Add the following code segment at the beginning of thebuild.gradle (Project)
file.
apply from:rootProject.file('dependencies.gradle')
- Adjust the content of the
settings.gradle
file as the following code segment.
rootProject.name = "My Application"
include ':app'
include ':android-sdk-v5-uxsdk'
- In the folder directory app > res > values > strings.xml, edit the "name" attribute of this string in the file. The meaning of this code is the name of your app.
<string name="your_app_name">My Application</string>
In actual development, you can edit the id and value of this code above. Just keep the id name consistent with the corresponding id name in the AndroidManifest.xml
file in the project. In this example, the application's id name is "your_app_name".
<application
android:label="@string/your_app_name">
Edit the gradle.properties File
- Use the
KOTLIN_VERSION
andSDK_VERSION
sections in thegradle.properties
file to change the Kotlin version and MSDK version. For example, you can add the following two lines of code after the#buildconfig
section to use Kotlin version 1.8.10 and MSDK version 5.10.0.
KOTLIN_VERSION=1.8.10
SDK_VERSION=5.10.0
Note: To avoid compatibility problem in the compilation process, change the configuration sections in gradle.properties as follows.
android.useAndroidX=true android.enableJetifier=true android.nonTransitiveRClass=false
Congrats! By now, you have completed the configuration of the empty project.
Testing and Debugging
Select "Sync Now" to synchronize the project.
Click on the hammer icon on the interface, build your project, and do necessary debugging.
Due to the limitations of the empty project, occasional errors might occur during the build process because the
UXSDK
package content can not be properly referenced. This does not affect the normal function of the project, and you should continue to connect your device to test the app. If you find a solution to such errors during the integration process, feel free to provide feedback via documentation. Possible errors may include:
Execution failed for task ':android-sdk-v5-uxsdk:kaptGenerateStubsDebugKotlin'.
- Connect the DJI remote controller with screen or your mobile device, enable the corresponding developer options, and once your device is displayed on the top right corner of Android Studio, select the 'run'app' triangle icon to test whether the project is good to run.