4

On my current project our test APK has grown over the 64k method limit. We have multidex enabled, so running tests on a device with API > 19 , gives no problems, but on API 19 the runner can't find classes in the second dex file.

I have tried reducing the androidTestCompile dependencies but the biggest culprit is espresso, which I need.

Are there any work arounds for the dex limit on the test APK running on platforms that don't natively support multidex ?

RominaV
  • 3,335
  • 1
  • 29
  • 59
James Muranga
  • 808
  • 9
  • 13
  • Possible duplicate of [Android support multidex library implementation](http://stackoverflow.com/questions/26925264/android-support-multidex-library-implementation) – Kristopher Micinski Aug 26 '16 at 21:11

2 Answers2

1

Prior to Android L, Dalvik runtime is used for executing app code. To get around it, you can use the multidex support library.

Read more here.

RominaV
  • 3,335
  • 1
  • 29
  • 59
  • 1
    I have multidex enabled and it works for the main apk I can run the application fine even on Dalvik ,but not the test apk can't run the androidTests – James Muranga Aug 26 '16 at 16:22
1

Create a Java class, which would be your custom testInstrumentationRunner.

Put 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 your app's build.gradle

Replace existing line:

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

with yours custom class:

testInstrumentationRunner "com.mypackagename.test.MultiDexAndroidJUnitRunner"

Hope it will work

piotrek1543
  • 19,130
  • 7
  • 81
  • 94