I know that there was already such a question, but its author asked a question without details and did not receive an answer.

I created a project with a library, next I created an application module for checking the library. I want to test this whole thing with the help of Robolectric. Added it depending. After that, the project began to compile for a long time. If you remove the Robolectric, everything is fine.

Adding multidex to defaultConfig and connecting the support.multidex library does not help.

Here is the application's build.gradle file:

apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "imangazaliev.quickmenusample" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile project(':library') compile 'com.android.support:appcompat-v7:23.1.0' compile 'org.robolectric:robolectric:3.0' } 

And this error pops up:

 Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug] :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :library:compileLint :library:copyReleaseLint UP-TO-DATE :library:preBuild UP-TO-DATE :library:preReleaseBuild UP-TO-DATE :library:checkReleaseManifest :library:preDebugAndroidTestBuild UP-TO-DATE :library:preDebugBuild UP-TO-DATE :library:preDebugUnitTestBuild UP-TO-DATE :library:preReleaseUnitTestBuild UP-TO-DATE :library:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE :library:prepareComAndroidSupportSupportV42310Library UP-TO-DATE :library:prepareReleaseDependencies :library:compileReleaseAidl UP-TO-DATE :library:compileReleaseRenderscript UP-TO-DATE :library:generateReleaseBuildConfig UP-TO-DATE :library:generateReleaseAssets UP-TO-DATE :library:mergeReleaseAssets UP-TO-DATE :library:generateReleaseResValues UP-TO-DATE :library:generateReleaseResources UP-TO-DATE :library:mergeReleaseResources UP-TO-DATE :library:processReleaseManifest UP-TO-DATE :library:processReleaseResources UP-TO-DATE :library:generateReleaseSources UP-TO-DATE :library:processReleaseJavaRes UP-TO-DATE :library:compileReleaseJavaWithJavac UP-TO-DATE :library:extractReleaseAnnotations UP-TO-DATE :library:mergeReleaseProguardFiles UP-TO-DATE :library:packageReleaseJar UP-TO-DATE :library:compileReleaseNdk UP-TO-DATE :library:packageReleaseJniLibs UP-TO-DATE :library:packageReleaseLocalJar UP-TO-DATE :library:packageReleaseRenderscript UP-TO-DATE :library:packageReleaseResources UP-TO-DATE :library:bundleRelease UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42310Library UP-TO-DATE :app:prepareQuickMenuLibraryLibraryUnspecifiedLibrary UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:preDebugAndroidTestBuild UP-TO-DATE :app:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl UP-TO-DATE :app:processDebugAndroidTestManifest UP-TO-DATE :app:compileDebugAndroidTestRenderscript UP-TO-DATE :app:generateDebugAndroidTestBuildConfig UP-TO-DATE :app:generateDebugAndroidTestAssets UP-TO-DATE :app:mergeDebugAndroidTestAssets UP-TO-DATE :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources UP-TO-DATE :app:mergeDebugAndroidTestResources UP-TO-DATE :app:processDebugAndroidTestResources UP-TO-DATE :app:generateDebugAndroidTestSources UP-TO-DATE :app:processDebugJavaRes UP-TO-DATE :app:compileDebugJavaWithJavac UP-TO-DATE :app:compileDebugNdk UP-TO-DATE :app:compileDebugSources UP-TO-DATE :app:preDexDebug UP-TO-DATE :app:dexDebug UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502) at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277) at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334) at com.android.dx.command.dexer.Main.run(Main.java:277) at com.android.dx.command.dexer.Main.main(Main.java:245) at com.android.dx.command.Main.main(Main.java:106) Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 2 Information:BUILD FAILED Information:Total time: 18.905 secs Information:1 error Information:0 warnings Information:See complete output in console 

1 answer 1

This error seems to be caused by the fact that with this library you have exceeded the limit of the number of methods in the project - 65536 .

You can decide:

  1. Using google solution for this problem Building Apps with Over 65K Methods . In short : add this in the gradle :

     android { defaultConfig { ... // Enabling multidex support. multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.1' } 

Add an attribute to the Application Manifest -a tag:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application ... android:name="android.support.multidex.MultiDexApplication"> ... </application> </manifest> 

And, if you use your Application class, you need to expand it now from MultiDexApplication

  1. As mentioned in the @temq comments, specify testCompile instead of compile for the libraries needed for unit tests.
  2. Delete all other libraries to enter the limit)
  • Very cool! It helped me! Today, just hours 6 sat reading the documentation ... From where do you know this? How do you find the answers? And I still have a question, I added only what you recommend for gradle at the very beginning of your answer I tried to start and it all worked)) I didn’t believe at first)) So the question is whether you need to add lines to the manifest and everything else if does it work for me? - Aleksey Timoshchenko