android library crash on start MultiDex

落花浮王杯 提交于 2020-01-16 18:49:10

问题


I've built an android library ( a custom button of sorts ) and uploaded it to my JFrog Artifactory now i tried testing it in an example app (really simple one with default activity) .

The sync went well and I added the Button to the xml layout , when i run the app it crashes before it starting with :

java.lang.RuntimeException: Unable to instantiate application com.mylib.library.LibApp: java.lang.ClassNotFoundException: Didn't find class "com.mylib.library.LibApp" on path: DexPathList

Which is the class that extends MultiDexApplication ,

When i run it from the library project (with another local app module and activity ) it runs great but when i compile it from the server it causes this error

After a lot of googling I've tried clean and rebuild and also disabling instant run, i tried removing just the view from the xml file but it still crashes , it seems the app has a problem with the library .

Anyone can help ? all help would be appreciated !

EDIT :

I'm using MultiDex and i've tried two ways to implement it , extending Application and extending MultiDexApplication , same result , also tried rebuilding cleaning and so on , i also tried -dontobfuscate i case it was caused because of proguard

This are the library build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0.1"
        multiDexEnabled true

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexEnabled true
        } }}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-messaging:11.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.google.dagger:dagger:2.9'
    compile 'com.squareup.retrofit2:retrofit:2.+'
    compile 'com.squareup.retrofit2:converter-gson:2.+'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.+'
    compile 'io.reactivex:rxjava:1.0.4'
    compile "com.google.android.gms:play-services-gcm:11.0.4"
    compile 'io.reactivex:rxandroid:0.24.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:23.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
    provided 'javax.annotation:jsr250-api:1.0'
    compile 'com.evernote:android-job:1.1.8'
    compile 'com.android.support:multidex:1.0.2'
}
apply plugin: 'com.google.gms.google-services'

回答1:


try to add to android section:

dexOptions { javaMaxHeapSize "2g" }

also, check if you change from api 19 to api 21, if the problem disappear.




回答2:


Try adding this to your class which extends Application.

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

Adding multiDexEnabled true is not enough for it to actually work.

EDIT:

There are other options if this does not suit you:

Adding it via AndroidManifest.xml:

<application
    android:name="android.support.multidex.MultiDexApplication" >
    ...
</application>

Or, instead of extendig Application, extend MultiDexApplication:

public class MyApplication extends MultiDexApplication { ... }



回答3:


It happens when one or more of the 3 party libraries isn't build as expected. Try checking whether there are newer versions of those libraries



来源:https://stackoverflow.com/questions/48826836/android-library-crash-on-start-multidex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!