Skip to content

Commit

Permalink
Android upgrades and fixes (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
orenagiv committed Jun 11, 2022
1 parent a5881cc commit 24e1f0d
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 268 deletions.
2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 78 additions & 68 deletions android/build.gradle
@@ -1,15 +1,15 @@
group 'cloud.dragonx.plugin.flutter.dji'
version '1.0-SNAPSHOT'
group "cloud.dragonx.plugin.flutter.dji"
version "1.0-SNAPSHOT"

buildscript {
ext.kotlin_version = '1.5.31'
ext.kotlin_version = "1.6.20"
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
Expand All @@ -22,39 +22,39 @@ rootProject.allprojects {
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "kotlinx-serialization"

android {
compileSdkVersion 31
// useLibrary 'org.apache.http.legacy'
useLibrary "org.apache.http.legacy"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = "1.8"
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.java.srcDirs += "src/main/kotlin"
}

defaultConfig {
minSdkVersion 24
targetSdkVersion 30
minSdkVersion 19
targetSdkVersion 31

multiDexEnabled true
// ndk {
// abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
// }
}

// dexOptions {
// javaMaxHeapSize "4g"
// }
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', 'arm64-v8a'
}
}

packagingOptions {
doNotStrip "*/*/libdjivideo.so"
Expand All @@ -77,60 +77,70 @@ android {
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'

pickFirst "lib/*/libstlport_shared.so"
pickFirst "lib/*/libRoadLineRebuildAPI.so"
pickFirst "lib/*/libGNaviUtils.so"
pickFirst "lib/*/libGNaviMapex.so"
pickFirst "lib/*/libGNaviData.so"
pickFirst "lib/*/libGNaviMap.so"
pickFirst "lib/*/libGNaviSearch.so"
pickFirst "lib/*/libDJIFlySafeCore.so"
pickFirst "lib/*/libdjifs_jni.so"
pickFirst "lib/*/libsfjni.so"
exclude "META-INF/proguard/okhttp3.pro"
exclude "META-INF/rxjava.properties"
exclude "assets/location_map_gps_locked.png"
exclude "assets/location_map_gps_3d.png"
}
}

dependencies {
implementation 'androidx.multidex:multidex:2.0.1'

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
// testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0'

implementation('com.dji:dji-sdk:4.16.1', {
/**
* Uncomment the "library-anti-distortion" if your app does not need Anti Distortion for Mavic 2 Pro and Mavic 2 Zoom.
* Uncomment the "fly-safe-database" if you need database for release, or we will download it when DJISDKManager.getInstance().registerApp
* is called.
* Both will greatly reducing the size of the APK.
*/
exclude module: 'library-anti-distortion'
//exclude module: 'fly-safe-database'
implementation ("com.dji:dji-sdk:4.16.1", {
exclude module: "library-anti-distortion"
exclude module: "fly-safe-database"
})
implementation ("com.dji:dji-uxsdk:4.16", {
exclude module: "dji-sdk"
exclude group: "com.amap.api"
})
compileOnly 'com.dji:dji-sdk-provided:4.16.1'
compileOnly ("com.dji:dji-sdk-provided:4.16.1")

// https://stackoverflow.com/questions/58281124/layout-constraintbottom-totopof-not-found
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'

implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.core:core:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.annotation:annotation:1.2.0'
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
implementation "androidx.core:core-ktx:1.6.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0"

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.lifecycle:lifecycle-viewmodel-ktx:2.3.1"

// implementation 'androidx.test:runner:1.4.0@aar'

implementation "androidx.constraintlayout:constraintlayout:2.1.4"

implementation "androidx.multidex:multidex:2.0.1"
implementation "androidx.appcompat:appcompat:1.4.2"
implementation "com.google.android.material:material:1.6.1"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0"
implementation "androidx.annotation:annotation:1.3.0"

// Kotlin Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"

// Ktx
implementation "androidx.activity:activity-ktx:1.4.0"
implementation "androidx.core:core-ktx:1.8.0"
implementation "androidx.fragment:fragment-ktx:1.4.1"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-process:2.4.1"

// Lifecycle, LiveData, ViewModel
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.4.1"

// ButterKnife
implementation "com.jakewharton:butterknife:10.0.0"
annotationProcessor "com.jakewharton:butterknife-compiler:10.0.0"

// Junit
testImplementation "junit:junit:4+"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"

implementation "com.squareup:otto:1.3.8"
}
90 changes: 0 additions & 90 deletions android/proguard-rules.pro

This file was deleted.

Expand Up @@ -21,7 +21,6 @@ import dji.common.util.CommonCallbacks
import dji.sdk.base.BaseComponent
import dji.sdk.base.BaseProduct
import dji.sdk.base.BaseProduct.ComponentKey
import dji.sdk.camera.VideoFeeder
import dji.sdk.flightcontroller.FlightController
import dji.sdk.media.DownloadListener
import dji.sdk.media.MediaFile
Expand All @@ -37,6 +36,7 @@ import dji.sdk.products.Aircraft
import dji.sdk.sdkmanager.DJISDKInitEvent
import dji.sdk.sdkmanager.DJISDKManager
import dji.sdk.sdkmanager.DJISDKManager.SDKManagerCallback
import dji.sdk.camera.VideoFeeder
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
Expand All @@ -48,8 +48,7 @@ import kotlinx.serialization.json.Json
import java.io.File
import java.nio.ByteBuffer


/** DjiPlugin */
/** DjiPlugin */

class DjiPlugin: FlutterPlugin, Messages.DjiHostApi, ActivityAware {
/// The MethodChannel that will the communication between Flutter and native Android
Expand All @@ -70,13 +69,21 @@ class DjiPlugin: FlutterPlugin, Messages.DjiHostApi, ActivityAware {
private var drone: Aircraft? = null
private var droneCurrentLocation: LocationCoordinate3D? = null // Note: this is different from DJI SDK iOS where CLLocation.coordinate is used (LocationCoordinate3D in dji-android is the same as CLLocation.coordinate in dji-ios).
private var mediaFileList: MutableList<MediaFile> = ArrayList<MediaFile>()

private var videoDataListener: VideoFeeder.VideoDataListener? = null
// private lateinit var sourceListener: VideoFeeder.PhysicalSourceListener

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
Messages.DjiHostApi.setup(flutterPluginBinding.binaryMessenger, this)
fltDjiFlutterApi = Messages.DjiFlutterApi(flutterPluginBinding.binaryMessenger)

this.djiPluginContext = flutterPluginBinding.applicationContext

// Preparing the Video Feed Listener
// Note: this must come here, and not inside the videoFeedStart method, because otherwise it would trigger a "class not found" exception.
videoDataListener = VideoFeeder.VideoDataListener { bytes, _ ->
_fltSendVideo(bytes)
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
Expand Down Expand Up @@ -750,20 +757,30 @@ class DjiPlugin: FlutterPlugin, Messages.DjiHostApi, ActivityAware {
/** Video Feed Methods **/

override fun videoFeedStart() {
if (videoDataListener == null) {
videoDataListener = VideoFeeder.VideoDataListener { bytes, _ ->
_fltSendVideo(bytes)
}
}
// sourceListener = VideoFeeder.PhysicalSourceListener { videoFeed, newPhysicalSource ->
// if (videoFeed === VideoFeeder.getInstance().primaryVideoFeed) {
// Log.d(TAG, "Video Feed - Primary Source: $newPhysicalSource")
// }
// }
// VideoFeeder.getInstance().addPhysicalSourceListener(sourceListener)

// if (videoDataListener == null) {
// videoDataListener = VideoFeeder.VideoDataListener { bytes, _ ->
// _fltSendVideo(bytes)
// }
// }

videoDataListener?.let {
VideoFeeder.getInstance()?.primaryVideoFeed?.addVideoDataListener(it)
}
}

override fun videoFeedStop() {
videoDataListener?.let {
VideoFeeder.getInstance()?.primaryVideoFeed?.removeVideoDataListener(it)
}
// videoDataListener?.let {
// VideoFeeder.getInstance()?.primaryVideoFeed?.removeVideoDataListener(it)
// }

VideoFeeder.getInstance()?.primaryVideoFeed?.listeners?.clear()
}

}
Expand Down

0 comments on commit 24e1f0d

Please sign in to comment.