我有一个运行API 21的多索引的大型应用程序,有Dagger 1.2,当我使用Jake Wharton的ActivityRule添加Espresso时,它无法在模拟器或物理手机上安装该应用程序。我得到以下对话框。
安装失败,因为设备可能有与当前版本不匹配的过时dexed jar(dexopt错误)。 要继续,您必须卸载现有的应用程序。
警告:卸载将删除应用程序数据! 是否要卸载现有应用程序?
我点击确定,测试框架意外退出
Testing started at 4:23 PM ...
目标设备:genymotion-google_nexus_4 ___ 5_0_0 ___ api_21 ___ 768x1280-192.168.56.101:5555 安装APK:C:\ AAAAAOtto \ Otto \ Otto \ app \ build \ outputs \ apk \ app-developercode-debug.apk 将文件上传到:/data/local/tmp/com.example.myapp 安装com.example.myapp DEVICE SHELL COMMAND:pm install -r" /data/local/tmp/com.example.myapp" pkg:/data/local/tmp/com.example.myapp 失败[INSTALL_FAILED_DEXOPT]
DEVICE SHELL COMMAND:pm uninstall com.example.myapp DELETE_FAILED_INTERNAL_ERROR
这里我的gradle构建调试版本的最小值和最大值为api 21,显然没有带来任何预售5.0问题。
buildscript {
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "org.codehaus.groovy:gradle-groovy-android-plugin:0.3.5"
classpath 'io.fabric.tools:gradle:1.+'
}
}
申请插件:' com.android.application' 申请插件:' io.fabric'
知识库{ maven {url' https://maven.fabric.io/public' } }
android {
compileSdkVersion 21
buildToolsVersion "23.0.1"
defaultConfig {
applicationId 'com.example.myapp'
minSdkVersion 16
targetSdkVersion 21
versionCode 1430
versionName "1.4.30"
multiDexEnabled = true
// testInstrumentationRunner" com.android.test.runner.MultiDexTestRunner" // testInstrumentationRunner" android.support.test.runner.AndroidJUnitRunner" }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'LICENSE.txt'
}
dexOptions {
preDexLibraries = false
}
productFlavors {
developercode {
minSdkVersion 21
applicationId 'com.example.myapp'
targetSdkVersion 21
versionCode 1430
versionName '1.4.30'
}
integrationcode {
minSdkVersion 16
applicationId 'com.example.myapp'
targetSdkVersion 21
versionCode 1430
versionName '1.4.30'
}
eridesharecode {
minSdkVersion 16
applicationId 'com.example.myapp'
targetSdkVersion 21
versionCode 1430
versionName '1.4.30'
}
}
dexOptions { javaMaxHeapSize "2g" }
compileOptions {
encoding "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.squareup.okio:okio:1.1.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.joanzapata.android:android-iconify:1.0.6'
compile 'com.tundem.aboutlibraries:library:4.0.1@aar'
compile 'com.squareup.retrofit:retrofit:1.9.0'
provided 'com.squareup.dagger:dagger:1.2.+'
compile 'com.google.android.gms:play-services:+'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'de.greenrobot:eventbus:2.1.0'
compile files('libs/nineoldandroids-2.4.0.jar')
provided 'com.squareup.dagger:dagger-compiler:1.2.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.joanzapata.mapper:simple-mapper:1.0.10'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile 'javax.mail:mail:1.4.7'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile 'com.android.support:multidex:1.0.0'
// Espresso
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
// {
// exclude group: 'javax.inject'}
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex'}
// // Jacoco config
// apply plugin: 'jacoco'
//
// jacoco {
// // Use this version for upper ones are broken (with Gradle)
// // https://github.com/jacoco/jacoco/issues/288
// toolVersion = "0.7.1.201405082137"
// }
//
//// Edit covered scope if needed
//// For my part I like having the coverage of both application and tests
// def coverageSourceDirs = [
// '../app/src'
// ]
//
// task jacocoTestReport(type: JacocoReport, dependsOn: "test") {
// group = "Reporting"
//
// description = "Generate Jacoco coverage reports"
//
// classDirectories = fileTree(
// dir: '../app/build/intermediates/classes',
// excludes: ['**/R.class',
// '**/R$*.class',
// '**/*$ViewInjector*.*',
// '**/BuildConfig.*',
// '**/Manifest*.*']
// )
//
// additionalSourceDirs = files(coverageSourceDirs)
// sourceDirectories = files(coverageSourceDirs)
// executionData = files('../app/build/jacoco/testUnitTestDebug.exec')
//
// reports {
// xml.enabled = true
// html.enabled = true
// }
//
// }
////end Jacoco config
}
P.S。我试过上面有和没有Jacoco修复,没有区别。
我的manifest.xml的重要部分
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidDomInspection -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.myapp">
<uses-feature
android:glEsVersion="0x00020000"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.animator"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.location"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-permission
android:name="com.example.myapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<!-- The following four permissions -->
<!-- <uses-permission android:name="android.permission.GET_TASKS" /> -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.CAMERA" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_LOGS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcherx"
android:label="@string/app_name"
android:theme="@style/BaseTheme1"
tools:replace="android:icon,android:theme"
android:name="android.support.multidex.MultiDexApplication">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/map_v2_api_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.myapp.MainActivity"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
...
/>
</application>
</manifest>
对于应用,我有以下Android Studio配置集
android.support.test.runner.AndroidJUnitRunner
扩展应用程序类
protected void attachBaseContext(Context base)
{
super.attachBaseContext(base);
MultiDex.install(this);
}