Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 442
tm1701 Avatar asked Feb 02 '26 03:02

tm1701


1 Answers

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

like image 164
tm1701 Avatar answered Feb 03 '26 18:02

tm1701