dji-sdk / Mobile-UXSDK-Android

DJI Mobile UXSDK is a suite of product agnostic UI objects that fast tracks the development of Android applications using the DJI Mobile SDK.
Other
153 stars 110 forks source link

Default DJI EventBus instance already exists. #130

Closed magiclingfeng closed 3 years ago

magiclingfeng commented 3 years ago

PreFlightStatusWidget不更新连接状态 ,其他的状态都是正常的,看日志是EventBus出问题了

我的环境如下:

build.gradle

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-kapt'
}

apply from: '../shared_dependencies.gradle'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        minSdkVersion 22
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

    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"

        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 {

    //DJI SDK
    api('com.dji:dji-uxsdk:4.14', {
        /**
         * Comment the "library-anti-distortion" if your app does need Anti Distortion for Mavic 2 Pro and Mavic 2 Zoom.
         * Comment the "fly-safe-database" if you do not need database for release, or we will download it when DJISDKManager.getInstance().registerApp
         * is called.
         * Both will greatly reduce the size of the APK.
         */
        exclude module: 'library-anti-distortion'
        exclude module: 'fly-safe-database'

        /**
         * Uncomment the following line to exclude amap from the app.
         * Note that Google Play Store does not allow APKs that include this library.
         */
        // exclude group: 'com.amap.api'
    })

    /**
     * Uncomment the following block if you are using an SDK version does not match the UX SDK
     * version above. For example, this could be used if the SDK has a minor release version
     * ahead of the UX SDK.
     */
// implementation ('com.dji:dji-sdk:4.14', {
//    /**
//     * 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 reduce the size of the APK.
//     */
//     exclude module: 'library-anti-distortion'
//     exclude module: 'fly-safe-database'
//
//    /**
//     * Uncomment the following line to exclude amap from the app.
//     * Note that Google Play Store does not allow APKs that include this library.
//     */
//    // exclude group: 'com.amap.api'
// })

    compileOnly 'com.dji:dji-sdk-provided:4.14.1'

    implementation(project(':lib-comm'))
    implementation(project(':map-sdk'))

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

layout

<?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"
    android:orientation="horizontal"
    tools:context=".MainActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <!-- Widget to see first person view (FPV) -->
        <dji.ux.widget.FPVWidget
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <!--    <dji.ux.widget.FPVOverlayWidget-->
        <!--        android:layout_width="match_parent"-->
        <!--        android:layout_height="match_parent"-->
        <!--        android:visibility="gone"-->
        <!--        />-->

        <!--    <dji.ux.workflow.CompassCalibratingWorkFlow-->
        <!--        android:layout_width="match_parent"-->
        <!--        android:layout_height="match_parent"-->

        <!--        android:visibility="gone"-->
        <!--        />-->

    </androidx.constraintlayout.widget.ConstraintLayout>
    <!-- Widgets in top status bar -->
    <LinearLayout
        android:id="@+id/signal"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:background="@color/dark_gray"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <dji.ux.widget.PreFlightStatusWidget
            android:layout_width="238dp"
            android:layout_height="25dp"
            />

        <dji.ux.widget.FlightModeWidget
            android:layout_width="103dp"
            android:layout_height="22dp" />

        <dji.ux.widget.GPSSignalWidget
            android:layout_width="44dp"
            android:layout_height="22dp" />

        <dji.ux.widget.VisionWidget
            android:layout_width="22dp"
            android:layout_height="22dp" />

        <dji.ux.widget.RemoteControlSignalWidget
            android:layout_width="38dp"
            android:layout_height="22dp" />

        <dji.ux.widget.VideoSignalWidget
            android:layout_width="38dp"
            android:layout_height="22dp" />

        <dji.ux.widget.WiFiSignalWidget
            android:layout_width="22dp"
            android:layout_height="20dp" />

        <dji.ux.widget.BatteryWidget
            android:layout_width="96dp"
            android:layout_height="22dp"
            app:excludeView="singleVoltage" />

        <dji.ux.widget.ConnectionWidget
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:layout_marginTop="3dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/signal"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:background="@color/dark_gray"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/signal">

        <dji.ux.widget.AutoExposureLockWidget
            android:layout_width="30dp"
            android:layout_height="30dp" />

        <dji.ux.widget.FocusExposureSwitchWidget
            android:layout_width="30dp"
            android:layout_height="30dp" />

        <dji.ux.widget.FocusModeWidget
            android:layout_width="30dp"
            android:layout_height="30dp" />

        <dji.ux.widget.config.CameraConfigISOAndEIWidget
            android:layout_width="60dp"
            android:layout_height="30dp" />

        <dji.ux.widget.config.CameraConfigShutterWidget
            android:layout_width="60dp"
            android:layout_height="30dp" />

        <dji.ux.widget.config.CameraConfigApertureWidget
            android:layout_width="60dp"
            android:layout_height="30dp" />

        <dji.ux.widget.config.CameraConfigEVWidget
            android:layout_width="60dp"
            android:layout_height="30dp" />

        <dji.ux.widget.config.CameraConfigWBWidget
            android:layout_width="70dp"
            android:layout_height="30dp" />

        <dji.ux.widget.config.CameraConfigStorageWidget
            android:layout_width="130dp"
            android:layout_height="30dp" />
    </LinearLayout>

    <dji.ux.widget.ManualFocusWidget
        android:layout_width="42dp"
        android:layout_height="218dp"
        android:layout_below="@id/camera"
        android:layout_alignLeft="@id/camera"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="5dp"
        app:layout_constraintStart_toEndOf="@+id/camera"
        app:layout_constraintTop_toBottomOf="@+id/camera"
        tools:ignore="RtlHardcoded" />

    <dji.ux.widget.RemainingFlightTimeWidget
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="18dp"
        android:background="@color/transparent"
        app:layout_constraintTop_toTopOf="parent" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"

        android:padding="12dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <dji.ux.widget.dashboard.DashboardWidget
            android:id="@+id/Compass"
            android:layout_width="405dp"
            android:layout_height="91dp"
            android:layout_marginRight="12dp"
            tools:ignore="RtlHardcoded" />

    </LinearLayout>

    <!--Take off and return home buttons on left -->
    <LinearLayout
        android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginStart="12dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <dji.ux.widget.TakeOffWidget
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginBottom="12dp" />

        <dji.ux.widget.ReturnHomeWidget
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginTop="12dp" />
    </LinearLayout>

    <!--    <dji.ux.widget.controls.CameraControlsWidget-->
    <!--        android:id="@+id/CameraCapturePanel"-->
    <!--        android:layout_alignParentRight="true"-->
    <!--        android:layout_below="@id/camera"-->
    <!--        android:layout_width="50dp"-->
    <!--        android:layout_height="213dp"-->
    <!--        tools:ignore="RtlHardcoded"/>-->

    <!--    <dji.ux.panel.CameraSettingExposurePanel-->
    <!--        android:layout_width="180dp"-->
    <!--        android:layout_below="@id/camera"-->
    <!--        android:layout_toLeftOf="@+id/CameraCapturePanel"-->
    <!--        android:background="@color/transparent"-->
    <!--        android:gravity="center"-->
    <!--        android:layout_height="263dp"-->
    <!--        android:visibility="invisible"-->
    <!--        tools:ignore="RtlHardcoded"/>-->

    <!--    <dji.ux.panel.CameraSettingAdvancedPanel-->
    <!--        android:layout_width="180dp"-->
    <!--        android:layout_height="263dp"-->
    <!--        android:layout_below="@id/camera"-->
    <!--        android:layout_toLeftOf="@+id/CameraCapturePanel"-->
    <!--        android:background="@color/transparent"-->
    <!--        android:gravity="center"-->
    <!--        android:visibility="invisible"-->
    <!--        tools:ignore="RtlHardcoded"/>-->

    <!--    &lt;!&ndash; Pre-flight checklist panel &ndash;&gt;-->
    <!--    <dji.ux.panel.PreFlightCheckListPanel-->
    <!--        android:layout_width="400dp"-->
    <!--        android:layout_height="wrap_content"-->
    <!--        android:layout_below="@id/signal"-->
    <!--        custom:excludeItem="ESCStatus"-->
    <!--        android:visibility="gone"/>-->

</androidx.constraintlayout.widget.ConstraintLayout>

错误如下:

2021-06-25 11:44:53.204 25269-25269/com.lingyun.app.dji E/DjiLog: Default DJI EventBus instance already exists. It may be only set once before it's used the first time to ensure consistent behavior. 
    ------ begin of trace ------
    dalvik.system.VMStack.getThreadStackTrace(Native Method)
    java.lang.Thread.getStackTrace(Thread.java:1730)
    com.dji.frame.util.V_JsonUtil.getTrace(Unknown Source:4)
    dji.midware.util.ddf.nhf(Unknown Source:24)
    dji.midware.util.ddf.fdd(Unknown Source:0)
    dji.internal.logics.LogicManager.<init>(Unknown Source:33)
    dji.internal.logics.LogicManager.<init>(Unknown Source:0)
    dji.internal.logics.LogicManager$HOLDER.<clinit>(Unknown Source:3)
    dji.internal.logics.LogicManager$HOLDER.access$100(Unknown Source:0)
    dji.internal.logics.LogicManager.getInstance(Unknown Source:0)
    dji.ux.widget.PreFlightStatusWidget.onAttachedToWindow(Unknown Source:10)
    android.view.View.dispatchAttachedToWindow(View.java:19731)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3443)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3450)
    android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2201)
    android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1857)
    android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8089)
    android.view.Choreographer$CallbackRecord.run(Choreographer.java:1057)
    android.view.Choreographer.doCallbacks(Choreographer.java:875)
    android.view.Choreographer.doFrame(Choreographer.java:776)
    android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1042)
    android.os.Handler.handleCallback(Handler.java:888)
    android.os.Handler.dispatchMessage(Handler.java:100)
    android.os.Looper.loop(Looper.java:213)
    android.app.ActivityThread.main(ActivityThread.java:8178)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
    ------ end of trace ------
magiclingfeng commented 3 years ago

我找到原因了 需要把PreFlightCheckListPanel也加到xml里面才能正确显示