tm1701
tm1701

Reputation: 7581

Android with sourceCompatibility = JavaVersion.VERSION_11 gives error error: "package android.app does not exist"

When using the JDK 11 target, then I get this error:

error: package android.app does not exist

I saw a solution to upgrade to the 'Canary' AS version. I prefer to use the beta or stable Android Studio version. I have updated it regularly. Not planning a major change for just an upgrade.

So, this works well: even with an Android Studio "Project settings" and "JDK" with "JDK 11".

When the build.gradle has these compile options, everything works fine.

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

This gives the mentioned errors:

compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

My build.grade project file is:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'org.ajoberstar:grgit:3.3'
    }
}

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        google()
    }
}

Parts of my build.grade module file is:

apply plugin: 'com.android.application'
repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
    google()
}

How can I build normally using the (Oracle) JDK 11 compiler?

Upvotes: 3

Views: 13342

Answers (1)

tm1701
tm1701

Reputation: 7581

Just receive the Android Studio / Gradle 7 upgrade.

Everything is working right now!

  1. Use this as your compiler options:
compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}
  1. In the settings you see that the JDK 11 is already chosen. If not chosen automatically, you will be allowed to chose that JDK 11 version.

enter image description here

Upvotes: 8

Related Questions