Multidexed apk test will not work on api-19

In my current project, our test APK has grown above the limit of the 64k method. We have multidex support, so running tests on a device with API> 19 does not cause problems, but on API 19, the runner cannot find classes in the second dex file.

I tried to reduce the dependencies of androidTestCompile, but the biggest culprit is the espresso I need.

Is there any work around the dex limit on a test APK running on platforms that don't support multidex?

+4
source share
2 answers

Prior to launching Android L, Dalvik runtime is used to run the application code. To get around this, you can use the multidex support library .

More details here .

+1
source

Create a class Javathat will be your custom testInstrumentationRunner.

Paste this code into it:

public class MultiDexAndroidJUnitRunner extends AndroidJUnitRunner {
    @Override
    public void onCreate(Bundle arguments) {
        //To make it work on MultiDex environment.
        //https://plus.google.com/+OleksandrKucherenko/posts/i7qZdVEy3Ue
        MultiDex.install(getTargetContext());

        super.onCreate(arguments);
    }
}

Open app build.gradle

Replace existing line:

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

with your special class:

testInstrumentationRunner "com.mypackagename.test.MultiDexAndroidJUnitRunner"

Hope it works

0
source

Source: https://habr.com/ru/post/1652619/


All Articles