将multidex添加到我的应用程序后,由于“ java.lang.NoClassDefFoundError”,检测运行失败 [英] Instrumentation run failed due to 'java.lang.NoClassDefFoundError' after adding multidex to my application

查看:206
本文介绍了将multidex添加到我的应用程序后,由于“ java.lang.NoClassDefFoundError”,检测运行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是此问题的延续:无法合并dex-如何排除适当的jar?

我没有典型的android项目,我只是在单独的模块上工作,该模块与活动无关清单中的,片段,UI等,我没有声明任何Android规范。这是我的清单:

I have not a typical android project, i am just working on the separate module, which is not connected with activies, fragments, UI etc. in my manifest i am not declaring any Android specifiacions. Here is my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.moduleName.sampleName"
>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>

</manifest>

我有一个例外:


原因:com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中:65536

Caused by: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

所以,这是我的build.gradle文件现在的样子:

So, here is what my build.gradle file looks like now:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"


packagingOptions {
    exclude 'protobuf.meta'
}

testOptions {
    unitTests {
        includeAndroidResources = true
    }

}
sourceSets {
    test.java.srcDirs += ['build/generated/source/apt/test/debug']
}

defaultConfig {
    multiDexEnabled true
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"

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

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
 }

}

ext.daggerVersion = '2.11'
ext.roomVersion = '1.0.0-rc1'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:26.1.0'
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'
testImplementation "org.robolectric:robolectric:3.4.2"
kaptTest "com.google.dagger:dagger-compiler:$daggerVersion"
kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion"


// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.1.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

// Room
implementation "android.arch.persistence.room:runtime:$roomVersion"
implementation "android.arch.persistence.room:rxjava2:$roomVersion"
kapt "android.arch.persistence.room:compiler:$roomVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.1.51"
androidTestImplementation "android.arch.persistence.room:testing:$roomVersion"

// Dagger
implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"

implementation 'pl.charmas.android:android-reactive-location2:2.0@aar'
implementation 'com.google.android.gms:play-services-location:11.4.2'
implementation 'com.google.android.gms:play-services-places:11.4.2'

//Jackson
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.1'

implementation 'com.android.support:multidex:1.0.2'

}

test包中的我的测试正常。

My tests that are in the package 'test' are working fine.

但是当我尝试在我的androidTest类包中运行一些测试时,我得到了:

But when i trying to run some test in my androidTest class package i get this:


开始运行测试
测试运行失败:由于'java.lang.NoClassDefFoundError'
空测试套件,使测试运行失败。

Started running tests Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError' Empty test suite.

总结:

这个问题的开始在上面的链接中-添加杰克逊库后,我有大量方法,所以我添加了dex支持,这使我陷入了这个问题,我真的不知道该如何解决-试图排除一些依赖并只保留非常重要的内容,尝试清理项目,删除构建包。他们都没有工作。如果重要的是我在此模块中使用Kotlin

The beginning of this problem is in the link above - i was having large amount of methods after adding jackson library, so i added dex support and this got me to this problem, which i really don't know how to solve - trying to exclude some depenendencies and leave only really important, trying to clean the project, deleting build package. None of them worked. If it is important i am using Kotlin in this module

推荐答案

您可能必须在AndroidManifest中添加MultiDexApplication:

You may have to add MultiDexApplication in the AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.myapp">
<application
     android:name="com.example.myapp.MyApplication" >
    ...
</application>

如果您覆盖应用程序类,将其更改为扩展MultiDexApplication(如果可能),如下所示:

If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:

public class MyApplication extends MultiDexApplication { ... }


在此处查看此Google官方博客以获取MultiDex支持

这篇关于将multidex添加到我的应用程序后,由于“ java.lang.NoClassDefFoundError”,检测运行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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