How to install the original Java library in an Android Studio project

I have an Android project, broken into a pure Java library and an Android application. I am using Gradle Retrolambda , so I can write Java 8 code.

Android Studio 1.3 correctly recognizes android.compileOptions.sourceCompatibility in the Android module that I installed in JavaVersion.VERSION_1_8 .

Now I would like Android Studio to realize that the Java module is also Java 8. I tried (in the root of the Gradle script, after apply plugin 'java' :

  • sourceCompatibility = 1.8 But does not work. Gradle compiles correctly, but Android Studio shows a warning ("Destination is not used") and assumes Java 6.

  • sourceCompatibility 1.8 does not compile.

How can I get Android Studio to recognize this without resorting to the โ€œInstall Source Versionโ€ quick installation? Or is it not implemented at the moment?

EDIT

To clarify, the entire project is compiled with ./gradlew assembleDebug . The problem is with the highlighting of the source code for Android Studio.

My Java build.gradle module is as follows:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'me.tatarka:gradle-retrolambda:3.2.0' } } repositories { jcenter() mavenCentral() } apply plugin: 'java' apply plugin: 'me.tatarka.retrolambda' sourceCompatibility = JavaVersion.VERSION_1_8 dependencies { compile 'io.reactivex:rxjava:1.0.12' compile 'io.reactivex:rxjava-string:1.0.0' compile 'joda-time:joda-time:2.8.1' testCompile 'junit:junit:4.12' } retrolambda { jdk System.getenv("JAVA_HOME") defaultMethods true incremental false } 

And here is what Android Studio offers me: Android Studio highlight error

+5
source share
2 answers

It appeared (thanks to @Anand Singh) that Android Studio is not coping with this, so you need to apply a quick fix.

0
source

in your java build.gradle module write code like this:

  buildscript { repositories { mavenLocal() mavenCentral() } dependencies { classpath "me.tatarka:gradle-retrolambda:3.2.0" } } apply plugin: 'java' apply plugin: 'me.tatarka.retrolambda' repositories { mavenCentral() } dependencies { } retrolambda { jdk System.getenv("JAVA8_HOME") defaultMethods true incremental false } 
0
source

All Articles