Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

I am developing an Android App in Android Studio. Not quite sure what went wrong. I was successfully building a few days ago. Any help would be great.

Here is the error:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.  * What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.

Here is my build.gradle

apply plugin: 'com.android.application'  android { compileSdkVersion 23 buildToolsVersion "21.1.2"  defaultConfig {     multiDexEnabled true     applicationId "com.tubbs.citychurchob"     minSdkVersion 14     targetSdkVersion 23     versionCode 1     versionName "1.0" } buildTypes {     release {         minifyEnabled false       proguardFiles getDefaultProguardFile('proguard-android.txt'),        'proguard-rules.pro'     } } }  dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: 'Parse-*.jar') compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:cardview-v7:23.1.0' compile 'com.parse.bolts:bolts-android:1+' compile 'com.android.support:recyclerview-v7:23.1.0' }

回答1:

Try to upgrade your buildToolsVersion to "23.0.1",like this:

compileSdkVersion 23 buildToolsVersion "23.0.1"

If you didn't install the buildTools for this version,please download it with SDKManager as hint.



回答2:

This is because your $JAVA_HOME is not set. If you are using a Mac:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home" in .bash_profile



回答3:

Set JDK location in project settings



回答4:

Update (06/05/2017)

I wanted to use Realm for Android and that required Retrolambda. Problem is Retrolambda conflicts with Jack.

So I removed my Jack options config from my gradle shown in original answer below and made the following changes:

// --------------------------------------------- // Project build.gradle file // --------------------------------------------- buildscript {     repositories {         jcenter()     }     dependencies {         classpath 'com.android.tools.build:gradle:2.3.1'         classpath 'me.tatarka:gradle-retrolambda:3.6.1'         classpath "io.realm:realm-gradle-plugin:3.1.4"          // NOTE: Do not place your application dependencies here; they belong         // in the individual module build.gradle files     } }

and

// --------------------------------------------- // Module build.gradle file // --------------------------------------------- apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' apply plugin: 'realm-android'  android {     compileSdkVersion 25     buildToolsVersion "25.0.2"     ...

Tools.jar

If you made those changes above and you still get the following error:

Execution failed for task ':app:compileDebugJavaWithJavac'. com.sun.tools.javac.util.Context.put(Ljava/lang/Class;Ljava/lang/Object;)V

Try removing the following file:

/Library/Java/Extensions/tools.jar 

Then:

  1. Quit emulator
  2. Quit Android Studio
  3. Reopen Android Studio
  4. Build > Clean Project
  5. Run/debug your app onto your device/emulator again

All the changes fixed it for me.

Note:

I am not sure what tools.jar does or whether it's important. Like other uses in this Stackoverflow question:

Can't build Java project on OSX yosemite

We were unfortunate enough to have to use AUSKey (some ancient dinosaur Java authentication key system used by Australian Government to authenticate our computer before we can log into Australian business portal website).

My speculation is tools.jar might have been a JAR file for/by AUSKey.

If you're worried, instead of deleting this file, you can make a backup of the whole folder and save it somewhere just in case you can't login to Australian Business Portal again.

Hope that helps :D

Original Answer

I came across this problem today (27/06/2016).

I downloaded Android Studio 2.2 and updated JDK to 1.8.

In addition to the above answers of pointing to the correct JDK path, I had to additionally specify the JDK version in my build.gradle(Module: app) file:

compileOptions {     sourceCompatibility JavaVersion.VERSION_1_8     targetCompatibility JavaVersion.VERSION_1_8 }

The resulting file looks like this:

apply plugin: 'com.android.application'  android {     compileSdkVersion 24     buildToolsVersion "24.0.2"     defaultConfig {         applicationId "com.mycompany.appname"         minSdkVersion 17         targetSdkVersion 24         versionCode 1         versionName "1.0"         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"          jackOptions {             enabled true         }     }     buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }     }     compileOptions {         sourceCompatibility JavaVersion.VERSION_1_8         targetCompatibility JavaVersion.VERSION_1_8     } }  dependencies {     compile fileTree(dir: 'libs', include: [        
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!