We recommend using a newer Android Gradle plugin to use compileSdkPreview = "Tiramisu"

2.1k views Asked by At

I am using Android Studio Dolphin | 2021.3.1 Canary 8 for JEtpack Compose,

OS: Windows 10 (latest version)

My @Preview() stop working after I update my Android Studio:


@Preview(showBackground = true)
@Composable
fun DefaultPreview()
{
    Template_Compose_11Theme {
        Greeting("Android")
    }
}

and I got this error:

java.lang.ClassNotFoundException: android.view.OnBackInvokedCallback
    at com.android.tools.idea.rendering.classloading.loaders.DelegatingClassLoader.findClass(DelegatingClassLoader.kt:81)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at com.android.tools.idea.rendering.classloading.loaders.DelegatingClassLoader.loadClass(DelegatingClassLoader.kt:65)
    at androidx.compose.ui.tooling.ComposeViewAdapter$FakeOnBackPressedDispatcherOwner$1.<init>(ComposeViewAdapter.kt:744)
    at androidx.compose.ui.tooling.ComposeViewAdapter.<init>(ComposeViewAdapter.kt:743)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:325)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:174)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:135)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:294)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:359)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:719)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:875)
    at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:192)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

Moreover I got this error:

We recommend using a newer Android Gradle plugin to use compileSdkPreview = "Tiramisu"

This Android Gradle plugin (7.3.0-alpha08) was tested up to compileSdk = 32

This warning can be suppressed by adding
    android.suppressUnsupportedCompileSdk=Tiramisu
to this project's gradle.properties

The build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdkPreview = "Tiramisu"

Even my Android Gradle Plugin is the newest. here is my build.gradle file:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.coolme.me.template_compose_11'
    compileSdkPreview 'Tiramisu'

    defaultConfig {
        applicationId "com.coolme.me.template_compose_11"
        minSdk 28
        targetSdkPreview 'Tiramisu'
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    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 = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_ui_version // '1.1.1'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
    buildToolsVersion '33.0.0 rc2'
    ndkVersion '25.0.8221429 rc2'
}

dependencies {

    implementation 'androidx.core:core-ktx:1.9.0-alpha02'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-alpha06'
    implementation 'androidx.activity:activity-compose:1.6.0-alpha01'
    implementation "androidx.compose.ui:ui:1.2.0-alpha07"
    implementation "androidx.compose.ui:ui-tooling-preview:1.2.0-alpha07"
    implementation 'androidx.compose.material:material:1.2.0-alpha07'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4-alpha05'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha05'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.2.0-alpha07"
    debugImplementation "androidx.compose.ui:ui-tooling:1.2.0-alpha07"
    debugImplementation "androidx.compose.ui:ui-test-manifest:1.2.0-alpha07"
}

and here is the other build.gradle file:

buildscript {
    ext {
        compose_ui_version = '1.2.0-alpha07'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.3.0-alpha08' apply false
    id 'com.android.library' version '7.3.0-alpha08' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

Please help me and thanks in Advance?

1

There are 1 answers

1
Dương Minh On

You can try the newest alpha version of com.android.application and com.android.library.

And don't forget to using Android Studio Canary to latest version.

If you need some information of my build.gradle and my Android Studio version, here you are:

My build.gradle.kts in root project:

plugins {
    id("com.android.application") version "7.4.0-alpha02" apply false
    id("com.android.library") version "7.4.0-alpha02" apply false
    id("org.jetbrains.kotlin.android") version "1.6.10" apply false
    id("org.jetbrains.kotlin.jvm") version "1.6.10" apply false
    id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version "2.0.1" apply false
}

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath("com.google.dagger:hilt-android-gradle-plugin:2.42")
    }
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

And my Android studio verion: enter image description here