Skip to content Skip to sidebar Skip to footer

Wrong Java Compiler When Including A Java Module As Dependency In Android Studio

I have a java module in my Android Studio project that is a dependency of an Android module. I am having problems on build with the following exception appearing. Error:Execution f

Solution 1:

So I have found the solution at this blog post.

The trick is in your Java Library module's build.gradle file you need to include the following.

apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6

This will then work.

Solution 2:

Seems things have changed on newer versions of Gradle / Android Studio, so the above solution about selecting source compatibility alone may not suffice. Particularly for complex projects which have a mix of modules which apply more than the simple android plugin ( I have seen following three plugins used on modules of same project: 'android' , 'java' and 'android-library')

You need to make sure that the following things are satisfied if source compatibility alone does not resolve your issue.

1) For you modules which apply plugin: 'android' select the source compatibility inside your build.gradle:

android {

      //... other sections.
compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

2) Select Project Byte code version from: File -> Other Settings -> Default settings.

project bytecode version

3) Explicitly select the JDK environment: File -> Project Structure -> SDK location and set it to the JDK 7 folder.

explicit JDK selection

--Update: with the new Android Studio 1.2.x they changed the location where you can select the Java byteCode version to the following: File->Other Settings->Default Settings->Build , Executions Enviromnent-> Compiler.

enter image description here

Post a Comment for "Wrong Java Compiler When Including A Java Module As Dependency In Android Studio"