An exception occurred applying plugin request [id: 'com.android.application'] while integration Jetpack Compose

23,723

Solution 1

Android Gradle Plugin 7 requires Java 11.

Go to File > Project Structure and change JDK location to Embedded JDK.

Solution 2

For Android Studio Artic Fox (2020.3.1), you can find the JDK settings here:

Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JDK

Then change the setting to "Embedded JDK"

Solution 3

For Android Studio Artic Fox (2020.3.1) Android Gradle Plugin 7 requires Java 11. use short key Ctr+Alt+Shift+S or Go to File > Project Structure and change JDK location to Embedded JDK. Same Answer @Mariusz Here is Screenshot

Solution 4

Check the following picture to re-direct the JDK source:

Step 1.
enter image description here

Step 2.
enter image description here

Step 3.
enter image description here

And you should be good to go.

Solution 5

I have issue with build cache and the error:

An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
   > The option 'android.enableBuildCache' is deprecated.
     The current default is 'false'.
     It was removed in version 7.0 of the Android Gradle plugin.

Removing org.gradle.caching=true from root gradle properties file solved the issue.

Share:
23,723

Related videos on Youtube

Devraj
Author by

Devraj

I am cool, weird, Techie, Fun loving, Gamer, Android developer... :-)

Updated on July 09, 2022

Comments

  • Devraj
    Devraj almost 2 years

    I am trying to implement JetPack Compose using Canary 8 but getting this error every time I try to sync gradle

    An exception occurred applying plugin request [id: 'com.android.application']

    My app\build.gradle file is below

        plugins {
        id 'com.android.application'
        id 'kotlin-android'
    }
    
    android {
        compileSdkVersion 30
        buildToolsVersion "30.0.0"
    
        defaultConfig {
            applicationId "com.example.myapplication"
            minSdkVersion 21
            targetSdkVersion 30
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        kotlinOptions {
            jvmTarget = '11'
            useIR = true
        }
        buildFeatures {
            compose true
        }
        composeOptions {
            kotlinCompilerExtensionVersion compose_version
            kotlinCompilerVersion '1.4.30'
        }
    }
    dependencies {
        implementation 'androidx.core:core-ktx:1.3.2'
        implementation 'androidx.appcompat:appcompat:1.2.0'
        implementation 'com.google.android.material:material:1.2.1'
        implementation "androidx.compose.ui:ui:$compose_version"
        implementation "androidx.compose.material:material:$compose_version"
        implementation "androidx.compose.ui:ui-tooling:$compose_version"
        implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha06'
        implementation 'androidx.activity:activity-compose:1.3.0-alpha02'
        testImplementation 'junit:junit:4.+'
        androidTestImplementation 'androidx.test.ext:junit:1.1.2'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    }
    

    My build.gradle file is below

    buildscript {
        ext {
            compose_version = '1.0.0-beta01'
        }
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.0.0-alpha08'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    and this is my gradle-wrapper.properties

    distributionBase=GRADLE_USER_HOME
    distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
    distributionPath=wrapper/dists
    zipStorePath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    
    • Gaëtan
      Gaëtan over 3 years
      Do you have the exception as well?
    • Devraj
      Devraj over 3 years
      @Gaëtan yes, org.gradle.api.plugins.InvalidPluginException:
    • Yaqoob Bhatti
      Yaqoob Bhatti almost 3 years
      use short key Ctr+Alt+Shift+S or Go to File > Project Structure and change JDK location to Embedded JDK
  • Devraj
    Devraj over 3 years
    I dont understand why android behave so mistereously as same configuration was working fine 2 days back. Also when I am trying to update Gradle from 6.8.2 to 7.x.x , it starts giving another exception
  • MSDarwish
    MSDarwish over 3 years
    Could you share the new exception with us?
  • Mariusz
    Mariusz over 3 years
    you already use AGP 7 com.android.tools.build:gradle:7.0.0-alpha08 Android Gradle Plugin != Gradle, I bet AGP in alpha08 got some bug or some other dependencies are bugged or not upteded
  • Mariusz
    Mariusz over 3 years
    update: switched to gradle 7 m 2 distributionUrl=https\://services.gradle.org/distributions/g‌​radle-7.0-milestone-‌​2-bin.zip still giving same exception An exception occurred applying plugin request [id: 'com.android.application']
  • Devraj
    Devraj over 3 years
    @Mariusz, Hurraah!!! fixed this time. but it is very stange that I have developed a demo app with distributionUrl=https\://services.gradle.org/distributions/g‌​radle-6.8.2-bin-zip and java8. but suddenly it stopped working. Thank you so much.. Upgrading java 8 to java 11 solved my problem.
  • Mariusz
    Mariusz over 3 years
    @Devraj most probably you used stable Android Studio (with java8) and AS Preview uses AGP 7 that require J11
  • Devraj
    Devraj over 3 years
    @Mariusz but Android Jetpack compose does not work on Stable Android studio, It requires Canary. correct me if I am wrong.
  • a55
    a55 almost 3 years
    where is Project Structure ? i can not find it.
  • aldok
    aldok almost 3 years
    @a55 As the answer said, "File -> Project Structure...". Or, the shortcut: "CMD+;".
  • Yaqoob Bhatti
    Yaqoob Bhatti almost 3 years
    use short key Ctr+Alt+Shift+S
  • Vikash Parajuli
    Vikash Parajuli over 2 years
    What could be the impact if I remove org.gradle.caching=true from the existing project
  • 0xAliHn
    0xAliHn over 2 years
    We don't need it anymore. You can remove this
  • Farid
    Farid over 2 years
    Still the same error
  • Farid
    Farid over 2 years
    Was already 11 so nope, not a solution
  • Farid
    Farid over 2 years
    Nothing, still the same error