I'm working an android project where the model is written in java alone and a dependency for the rest of the project (view, controller), written in "android-java".
I have recently switched from android studio 1.3 to 2.1 and begun to use java 8 in the model.
It compiles fine insofar as rebuilding the project throws no errors.
(I occasionally get "Lambda expressions are not supported at this language level", but this can be resolved by clicking on the red light bulb which offers to set the language level to 8)
Now, when I run the app, I get ~40 errors that look like this one(with another class file each):
...while parsing /foo/ba/xy.class
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
This question is very similar, however I can specify that the source of my errors contains no android specific code (and have thus no android-block, in my gradle file).
An obvious choice is now to add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
This beggs the first question: Why sourceCompatibility = '1.7'
? I want to use java 8!
But regardless, I don't know how to add these 2 lines the the build.gradle file. The file in question looks like this:
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.7'
testCompile 'org.apache.directory.studio:org.apache.commons.io:2.4'
testCompile 'org.kie.modules:org-apache-commons-lang3:6.3.0.CR1'
}
Attempt 1: add both lines directly in line 2
get "Lambda expressions are not supported at this language level" again, click red bulb again, 1.7
is changed to 1.8
in both lines.
rebuild succeeds, try running.
get 107 errors as above suggesting I set both to 1.7
.
Set targetCompatibility
to 1.7
and sourceCompatibility
to 1.8
because it seems logical:
get
Error:Execution failed for task ':xxxxmodel:compileJava'.
> Compilation failed; see the compiler error output for details.
Gradle window says
javacTask: target release 1.7 conflicts with default source release 1.8
I can't find the compiler error output however.
Attempt 2: add
apply plugin: 'com.android.application'
android {
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
}
Get Error:Cause: buildToolsVersion is not specified.