pplication的使用会导致Robolectric测试应用程

pplication的使用会导致Robolectric测试应用程

本文介绍了MultiDexApplication的使用会导致Robolectric测试应用程序类,打破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

添加多DEX支持,支持V4-R21采用摇篮DEF(https://plus.google.com/+IanLake/posts/JW9x4pcB1rj)

 应用插件:com.android.application

安卓{
compileSdkVersion 19
buildToolsVersion20.0.0

defaultConfig {
    的applicationIDinfo.osom.multidex
    的minSdkVersion 19
    targetSdkVersion 19
    版本code 1
    VERSIONNAME1.0
}
buildTypes {
    推出 {
        runProguard假
        proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'proguard-rules.pro
    }
}

dexOptions {
    preDexLibraries = FALSE
}

afterEvaluate {
    tasks.matching {
    it.name.startsWith(DEX)
    } {。每个DX  - >
    如果(dx.additionalParameters == NULL){
        dx.additionalParameters = []
    }
    dx.additionalParameters + ='--multi-DEX
    dx.additionalParameters + = - 主-DEX-列表= $ PROJECTDIR / multidex.keep的ToString()
}
 

现在这个工程的应用程序本身,我能够构建和部署,但是当我运行一个robolectric测试我的应用程序类,我从ZipUtils失败(这是陷入MultiDex.java)。其他的测试运行良好。下面是跟踪 -

解决方案

这是一个已知的错误,等待修复:的

Adding Multi dex support with the support v4-r21 using gradle def (https://plus.google.com/+IanLake/posts/JW9x4pcB1rj)

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "info.osom.multidex"
    minSdkVersion 19
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dexOptions {
    preDexLibraries = false
}

afterEvaluate {
    tasks.matching {
    it.name.startsWith('dex')
    }.each { dx ->
    if (dx.additionalParameters == null) {
        dx.additionalParameters = []
    }
    dx.additionalParameters += '--multi-dex'
    dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
}

Now this works for the app itself and I'm able to build and deploy but when I run a robolectric test for my Application class, I get a failure from ZipUtils (which is caught in MultiDex.java). The other tests are running fine. Here is the trace -

解决方案

It's a known bug, wait for a fix: https://github.com/robolectric/robolectric/issues/1328

这篇关于MultiDexApplication的使用会导致Robolectric测试应用程序类,打破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:29