android library crash on start MultiDex

2019-08-23 19:45发布

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'

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-23 20:16

try to add to android section:

dexOptions { javaMaxHeapSize "2g" }

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

查看更多
Juvenile、少年°
3楼-- · 2019-08-23 20:18

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 { ... }
查看更多
趁早两清
4楼-- · 2019-08-23 20:22

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

查看更多
登录 后发表回答