简体   繁体   中英

jetpack compose: @Preview is unresolved after updating to alpha08

I updated compose libraries from alpha07 to alpha08

version = "1.0.0-alpha08"
androidx.compose.ui:ui:$version
androidx.ui:ui-tooling:$version

But after that androidx.ui.tooling.preview.Preview is unresoved

Checking out the release note of alpha08 in Jetpack compose, you'll notice that ui-tooling has been moved from androidx.ui to androidx.compose.ui

Changes you need to make:

dependencies {
    // New dependencies
    implementation "androidx.compose.ui:ui-tooling:1.0.0-alpha08"
    testImplementation "androidx.compose.ui:ui-test:1.0.0-alpha08"

    // Old dependencies
    implementation "androidx.ui:ui-tooling:1.0.0-alpha07"
    testImplementation "androidx.ui:ui-test:1.0.0-alpha07"
}

you mean using:

dependencies {

// New dependencies
implementation 'androidx.compose.ui:ui-tooling:1.0.0-beta02"
testImplementation "androidx.compose.ui:ui-test:1.0.0-beta02"

// Old dependencies
implementation "androidx.ui:ui-tooling:1.0.0-alpha07"
testImplementation "androidx.ui:ui-test:1.0.0-alpha07"
}

And using

android {

//....

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
    useIR = true
}
buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerVersion "1.4.31"
    kotlinCompilerExtensionVersion "1.0.0-beta02"
}
}


tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach 
{
kotlinOptions {
    jvmTarget = "1.8"
}
 

but this doesn't fix the problem for me.

Top gradle:

dependencies {
    classpath "com.android.tools.build:gradle:4.2.0-alpha16"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"
 }

i didn't find any solution for now using last compose dependencies versions.

Solved the problem by:

  • Using the latest Android Studio Artic Fox (Canary build) and not any other canary old IDE.

  • Use Android studio Artic Fox Embeded JDK (openjdk version "11.0.8") or download and replace 1.8 java by OpenJdk 11.

  • Update dependencies as above.

in this case all are good and all compile,

Voila,

The latest tooling dependency which worked for me is

 implementation "androidx.compose.ui:ui-tooling:1.2.0-alpha07"

I am using

Android Studio Arctic Fox | 2020.3.1
Build #AI-203.7717.56.2031.7583922, built on July 27, 2021

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM