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
testCompileinstead ofcompilefor libraries that are needed forunittests, here you can see how to create a test - en. stackoverflow.com/a/478829/181119 - temq