android库在启动MultiDex时崩溃 [英] android library crash on start MultiDex

查看:225
本文介绍了android库在启动MultiDex时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个android库(一个自定义按钮),并将其上传到我的JFrog Artifactory 现在,我尝试在一个示例应用程序中进行测试(真的很简单,具有默认活动).

同步进行得很顺利,我将Button添加到xml布局中,当我运行该应用程序时,它在以:开头的

之前崩溃了

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

哪个是扩展MultiDexApplication的类,

当我从库项目(带有另一个本地应用程序模块和activity)运行它时,它运行得很好,但是当我从服务器中编译它时,会导致此错误

经过大量搜索后,我尝试进行清理和重建并禁用即时运行,我尝试从xml文件中仅删除视图,但仍然崩溃,看来该应用程序库有问题.

任何人都可以帮忙吗?所有帮助将不胜感激!

我正在使用MultiDex,并且尝试了两种方法来实现它:扩展Application和扩展MultiDexApplication,相同的结果,还尝试重建清理等等,我还尝试了-dontobfuscate,以防它是由proguard引起的./p>

这是库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'

解决方案

尝试添加到android部分:

dexOptions { javaMaxHeapSize"2g" }

此外,检查问题是否消失,是否从api 19更改为api 21.

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'

解决方案

try to add to android section:

dexOptions { javaMaxHeapSize "2g" }

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

这篇关于android库在启动MultiDex时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆