dji-sdk / Mobile-SDK-Android

DJI Mobile SDK for Android: http://developer.dji.com/mobile-sdk/
Other
991 stars 580 forks source link

java.lang.NoClassDefFoundError Only In Debug Build #428

Open maxkunes opened 5 years ago

maxkunes commented 5 years ago

(Instant Run Is Disabled)

When I change the build variants on my project to release, my application runs fine without crashing.

I am using multidex which is being configured in my main app module's build.gradle and I pointed android to a custom Application class in which I am calling Multidex.install. This all seems to work fine as it works fine in debug mode. I have breakpointed to confirm this code is being called as expected.

But when I debug my app, it crashes with the exception:

Failed resolution of: Ldji/sdk/sdkmanager/DJISDKManager$SDKManagerCallback

This is my app's build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

repositories {
    mavenLocal()
}

android {
    signingConfigs {
        release {
            storeFile file('REDACTED\\REDACTED.jks')
            keyAlias = 'REDACTED'
            storePassword 'REDACTED'
            keyPassword 'REDACTED'
        }
    }
    compileSdkVersion 27
    buildToolsVersion '28.0.3'

    defaultConfig {
        versionCode 5
        applicationId "com.example.djiapitest"
        minSdkVersion 16
        targetSdkVersion 27
        multiDexEnabled 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 {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    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"
        exclude 'META-INF/rxjava.properties'
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    implementation 'com.android.support:multidex:1.0.2'
    compile project(path: ':djimodule')
    compile project(path: ':core')

}

The proguard file is the one from the example project for the DJI android sdk.

The output apks are similar in size, the release one I have signed.

Strangely, the debug apk has 5 .dex class files while the release one has only two.

Release: Release apk zip image.

Debug: Debug apk zip.

My app is modularized, I have my main app module, a core module, and a djiplatform module. The proguard files for the core and djiplatform module are the same as the main module. (From DJI example project)

This is what my djiplatform build.gradle looks like, the core module's build.gradle is identical apart from it doesn't import the dji libs.

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
    mavenLocal()
}

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.squareup:otto:1.3.8'
    implementation ('com.dji:dji-sdk:4.10', {
//             Uncomment the following line if your app does not need Anti Distortion for
//             Mavic 2 Pro and Mavic 2 Zoom. It will greatly reducing the size of the APK:
        exclude module: 'library-anti-distortion'
//             Uncomment the following line if your APP does not need network RTK
        exclude module: 'library-networkrtk-helper'
    })
    compileOnly 'com.dji:dji-sdk-provided:4.10'
    implementation project(path: ':core')
}

And finally, the logcat. (Externally linked as I hit the character limit)

https://pastebin.com/85u7Zjd3

trofunenko commented 5 years ago

@maxkunes Any updates with issue ?

EXEShirley commented 4 years ago

(Instant Run Is Disabled)

When I change the build variants on my project to release, my application runs fine without crashing.

I am using multidex which is being configured in my main app module's build.gradle and I pointed android to a custom Application class in which I am calling Multidex.install. This all seems to work fine as it works fine in debug mode. I have breakpointed to confirm this code is being called as expected.

But when I debug my app, it crashes with the exception:

Failed resolution of: Ldji/sdk/sdkmanager/DJISDKManager$SDKManagerCallback

This is my app's build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

repositories {
    mavenLocal()
}

android {
    signingConfigs {
        release {
            storeFile file('REDACTED\\REDACTED.jks')
            keyAlias = 'REDACTED'
            storePassword 'REDACTED'
            keyPassword 'REDACTED'
        }
    }
    compileSdkVersion 27
    buildToolsVersion '28.0.3'

    defaultConfig {
        versionCode 5
        applicationId "com.example.djiapitest"
        minSdkVersion 16
        targetSdkVersion 27
        multiDexEnabled 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 {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    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"
        exclude 'META-INF/rxjava.properties'
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    implementation 'com.android.support:multidex:1.0.2'
    compile project(path: ':djimodule')
    compile project(path: ':core')

}

The proguard file is the one from the example project for the DJI android sdk.

The output apks are similar in size, the release one I have signed.

Strangely, the debug apk has 5 .dex class files while the release one has only two.

Release: Release apk zip image.

Debug: Debug apk zip.

My app is modularized, I have my main app module, a core module, and a djiplatform module. The proguard files for the core and djiplatform module are the same as the main module. (From DJI example project)

This is what my djiplatform build.gradle looks like, the core module's build.gradle is identical apart from it doesn't import the dji libs.

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
    mavenLocal()
}

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.squareup:otto:1.3.8'
    implementation ('com.dji:dji-sdk:4.10', {
//             Uncomment the following line if your app does not need Anti Distortion for
//             Mavic 2 Pro and Mavic 2 Zoom. It will greatly reducing the size of the APK:
        exclude module: 'library-anti-distortion'
//             Uncomment the following line if your APP does not need network RTK
        exclude module: 'library-networkrtk-helper'
    })
    compileOnly 'com.dji:dji-sdk-provided:4.10'
    implementation project(path: ':core')
}

And finally, the logcat. (Externally linked as I hit the character limit)

https://pastebin.com/85u7Zjd3

Hi have you invoked com.secneo.sdk.Helper.install()? See DJISampleApplication.java in demo and see if you follow the lines.

Jai-GAY commented 3 years ago

mine is from this line of code under 4.14-trial1 in Android 5.1.1: private BaseComponent.ComponentListener mDJIComponentListener = new BaseComponent.ComponentListener() {

But did not happen in 4.13 version and 4.13.1

--------- beginning of crash 12-29 16:07:59.055 6463-6463/com.dji.sdk.sample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.dji.sdk.sample, PID: 6463 java.lang.NoClassDefFoundError: com.dji.sdk.sample.internal.controller.MainActivity$1 at com.dji.sdk.sample.internal.controller.MainActivity.(:90) at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.Class.newInstance(Class.java:1603) at android.app.Instrumentation.newActivity(Instrumentation.java:1066)