5

I'm trying to play with Java11 APIs in android application and failed to make it compile.

Steps to fail:

  1. Using current version of Android Studio 4.1.2 - generated dummy project "Basic Activity"
  2. Build & Launch - everything OK so far
  3. Open app/build.gradle and set sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11
  4. In Project Structure > SDK Location > JDK Location - select path to JDK 11
  5. Build ... and it fails with following error
FirstFragment.java:3: error: package android.os does not exist

So the question is - what am I doing wrong? What is missing to build the project with sourceCompatibility JavaVersion.VERSION_11?

Xtra Coder
  • 3,389
  • 4
  • 40
  • 59

1 Answers1

2

Just switch to the latest version Android Studio Arctic Fox Canary 9 (2020.3.1.9) and AGP 7.0

sdex
  • 3,169
  • 15
  • 28
  • 3
    And it appears that major point is `build.gradle`:`classpath "com.android.tools.build:gradle:7.0.0-alpha09"` - and this newer version is only supported by Canary version of Android Studio ... – Xtra Coder Mar 09 '21 at 23:58
  • may you have some comments for this question? https://stackoverflow.com/questions/66556819/android-corelibrarydesugaring-which-java-11-apis-can-i-expect-to-work – Xtra Coder Mar 10 '21 at 00:47