【问题标题】:Jetpack Compose Material 3 Error . Could not resolve all files for configuration ':app:debugRuntimeClasspath'Jetpack 组合材料 3 错误。无法解析配置 \':app:debugRuntimeClasspath\' 的所有文件
【发布时间】:2022-10-25 18:18:46
【问题描述】:

运行简单的 Jetpack Compose Material 3 项目时出现两行错误

build.gradle(项目:)

    buildscript {
    ext {
        compose_version = '1.3.0-beta02'
        core_ktx_version = '1.9.0-rc01'
        material3_version = 'material3:1.3.0-beta02'
        lifecycle_version =  '2.4.1'
        activity_compose_version = '1.5.1'
        nav_version = "2.5.2"
        hilt_version = "2.42"
        hilt_nav_fragment = "1.0.0"
        lottieVersion = "5.2.0"
        timber_version = "5.0.1"
        hilt_navigation_compose = "1.0.0"
        room_version = "2.3.0-beta02"
        kotlin_version = "1.6.21"
    }
    dependencies {

        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
        classpath "com.android.tools.build:gradle:4.2.1"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(模块:)

 plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}

android {
    compileSdk 33

    defaultConfig {
        applicationId "com.jetpackcompose.jp1"
        minSdk 24
        targetSdk 33
        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_version
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation "androidx.core:core-ktx:$core_ktx_version"
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material3:$material3_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
    implementation "androidx.activity:activity-compose:$activity_compose_version"

    implementation "androidx.compose.compiler:compiler:1.3.1"
    implementation 'androidx.appcompat:appcompat:1.6.0-beta01'
    // hilt -android
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"

    // To Integrate Navigation
    implementation "androidx.navigation:navigation-compose:$nav_version"

    // To use additional extensions of navigation frameworks like hiltViewModel()
    implementation "androidx.hilt:hilt-navigation-fragment:$hilt_nav_fragment"
    implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation_compose"
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    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"
 }

设置.gradle:

    pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven {
            url "https://maven.google.com"
        }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url "https://maven.google.com"
        }
    }
}
rootProject.name = "jp1"
include ':app'

当我运行该项目时,出现以下错误:

任务 ':app:desugarDebugFileDependencies' 执行失败。

无法解析配置“:app:debugRuntimeClasspath”的所有文件。 找不到 androidx.compose.material3:material3:1.3.0-beta02。

【问题讨论】:

    标签: android kotlin android-jetpack-compose dagger-hilt android-jetpack-compose-material3


    【解决方案1】:

    Compose 编译器和其他 compose 依赖项具有不同的版本.
    androidx.compose.compiler:compiler:1.3.0-beta02 版本不存在。
    你可以在google maven repo查看

    在任何情况下,您都可以使用模块编译器1.3.1 的稳定版本以及1.2.11.3.0-beta02 的所有其他组合依赖项:

    buildscript {
        ext {
            compose_compiler = '1.3.1'         //compiler
            compose_version = '1.3.0-beta02'   //compose dependencies
            compose_material3 = '1.0.0-beta02' //material3 release
        }
        //...
    }
    

    接着:

    composeOptions {
        kotlinCompilerExtensionVersion compose_compiler
    }
    
    dependencies {
       // beta 1.3.0 releases
       implementation "androidx.compose.material:material:$compose_version"
       //... 
    
       //material3
       implementation "androidx.compose.material3:material3:$compose_material3"
    }
    

    documentation 中所述,编译器 1.3.x 需要 kotlin 1.7.10:

    【讨论】:

    • 原因:org.gradle.internal.resolve.ModuleVersionNotFoundException:找不到androidx.compose.material3:material3:1.3.0-beta02。我再次遇到这样的错误@Gabriele Mariotti
    • @SasidharanIOS 因为material3 1.3.0 不存在。你必须检查你的依赖:developer.android.com/jetpack/androidx/releases/…
    • 工作正常..非常感谢@Gabriele Mariotti
    猜你喜欢
    • 2021-09-03
    • 2022-08-06
    • 2022-08-19
    • 2022-08-02
    • 1970-01-01
    • 2018-05-22
    • 2021-05-19
    • 2022-10-22
    • 2021-03-16
    相关资源
    最近更新 更多