[英]android library crash on start MultiDex
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) . 我已经建立了一个android库(一个自定义按钮)并将其上传到我的JFrog Artifactory,现在我尝试在示例应用程序中进行测试(真的很简单,默认活动)。
The sync went well and I added the Button to the xml layout , when i run the app it crashes before it starting with : 同步进展顺利,我将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
Which is the class that extends MultiDexApplication , 这是扩展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 . 经过大量谷歌搜索后,我尝试清理和重建并禁用即时运行,我尝试从xml文件中仅删除视图,但仍然崩溃,看来该应用程序库有问题。
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 我正在使用MultiDex,并且尝试了两种方法来实现它,扩展Application和扩展MultiDexApplication,相同的结果,还尝试了重建清理等等,我还尝试了-dontobfuscate以防它是由于proguard引起的
This are the library build.gradle 这是库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: 尝试添加到android部分:
dexOptions { javaMaxHeapSize "2g" } dexOptions {javaMaxHeapSize“ 2g”}
also, check if you change from api 19 to api 21, if the problem disappear. 另外,如果问题消失,请检查是否从api 19更改为api 21。
Try adding this to your class which extends Application
. 尝试将其添加到扩展Application
的类中。
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Adding multiDexEnabled true
is not enough for it to actually work. 仅添加multiDexEnabled true
不足以使其实际工作。
EDIT: 编辑:
There are other options if this does not suit you: 如果这不适合您,还有其他选择:
Adding it via AndroidManifest.xml
: 通过AndroidManifest.xml
添加它:
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
Or, instead of extendig Application
, extend MultiDexApplication
: 或者,代替extendig Application
,扩展MultiDexApplication
:
public class MyApplication extends MultiDexApplication { ... }
It happens when one or more of the 3 party libraries isn't build as expected. 当3个方库中的一个或多个库未按预期构建时,就会发生这种情况。 Try checking whether there are newer versions of those libraries 尝试检查这些库是否有较新版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.