Mobile-UXSDK-Android icon indicating copy to clipboard operation
Mobile-UXSDK-Android copied to clipboard

findViewById获取到的View无法转换为FPVWidget对象

Open qimi-dev opened this issue 5 years ago • 7 comments

在使用demo中,以下代码能正常运行,但编译器会标记错误: FPVWidget fpvWidget = findViewById(R.id.fpv_widget);

View对象无法转换为FPVWidget 对象

qimi-dev avatar Aug 10 '20 09:08 qimi-dev

Translation:

The View obtained by ndViewById cannot be converted to FPVWidget object #92

In the demo, the following code can run normally, but the compiler will mark an error: FPVWidget fpvWidget = findViewById(R.id.fpv_widget);

View object cannot be converted to FPVWidget object

dji-lisafedane avatar Aug 10 '20 15:08 dji-lisafedane

@qimikimi what is your compile sdk version? Since API 26 you no longer have to manually cast views returned by findViewByID. This is because it is now using Java's generics automatic type inference. Learn more:

  • https://stackoverflow.com/a/44903372/3641665
  • https://www.techyourchance.com/casting-android-views/

alainpimentel avatar Aug 11 '20 02:08 alainpimentel

@alainpimentel I use com.dji:dji-uxsdk:4.10 and this problem does not occur, but it will appear when I change it to com.dji:dji-uxsdk:4.13

qimi-dev avatar Aug 11 '20 13:08 qimi-dev

@alainpimentel error message: Required type: FPVWidget Provided: View Type parameter T has incompatible upper bounds: View and FPVWidget

qimi-dev avatar Aug 11 '20 13:08 qimi-dev

@qimikimi can you post your build.gradle's android block? this could be an issue with your configuration. If you are using the same configuration as the current sample app's build.gradle https://github.com/dji-sdk/Mobile-UXSDK-Android/blob/master/sample/build.gradle, try invalidating cache and restart https://stackoverflow.com/a/42824662/3641665 I see a lot of developers had this error when data binding was enabled.

alainpimentel avatar Aug 11 '20 23:08 alainpimentel

invalidating cache and restart cannot solve my problem. build.gradle:

apply plugin: 'com.android.application'

repositories {
    mavenLocal()
}

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.3'
    defaultConfig {
        applicationId "com.dji.ux.sample"
        minSdkVersion 19
        targetSdkVersion 29
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        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', 'x86', 'arm64-v8a'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "3g"
    }
    lintOptions{
        abortOnError false
    }
    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"

        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'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    //Internal maven 4.11 exist error. please use 4.11.0.1 in internal maven.
    implementation ('com.dji:dji-uxsdk:4.13', {
        /**
         * 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'

        /**
         * 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.13')

    // AMAP: Do not include if publishing to Google Play Store
    implementation 'com.amap.api:3dmap:6.9.2'
    implementation 'com.amap.api:search:6.9.2'
    implementation 'com.amap.api:location:4.7.0'

    implementation 'org.greenrobot:eventbus:3.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.annotation:annotation:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-rc01'
    implementation 'androidx.core:core:1.0.0'
    implementation 'androidx.annotation:annotation:1.0.0'

    //HERE maps
    implementation files('libs/HERE-sdk-3.15.0.aar')

}

qimi-dev avatar Aug 12 '20 01:08 qimi-dev

@qimikimi - sorry for the delayed response. we'll need to look into this further for you. can you start a help desk ticket using this form: https://formcrafts.com/a/dji-developer-feedback-en or email me at [email protected]. Please use a standard bug reporting format:

  1. SDK Used:
  2. SDK Version:
  3. Description:
  4. Expected results:
  5. Actual results:
  6. Code Samples/Notes/Screenshots

Please provide a link to this issue when you report the bug!

dji-lisafedane avatar Sep 18 '20 23:09 dji-lisafedane