我已经构建了一个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的类,
当我从库项目(与另一个本地应用程序模块和活动一起)运行它时,它运行得很好,但是当我从服务器编译它时,它会导致这个错误。
在进行了大量的googling搜索之后,我尝试过清理和重建,并禁用了即时运行,我尝试从xml文件中删除视图,但它仍然崩溃,看起来应用程序在库中有问题。
有人能帮忙吗?所有的帮助都将不胜感激!
编辑:
我正在使用MultiDex,我尝试了两种方法来实现它,扩展应用程序和扩展MultiDexApplication,同样的结果,也尝试了重建清理等等,我也尝试了-dontobfuscate
这是库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'发布于 2018-02-18 18:24:18
尝试添加到android部分:
dexOptions { javaMaxHeapSize "2g“}
此外,请检查是否将api 19更改为api 21,问题是否消失。
发布于 2018-02-16 12:47:32
尝试将其添加到扩展Application的类中。
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}添加multiDexEnabled true不足以使其实际工作。
编辑:
如果这样做不适合你,还有其他选择:
通过AndroidManifest.xml添加
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>或者,不是扩展Application,而是扩展MultiDexApplication
public class MyApplication extends MultiDexApplication { ... }发布于 2018-02-17 17:55:48
当第三方库中的一个或多个没有按预期构建时,就会发生这种情况。尝试检查这些库是否有更新的版本。
https://stackoverflow.com/questions/48826836
复制相似问题