testing-samples icon indicating copy to clipboard operation
testing-samples copied to clipboard

Problems running tests on multidex app on Kitkat emulator after updating gradle plugin to 3.1.1

Open fada21 opened this issue 6 years ago • 12 comments

Hello,

I've stumbled upon an issue after updating gradle plugin to 3.1.1.

I've tried to replicate on BasicSample (https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSample) project and got something very similar to my project's errors. Please take a look at 3 subsequent commits on the forked repo.

  1. https://github.com/fada21/android-testing/commit/13488879e62e07349f204fc969642c25fe5af089 Working state of my project based on BasicSample. With not too many changes on top of BasicSample tests on Kitkat and Oreo emulator pass. All working fine.

  2. https://github.com/fada21/android-testing/commit/8d314542c1823958a4dde7bac0a129bdcf9bcf02 After update to gradle build tool to 3.1.1 with few necessary changes tests on Kitkat emulator fail when they pass with no problems on Oreo. I think that is relevant console output part

> Task :app:compileDebugAndroidTestJavaWithJavac 
Note: /home/fada21/Projects/android/android-testing/ui/espresso/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/ChangeTextBehaviorTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Warning: The rule `-keep public class *extends java.lang.annotation.Annotation {
  *;
}` uses extends but actually matches implements.
Starting 0 tests on Nexus_4_API_19(AVD) - 4.4.2

com.android.builder.testing.ConnectedDevice > No tests found.[Nexus_4_API_19(AVD) - 4.4.2] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
  1. https://github.com/fada21/android-testing/commit/edc2613da4784002d04561578ca9c3de45ee616d After disabling multidex test pass on both emulators

My ci pipelines fail after update and I can't disable multidex. Any ideas? Should I report that to tools team?

Cheers, Lukasz

fada21 avatar Apr 11 '18 10:04 fada21

I am facing the same issue on devices using KitKat. Did someone find any solution to this issue?

MarisaLopes avatar May 11 '18 16:05 MarisaLopes

I have a similar issue.

When I try to execute tests using size attribute on devices with KitKat then I get a message No tests found. But when I execute tests using className everything is working correctly.

Tests work with the plugin in 3.0.1 version. From 3.1.0 tests are stopped working.

michalkierasinski avatar May 28 '18 09:05 michalkierasinski

did anyone fix this? I'm also facing the same issue

santanaluiz avatar May 31 '18 13:05 santanaluiz

I found a workaround to fix this problem. Instead of having my test related classes/packages inside: app/src/androidTest/com.company.app.**

I'm createad a subpackage called test: app/src/androidTest/com.company.app.**

Then, in my gradle file for I've added:

android {
   buildTypes {
        release {
            // ....
        }
        debug {
            // ....
            multiDexKeepProguard file('proguard-multidex-rules.pro')
        }
   }
}

Inside my file proguard-multidex-rules.pro, I've added the following rule:

-keep class com.company.app.test.** # <<--- this is the main trick
-keep class android.support.test.**
-keep class android.support.multidex.**
-keep class org.junit.**

Update:

instead of moving your packages, just add the following rule in the proguard-multidex-rules.pro file:

-keep @org.junit.runner.RunWith public class *
# ...

santanaluiz avatar Jun 06 '18 10:06 santanaluiz

I've updated the solution above 👆 check it out

santanaluiz avatar Jun 06 '18 12:06 santanaluiz

Did anyone find/file a bug report at https://issuetracker.google.com?

michael-mohemian avatar Jul 17 '18 10:07 michael-mohemian

Hi @santanaluiz,

I tried your updated solution but it didn't work.

I just added "proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'" to my build type "uitesting" on gradle file, like that:

buildTypes { uitesting { initWith debug minifyEnabled false shrinkResources false debuggable true testCoverageEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

Then, just added the rule to the proguard file: -keep @org.junit.runner.RunWith public class *

Do you have any idea why that doesn't work?

Thanks

MarisaLopes avatar Aug 30 '18 15:08 MarisaLopes

@MarisaLopes, note that you should not add to proguardFiles to your buildVariant but with multiDexKeepProguard

Then you add that line to your rules files. Something like:

buildTypes {
    uitesting {
        initWith debug
        minifyEnabled false
        shrinkResources false
        debuggable true
        testCoverageEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        multiDexKeepProguard file('proguard-multidex-rules.pro') // <--- THIS IS THE TRICK
    }
}

Please, let me know if you manage to fix it

santanaluiz avatar Aug 30 '18 15:08 santanaluiz

@santanaluiz Not working for me.

hrishikesh-kadam avatar Mar 08 '19 10:03 hrishikesh-kadam

The solution is described well here: https://spin.atomicobject.com/2018/07/16/support-kitkat-multidex/ For me, it works.

warcello avatar Mar 08 '19 12:03 warcello

@michael-mohemian Yes, I've found one, but I doubt that Google will fix this issue. See https://issuetracker.google.com/issues/132749662 for details and feel free to star the issue to make it more visible.

eschoenawa avatar Aug 26 '19 08:08 eschoenawa

I've opened a feature request to make Android Studio automatically apply the fix for this problem, so noone has to search for this solution online. Feel free to give it a star here: https://issuetracker.google.com/issues/140124440

eschoenawa avatar Sep 05 '19 22:09 eschoenawa