GeekHades
GeekHades

Reputation: 3016

Android studio Failed to run command: java -Xmx1024M -cp

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?

Upvotes: 3

Views: 786

Answers (2)

GeekHades
GeekHades

Reputation: 3016

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!

Upvotes: 0

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

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); 
   } 
}

Upvotes: 3

Related Questions