My android application uses the following config:
Gradle - 0.12.+
Contents of build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: 'com.android.library'
apply plugin: "jacoco"
dependencies {
compile 'commons-collections:commons-collections:3.2.1'
compile 'org.slf4j:slf4j-android:1.6.1-RC1'
// dependency injection
compile('org.roboguice:roboguice:2.0') {
exclude module: 'cglib'
exclude module: 'aopalliance'
exclude module: 'guice'
}
compile files('libs/guice-3.0-no_aop.jar')
compile 'javax.inject:javax.inject:1'
/*
* Test dependencies.
*/
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
}
android {
buildToolsVersion "20.0"
compileSdkVersion 19
buildTypes {
debug {
runProguard false
testCoverageEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 100
versionName "1.0.0"
}
/*
* Workaround for packaging bug in Android Gradle plugin regarding duplicate files.
*/
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
}
}
All my tests run successfully when property testCoverageEnabled is set to false. On setting it to true, the following exception is thrown when running the tests
Caused by: java.lang.VerifyError: *** Some class ***
at dalvik.system.DexFile.defineClass(Native Method)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:211)
at dalvik.system.DexPathList.findClass(DexPathList.java:313)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:51)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
The error happens on the line when mocks are initialised within the tests.
Has anyone managed to generate code coverage metrics for android application which uses mockito library for testing?
The following link was very useful in explaining the problem I encountered: http://www.androidpuzzles.com/168_17620080/
I subsequently switched the source and target compatibility settings to Java 1.5 and I was able to run the unit and UI tests (which used both mockito and espresso) and generate code coverage report using Jacoco.
If I had to retain Java 1.7 settings, the workaround would have been to change the scope of private methods in the class being tested to either protected or public scope. This would have then allowed me to generate the code coverage report (overcoming the issue as identified in the link included).
Jacoco coverage support has been added to the gradle plugin since 0.10.0. See http://tools.android.com/tech-docs/new-build-system.
Not quite sure I understand why you have such a complex gradle file.
You need to compile against Java 1.5 version.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
targetCompatibility JavaVersion.VERSION_1_5
}
https://code.google.com/p/android/issues/detail?id=69174
This issue has been fixed in build tools version 21+
android {
buildToolsVersion "21.1.2"
compileSdkVersion 19
...
}
Upgrade build tools to 21+ to retain Java 1.7 compatibility.
Related
On my latest release a few of my users (less than 0.2%) are getting a crash because android.support.v7.app.AppCompatDelegateImplV23 can not be found. I can not reproduce the issue, I'm only getting reports over crashlytics. I have used apktool to extract the files out of my apk and I can see AppCompatDelegateImplV23.smali in there. Any idea what could be happening?
This is my compile line on gradle:
compile 'com.android.support:appcompat-v7:23+'
This is the exception:
Fatal Exception: java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV23
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:133)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at MyActivityClass.onCreate(MyActivityClass.java:353)
at android.app.Activity.performCreate(Activity.java:6248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
EDIT: This is my main gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter() // version plugin support
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.android.tools.build:gradle:1.3.1'
}
allprojects {
repositories {
jcenter()
}
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
signingConfigs {
config {
......
}
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 14
}
}
defaultConfig {
applicationId "mypackage"
minSdkVersion 14
targetSdkVersion 23
versionCode some number
versionName "some version number"
multiDexEnabled true
signingConfig signingConfigs.config
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent,"myapk.apk")
}
}
}
debug {
signingConfig signingConfigs.config
}
}
repositories {
mavenCentral()
mavenLocal()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'AndroidManifest.xml'
exclude 'META-INF/beans.xml'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
}
productFlavors {
}
dexOptions {
// preDexLibraries = false
jumboMode = true
javaMaxHeapSize "2g"
//doesn't seem to be supported with multidex
// incremental true
}
lintOptions{
disable 'MissingTranslation'
disable 'ExtraTranslation'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//multidex
compile 'com.android.support:multidex:1.0.0'
//support libs
compile 'com.android.support:support-v4:23+'
compile 'com.android.support:appcompat-v7:23+'
compile 'com.android.support:cardview-v7:23+'
compile 'com.android.support:design:23+'
//app invites
compile 'com.google.android.gms:play-services-appinvite:8+'
compile 'com.google.android.gms:play-services-analytics:8+'
//chromecast
compile 'com.google.android.gms:play-services-cast:8+'
compile 'com.android.support:mediarouter-v7:23+'
//plus button
compile 'com.google.android.gms:play-services-plus:8+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.github.navasmdc:MaterialDesign:1.+#aar'
//material lib needs it
compile 'com.nineoldandroids:library:2.4.+'
compile 'com.facebook.stetho:stetho:1+'
compile 'com.facebook.stetho:stetho-okhttp:1+'
//debugCompile 'com.squareup.leakcanary:leakcanary-android:1+'
debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1+'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1+'
compile 'com.makeramen:dragsortadapter:1.3+'
compile 'com.github.amlcurran.showcaseview:library:5.0.0'
}
EDIT: just had a new report but for a different version of the same class
Fatal Exception: java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:135)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at MyActivity.onCreate(MyActivity.java:353)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
at android.app.ActivityThread.access$600(ActivityThread.java:133)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4795)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(NativeStart.java)
EDIT: I've just gone over a lot of the reports, some are for AppCompatDelegateImplV23 and some are for AppCompatDelegateImplV14, some involved XPosed but most don't. The one thing that is common to all of them is that they are all for rooted phones.
First of all, we need to understand why java.lang.NoClassDefFoundError error occurs :
So the answer is that when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.
So there are some options by that you can remove this error:
1) Make preDexLibraries to true:
dexOptions {
preDexLibraries = true
jumboMode = true
javaMaxHeapSize "2g"
//doesn't seem to be supported with multi dex
// incremental true
}
2) There may be the problem with the incremental build system. So try to try to remove your build folder from your project and Rebuild the project OR Right click on your project -> "Open module settings" -> Dependencies tab -> check if Export is checked for your library
3) You need to do more than just provide MultiDex support.
multiDexEnabled = true in your defaultConfig block
Include compile 'com.android.support:multidex:1.0.0' in your dependencies
Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application
For more reference you can check the below link which has provided more advance understanding of multi dex.
https://developer.android.com/tools/building/multidex.html
4) Or at last you can add jar files of V7 into your project's libs folder and then add it your build System.
5) Also try removing the jar files as well as it still includes the com.android.support:support-v4:23+ as gradle has a repository where it downloads the jars delcared like compile 'compile 'com.android.support:appcompat-v7:23+'
Hope this can give you some clue about your error.
My guess is that the problem is due to the xposed framework. At the bottom of the stack trace, you can find that the zygote was started by the xposed framework.
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
This means that the user is using a custom Android rom with the xposed framework installed. The framework is usually used to modify the behavior of the Android framework (and any app of course) code by injecting new code at run-time.
You can check how it works at: https://github.com/rovo89/XposedBridge/tree/art/app/src/main/java/de/robv/android/xposed
Since the code behavior can be altered in various degrees depending on what mods are installed via the xposed framework, I cannot pinpoint the exact cause of your exception. However, if all the stack traces you have got start with the XposedBrigde.main(), then I can say that your problem is due to the exposed framework or the mods installed via the framework.
I have a project on GitHub that I work on both in the office at home. For about 2 months it was working fine on both machines. Then two weeks ago, it stopped running on my home PC, but still works fine on my work PC.
This is the error I get:
:app:shrinkDebugMultiDexComponents FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:shrinkDebugMultiDexComponents'.
java.io.IOException: Can't read [D:\dev\gitRepo\app\android\app\build\intermediates\multi-dex\debug\allclasses.jar] (Can't process class [__MACOSX/com/stripe/android/._BuildConfig.class] (Invalid magic number [51607] in class))
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
The stripe package that is giving me errors is a 3rd party library that you can find here. I list it as a dependency in my build.gradle file exactly as they say to.
compile 'com.stripe:stripe-android:+'
I have commented out all code pertaining the stripe and the app runs completely fine, so I do know it has something to do with how I am handling that package.
Unfortunately I don't remember exactly what I had done to make this stop working. I do think that the week before this happened I upgraded Android Studio, and spent a considerable amount of time messing with ProGuard configurations.
What I have tried:
Working on the master branch where no ProGuard changes have been made.
Uninstalling and Reinstalling Android Studio
Re-cloning the git repo
Installing API 17 (stripe for eclipse requires this. Not Studio but I gave it a shot).
Contacting stripe customer support but they had no clue.
This stack overflow post. However, there is no Mac computer that has touched the project nor have I personally zipped anything related to stripe.
From here, converted the magic number from Hex to ASCII. The result was Q` which I do not recognize.
I think it may have something to do with something I did for ProGuard, but I don't understand how. I'm on a completely different branch than any Proguard work, with a clean AndroidStudio install, with a clean repository clone, and the project still works fine when I'm in the office.
EDIT
I am running this on the debug BuildType. These are my 3 gradle files. The first is for the entire Project, the second is for the Application Module, and the third is for a local android library Module.
Project build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
allprojects {
repositories {
jcenter()
maven{ url 'http://download.crashlytics.com/maven' }
}
}
Android Application Module build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.app.android"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
buildConfigField 'Boolean', 'enableCrashlytics', 'true'
}
debug {
buildConfigField 'Boolean', 'enableCrashlytics', 'false'
}
adhoc {
debuggable true
signingConfig signingConfigs.debug
buildConfigField 'Boolean', 'enableCrashlytics', 'true'
}
}
packagingOptions {
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'
}
}
dependencies {
compile project(':localLibrary')
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
compile 'commons-io:commons-io:2.4'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.android.support:support-v4:22.0.1'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'
compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'io.card:android-sdk:5.0.1'
compile 'com.stripe:stripe-android:+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
}
Local Android Library Module build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.1.0'
compile 'com.google.code.gson:gson:2.2.2'
compile 'com.android.support:multidex:1.0.0'
compile group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
}
This problem is probably related to the version of Java that you are running. I had a similar problem and discovered that Java 8 was used for the build. When I changed to Java 7, this build problem was fixed.
In Android Studio go to
File -> Project Structure -> SDK Location
The JDK Location should be Java 1.7.x (Java 7)
Yeah verify both machines have the same Java version, and indeed the same version of Android Studio. The only other thing I can think of is that maybe Stripe is using the build tools bundled with AS to build your apk, and the ones you have installed by default differ slightly and are missing something - see this post I made on a similar problem I had.
After upgrading to Android Studio 1.2, I´m getting the following error when trying to sync my project
Error:Unable to load class
'com.android.build.gradle.internal.tasks.OutputFileTask'. Possible
causes for this unexpected error include:Gradle's dependency
cache may be corrupt (this sometimes occurs after a network connection
timeout.) Re-download dependencies and sync
project (requires network)The state of a Gradle build
process (daemon) may be corrupt. Stopping all Gradle daemons may solve
this problem. Stop Gradle build processes
(requires restart)In the case of corrupt Gradle
processes, you can also try closing the IDE and then killing all Java
processes.
This is my gradle file
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
repositories {
mavenCentral()
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
consumerProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
compile 'com.android.support:support-v4:22.1.0'
compile 'com.android.support:appcompat-v7:22.1.0'
}
task sourceJar(type: Jar) {
classifier "source"
}
publishing {
publications {
repositories.maven {
url repo
credentials {
username user
password passwd
}
}
maven(MavenPublication) {
artifacts {
groupId 'com.android'
artifactId 'artefact-1'
version '1'
artifact artifactPath
}
}
}
}
}
I think there could be yet another gradle api change which is causing the old stuff to not work anymore.
How can I solve the problem to build my project again?
Are you using dexguard? I had the issue with an old dexguard version. Since I updated to 6.1.19 there is no issue anymore. (Currently using AS 1.2.1 & Gradle 2.4 & 1.2.3)
Same problem here. After update Dexguard everything works fine.
Dexguard version 7.0.04
Gradle 2.4
Gradle Plugin 1.2.3
I recently installed the latest tools from google to my android project:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.xxx"
minSdkVersion 10
targetSdkVersion 21
versionCode 200
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
debug {
...
}
release {
...
}
}
buildTypes {
release {
...
}
debug {
...
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
// ---- Tests with robolectric
testCompile 'com.google.guava:guava:14.0.1'
testCompile 'junit:junit:4.+'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.mockito:mockito-all:2.0.2-beta'
// ---- Tests with Espresso
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
exclude module: 'hamcrest-core'
}
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile ('com.android.support.test:testing-support-lib:0.1') {
exclude module: 'hamcrest-core'
}
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
androidTestCompile('junit:junit-dep:4.10') {
exclude module: 'hamcrest-core'
}
}
Where before that I used to use com.github.jcandksolutions.gradle:android-unit-test:2.1.1 to run my robolectric tests in the jvm.
As google says for their new build tools: "New source folders recognized as unit tests: src/test/java, src/testDebug/java, src/testMyFlavor/java etc."
But as you can see below, my test folder isn't recognised as a source folder. It worked with com.github.jcandksolutions.gradle:android-unit-test:2.1.1, but no more with the new build tools:
What I'm missing here? Thank you
I found the solution which is to switch between Test Artifacts in the left corner of the IDE. On this screen only "Android Instrumentation Tests" is available because I downgraded my android tools but with tools 1.1.0+ you should see different types of test to get the IDE recognize them as source folders.
I had a similar problem the other day, except that I was able to run Robolectric tests ok in Android Studio, but didn't work from the command line. What worked for me is the following.
1) Run ./gradlew clean assembleDebug test (instead of just clean test)
(now, it would find source from main packages, but I would get this problem instead)
2) Added this to the build.gradle file: android.sourceSets.test.java.srcDirs += "build/generated/source/r/debug"
Just follow http://tools.android.com/tech-docs/unit-testing-support to enable the experimental unit test and switch test artifact to unit tests. then your unit test folder will be recognised.
when you have more issues perhaps this will help http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html
If it's any use I set up a boiler plate project allowing the use of Unit tests and Espresso tests by the use of switching build variants. You won't need the use of any third party plugins with this.
https://github.com/hitherejoe/Android-Boilerplate
UPDATE Oct 21, 2014:
The issue has been confirmed as fixed by using buildtools 21.
UPDATE SEPT 18, 2014:
The issue's status has been updated to FutureRelease.
UPDATE:
I have heard that this may not work with Dagger, and since Espresso uses Dagger, it might be causing some issues. A bug was submitted to the Gradle team.
Google recently updated their Gradle implementation to 0.10.0. One of the things they now offer is Jacoco support. To do this, they mention setting the following:
testCoverageEnabled = true
Into your build type. Now when I run my Espresso tests (using connectedCheck), I get an error right as I start to run the :connectedAndroidTest task that states:
Tests on HTC One - 4.2.2 - API 17 - 1080x1920 - 4.2.2 failed: Instrumentation run failed due to 'java.lang.VerifyError'
01:38:31 E/Device: Error during Sync: Remote object doesn't exist!
null
java.io.IOException: com.android.ddmlib.SyncException: Remote object doesn't exist!
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:114)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:158)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:42)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.ddmlib.SyncException: Remote object doesn't exist!
at com.android.ddmlib.SyncService.pullFile(SyncService.java:314)
at com.android.ddmlib.Device.pullFile(Device.java:849)
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:107)
... 8 more
:connectedAndroidTest FAILED
Here are the parts I have changed in the build.gradle file:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
...
}
...
}
android {
buildTypes {
debug {
testCoverageEnabled = true
...
}
....
}
...
}
Is there any other piece of build.gradle file that I need to update in order to get Jacoco working?
The error mentions that a "remote object" doesn't exist. Usually I attribute this to the emulator being out of sync and a restart would fix it. But I've tried that and it isn't worked either. Any ideas what the error is trying to tell me?
Try This One...
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.0'
}
}
repositories {
mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1" // Must Require
defaultConfig {
applicationId "com.packagename" <Change it>
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
lintOptions {
abortOnError false
}
buildTypes {
debug {
testCoverageEnabled true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
jacoco {
toolVersion = "0.7.1.201405082137"
}