3

Today I meet this question, when i use android run the program. Gradle will take mistake like this:

Error:Execution failed for task ':app:createAnzhiDebugMainDexClassList'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: java -Xmx1024M -cp /Users/Hades/Library/Android/sdk/build-tools/21.1.2/lib/dx.jar com.android.multidex.ClassReferenceListBuilder /Users/Hades/Work/Code/RentAgent/RentAgent/app/build/intermediates/multi-dex/anzhi/debug/componentClasses.jar /Users/Hades/Work/Code/RentAgent/RentAgent/app/build/intermediates/multi-dex/anzhi/debug/allclasses.jar Error Code: 1 Output: Unable to locate a Java Runtime to invoke.

Could you help me?

GeekHades
  • 3,028
  • 3
  • 19
  • 15

2 Answers2

3

Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:

  1. Change your Gradle build configuration to enable multidex
  2. Modify your manifest to reference the MultiDexApplication class

Modify your app Gradle build file configuration to include the support library and enable multidex output .

    android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

Read Official Document about MultiDex

If your Application class is extending some other class and you don’t want to or can’t change it, override attachBaseContext() as shown below:

public class MyApplication extends MultiDexApplication { 
   @Override 
   protected void attachBaseContext(Context base) { 
      super.attachBaseContext(base); 
      MultiDex.install(this); 
   } 
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    Thank a lot, This is very useful. But my question is because my computer RAM is not enough for android Dalvik to use gradle build! So i restart my computer. It is resolve ! Thank you ! – GeekHades Nov 12 '15 at 08:24
  • @GeekHades You can read my answer here http://stackoverflow.com/questions/33313101/dexindexoverflowexception-only-when-running-tests?answertab=active#tab-top – IntelliJ Amiya Dec 11 '15 at 08:10
0

The best way to resolve this question:

in the android studio terminal: input this command line

if you use Mac

./gradlew --stop

if you use windows, you can try

 gradlew --stop

It works for me!

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
GeekHades
  • 3,028
  • 3
  • 19
  • 15