Language Level Java 8 (Retrolambda) on AndroidStudio 4+?
Solution 1
It is removed on new project, but it is available in the properties after the project is created. Note that I haven't actually compiled with any new Java 8 features yet, so let's hope that works.
Right click on your project, go to Open Module Settings. I think there's a bug somewhere, as once I navigate away from those language settings tab, I can never get back to it.
To work around that, you can edit MyProject/.idea/misc.xml and look for the languageLevel attribute.
To enable Project settings once you navigate away, edit MyProject/.idea/workspace.xml and search for project.structure.last.edited. Set the value to "Project".
Solution 2
I've found that you can set the "language level" to Java 8 in Android Studio by modifying the build.gradle to include the following:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Related videos on Youtube
![spierce7](https://i.stack.imgur.com/GDzVT.jpg?s=256&g=1)
spierce7
Updated on September 15, 2022Comments
-
spierce7 almost 2 years
So, someone backported Lambdas for Java 8 back to Java 6, and 7. Apparently it also works for Android. The project is called Retrolambda. I wanted to play around with this on AndroidStudio, but it seems in recent version they have removed the ability to set Java 8 as the Language Level (so I don't get compile errors while using Lambdas). Does anyone know a way around this? I imagine it'd have something to do with the fact that AndroidStudio is a modified IntelliJ. Any help would be appreciated.
-
spierce7 over 10 yearsI can't find the setting in the properties after the project is created. It looks like they removed it there too. Please give detailed instructions.
-
spierce7 over 10 yearsThat actually is what I was hoping for. Thanks!
-
spierce7 over 10 yearsUpdate: This option has just been added back into the latest build of Android Studio.
-
HolySamosa about 10 yearsFYI: I'm seeing the same bug (?) with the General settings disappearing from the Module Settings screen.
-
spierce7 about 10 years@HolySamosa you could try to just switch to IntelliJ. It's almost the exact same as Android Studio due to it being the base for Android Studio, and you can better control this type of stuff.
-
Paul Verest over 9 yearsvery similar to java 7 tools.android.com/tech-docs/new-build-system/…
-
IgorGanapolsky over 9 years@joe My .idea/misc.xml already has languageLevel="JDK_1_8". Yet I am experiencing this error.
-
Papipo about 9 yearsWhat happens if I have a module which is not an android project? I can't use this solution there.
-
Brent Aureli over 8 yearsthis worked, I can compile and run but android studio still flags the code as error(red underlined ect..) in the editor. Any suggestions?
-
azwar_akbar about 8 yearsGreat solution. Thanks.
-
Dino Tw over 7 yearsAndroid does not support all Java 8 language features, developer.android.com/guide/platform/j8-jack.html