Android Studio 无法导入rememberSnapFlingBehavior

kgsdhlau  于 2023-03-24  发布在  Android
关注(0)|答案(1)|浏览(132)

我尝试在编写应用程序中实现this behavior,但当我使用以下import语句导入所需函数时,Android Studio出现Unresolved reference: snapping错误。

import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior

在我的build.gradle文件中,我注意到compose_versionkotlinCompilerExtensionVersion变量都默认设置为1.2.0,所以我尝试将它们设置为1.3.1,但它没有解决这个问题。
以下是我当前的build.gradle(项目)文件:

buildscript {
    ext {
        compose_version = '1.3.1'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

build.gradle(App)文件:

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

android {
    namespace 'com.example.app'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.app"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"

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

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            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 '1.3.1'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.compose.material3:material3:1.0.1'
    implementation "androidx.compose.material:material-icons-extended:$compose_version"
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

我还可以尝试什么来解决这个问题?

irlmq6kh

irlmq6kh1#

您需要在模块级build.gradle文件中添加Compose Foundation依赖项。

dependencies {
    implementation("androidx.compose.foundation:foundation:1.3.1")
}

相关问题