【Introduction】
- This article will introduce how to intergrate the MSDK library and UXSDK module into an empty project.
- The author is using Android Studio 4.2.2.
- The author is using MSDK 5.2.0.
- Using version 5.8 and upper, please refer to this: https://developer.dji.com/doc/mobile-sdk-tutorial/en/quick-start/user-project-caution.html
【Create an empty project】
- Create an empty project, choose New Project-Phone and Tablet-Empty Activity.
- Name as My Application, Package name as com.dji.myapplication, Minimum SDK as 23.
- compileSdkVersion and targetSdkVersion are 32.
【Create MyApplication.java file】
- Edit as below, this will install the SDK library, you can refer to the DJIAllApplication in our Sample
package com.dji.myapplication
import android.app.Application
import android.content.Context
class MyApplication : Application() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
com.secneo.sdk.Helper.install(this)
}
}
【Edit build.gradle (Module) file】
- In dependencies section, add MSDK aircraft library, if you want to support handheld products, you can use all library or hanheld library only. You can refer to our Sample.
implementation "com.dji:dji-sdk-v5-aircraft:5.2.0"
implementation "com.dji:dji-sdk-v5-networkImp:5.2.0"
compileOnly "com.dji:dji-sdk-v5-aircraft-provided:5.2.0"
implementation 'com.squareup.okio:okio:1.15.0'
implementation 'com.squareup.wire:wire-runtime:2.2.0'
implementation 'com.airbnb.android:lottie:3.3.1' - In android section, add packagingOptions.
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 "*/*/libffmpeg.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"
} - Copy the sample.pro file content into your proguard-rules file in your project.
【Edit AndroidManifest.xml file】
- Add the basic required permissions according to the AndroidManifest.xml in our sample. For more details, please read What kind of Android system privileges are MSDK V5 required?
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> - Add the USB related permission to connect the RC according to the AndroidManifest.xml in our sample.
<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 Myapplication file under application tag, it needs to be loaded when the app starts.
<application
android:name="com.dji.myapplication.MyApplication" - Add the SDK API KEY sction according to the AndroidManifest.xml in sample. The "X" section represents the appkey you need to insert. You need to go to our developer website to apply the appkey. In this article, the package=com.dji.myapplication. So you need to input com.dji.myapplication in the package name section when applying the appkey.
<meta-data
android:name="com.dji.sdk.API_KEY"
android:value="X"/> - Add intent-filter and meta-data under 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" />
【Edit MainActivity.java file】
-
Add the MSDK init method.
package com.dji.myapplication
import android.os.Bundle
import android.util.Log
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
class MainActivity : AppCompatActivity() {
private val TAG = "myApp"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
registerApp()
}
private fun registerApp() {
SDKManager.getInstance().init(this, object : SDKManagerCallback {
override fun onRegisterSuccess() {
Log.i(TAG, "myApp onRegisterSuccess")
}
override fun onRegisterFailure(error: IDJIError) {
Log.i(TAG, "myApp onRegisterFailure")
}
override fun onProductDisconnect(productId: Int) {
Log.i(TAG, "myApp onProductDisconnect")
}
override fun onProductConnect(productId: Int) {
Log.i(TAG, "myApp onProductConnect")
}
override fun onProductChanged(productId: Int) {
Log.i(TAG, "myApp onProductChanged")
}
override fun onInitProcess(event: DJISDKInitEvent, totalProcess: Int) {
Log.i(TAG, "myApp onInitProcess")
if (event == DJISDKInitEvent.INITIALIZE_COMPLETE) {
Log.i(TAG, "myApp start registerApp")
SDKManager.getInstance().registerApp()
}
}
override fun onDatabaseDownloadProgress(current: Long, total: Long) {
Log.i(TAG, "myApp onDatabaseDownloadProgress")
}
})
}
}
【Import the UXSDK open source module】
- Copy the whole UXSDK project from the sample to your myApplication project's app/libs.
- Click File->New->Import Module, choose the android-sdk-v5-uxsdk project under the myapplication project's app/libs path, click finish.
-
Edit the settings.gradle file.
rootProject.name = "My Application"
include ':app', ':android-sdk-v5-uxsdk'
project(':android-sdk-v5-uxsdk').projectDir = new File(rootDir, 'app/libs/android-sdk-v5-uxsdk/') -
Edit the build.gradle(:android-sdk-v5-uxsdk) file to make it identical with the build.gradle file in myApplication project.
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 32
resourcePrefix "uxsdk_"
defaultConfig {
minSdkVersion 23
targetSdkVersion 32
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions{
jvmTarget = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.squareup.okio:okio:1.15.0'
implementation 'com.squareup.wire:wire-runtime:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
implementation 'androidx.lifecycle:lifecycle-runtime:2.3.1'
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
implementation 'androidx.media:media:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.core:core-ktx:1.3.2"
api 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'com.airbnb.android:lottie:3.3.1'
implementation 'androidx.cardview:cardview:1.0.0'
api 'org.maplibre.gl:android-plugin-annotation-v9:1.0.0'
api 'org.maplibre.gl:android-sdk-turf:5.9.0'
api 'org.maplibre.gl:android-sdk:9.4.2'
api 'com.amap.api:3dmap:7.3.0'
api 'com.amap.api:search:7.3.0'
api 'com.google.android.gms:play-services-places:16.0.0'
api 'com.google.android.gms:play-services-maps:16.0.0'
api 'com.google.android.gms:play-services-location:16.0.0'
api 'com.google.android.gms:play-services-base:16.0.0'
compileOnly "com.dji:dji-sdk-v5-aircraft-provided:5.2.0"
compileOnly "com.dji:dji-sdk-v5-aircraft:5.2.0"
} - Sync the project.
Comments
3 comments
I am trying to implment the sdk in a new project, So far I have successfully integrated the sdk and got successful registration callback. But I am facing issue in implementing UXSDK. When I try ti import the module as u told in the article gives me an error saying "Project already contains module with this name" but when i try to use any class or widget from the uxsdk its saying undefined. Can you help me a bit?
I have also downloaded the source code u provided using the password but that source code doesn't include uxsdk module
Edit as below, this will install the SDK library, you can refer to the DJIAllApplication in our
ıt gives page not found 404 ERROR
Has anyone succeeded in following these instructions? I've built an app before on the SDK4, and I've got the SDK5 Sample App running with Mini3 Pro - but ran into many build issues when trying to modify an existing "hello world" app according to these instructions. Most of these arise from the fact that the instructions involve copying over the entire uxsdk - and that involves a lot of dependencies. You you get trapped in dependency hell trying to fix dependencies (like mapbox) that you might not even need. It would be great to have a more minimal sample to use as a starting point. As is - I think I'll give up and just try to start with the working sample app keep cutting things out until I understand the minimal dependencies required to get this working.
Please sign in to leave a comment.