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