Android Espresso multidex not working

We have been using multidex in our application for a long time, but recently with the last update it fails in the android 19 API, for example an emulator with api 16 This is standard java.lang.NoClassDefFoundError.

If I define multidexKeepProguard for the missing class, for example. java.lang.NoClassDefFoundError. rx.plugins.RxJavaHooks exception

-keep class rx.plugins.**{*;} 

then it just fails elsewhere for the same reason NoClassDefFound

Here are the settings for the runner, application, and manifest:

https://gist.github.com/originx/1890599b57b0ee3e14a85a4732301cd9

Logcat:

https://gist.github.com/originx/887f80d405334f1903b3024eb5cd1024

Setting up the development environment:

Android Studio 2.2.2 Build # AI-145.3360264, built on October 18, 2016 JRE: 1.8.0_112-release-b05 x86_64 JVM: 64-bit OpenJDK virtual machine from JetBrains sro

Compilation options

 compile 'com.android.support:multidex:1.0.1' 

assembly tool information:

  classpath 'com.android.tools.build:gradle:2.2.2' compileSdkVersion 25 buildToolsVersion '25' defaultConfig { applicationId "app.packagename.com" minSdkVersion 16 targetSdkVersion 25 testInstrumentationRunner "de.payback.app.CustomAndroidJUnitRunner" multiDexEnabled true } dexOptions { jumboMode true preDexLibraries false javaMaxHeapSize "4g" maxProcessCount = 8 } debug { applicationIdSuffix '.debug' versionNameSuffix '-debug' signingConfig signingConfigs.debug minifyEnabled false shrinkResources debugShrinkResourcesEnabled proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguardRules/proguard-rules.pro', '../proguardRules/proguard-debug-rules.pro' // multiDexKeepProguard file('../proguardRules/multidex-proguard.pro') testProguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguardRules/proguard-rules.pro', '../proguardRules/proguard-debug-test-rules.pro' testCoverageEnabled false } release { minifyEnabled true shrinkResources true testProguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguardRules/proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguardRules/proguard-rules.pro' // multiDexKeepProguard file('../proguardRules/multidex-proguard.pro') } 

I tried everything: from the MultiDexApplication extension to the custom MultiDex.install (context) to using MultiDexRunner

same results always

if you use the multidexkeepproguard file for classes that are not usually found, they are in the main dex file, but of course something else is missing, which indicates that multidex was not installed and initialized correctly

Google bug report:

https://code.google.com/p/android/issues/detail?id=228449

repo to reproduce the problem can be found here:

https://github.com/originx/multidex/tree/master

To start, disable instant start

To reproduce the problem with multiple addresses, run the following command

./gradlew clean connectedPayGermanyCompatDebugAndroidTest

runs on any device or API emulator 16. Tests on the GTI8190 4.1.2 failed. Instrumental launch failed due to java.lang.NoClassDefFoundError

Any suggestions on how to get around this until I get more information from the Google team?

+6
source share
1 answer

Google dev explanation:

The problem is that the rx.plugins.RxJavaHooks class that references the CustomJunitRunner.onCreate () method is located in the secondary dex file of the main application and that you access before the class loaders get fully fixed .

When the main application and the test code have a common dependency, we will remove it from the test dependencies (as we expect, it will be available in the main application). However, with obsolete multidexes, this causes problems.

There are currently 2 workarounds:

Option 1 Make sure rx.plugins.RxJavaHooks is in the main by creating the multidexKeepProguard.pro file and adding the "-keep class" rx.plugins. ** "

Option 2 Remove the links to RxJavaHooks from onCreate () and move them toStart () (not sure if this is done when you want at least): @Override public void onStart () {super.onStart (); // connect the schedulers to rxjava, so the inaction espresso can extract it properly RxJavaHooks.setOnComputScheduler (current → Schedulers.from (AsyncTask.THREAD_POOL_EXECUTOR)); RxJavaHooks.setOnIOScheduler (current → Schedulers.from (AsyncTask.THREAD_POOL_EXECUTOR)); RxJavaHooks.setOnNewThreadScheduler (current → Schedulers.from (AsyncTask.THREAD_POOL_EXECUTOR)); }

Decision

Bypass

Such a workaround is to either use the multidexKeepProguard.pro file and specify this file in your debug configuration:

  debug { applicationIdSuffix '.debug' multiDexKeepProguard file('../proguardRules/multidex-proguard.pro') } 

The multidex proguard file should contain classes that were not found in the main dex file, in my case it was RxJavaPlugin, so the myideexproguard file contains:

 -keep class rx.** { *; } 
+1
source

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


All Articles