我正在使用其中一个代码实验室教程https://codelabs.developers.google.com/codelabs/android-room-with-a-view/index.html?index=..%2F..index#3
在编辑buil.gradle(应用程序)时读取。我收到无法解决:androidx 无法解决:androidx.arch 无法解决:com.google.android
build.gradle


android {
    compileSdkVersion 29
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.example.androidroomcodelabs"
        minSdkVersion 21
        targetSdkVersion 29
        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 = 1.8
        targetCompatibility = 1.8
    }

}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'


    // Room components
    implementation "androidx.room:room-runtime:$rootProject.2.2.4"
    annotationProcessor "androidx.room:room-compiler:$rootProject.2.2.4"
    androidTestImplementation "androidx.room:room-testing:$rootProject.2.2.4"

// Lifecycle components
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.2.3.0"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$rootProject.2.3.0"

// UI
    implementation "com.google.android.material:material:$rootProject.1.0.0"

// Testing
    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.1.2.0"

}

最佳答案

可能是因为在项目级别的build.gradle文件中缺少对Google Maven存储库的引用:

buildscript {
    repositories {
        google() // this allow to lookup in the Google's maven repository
        jcenter()
    }

    ...
}

allprojects {
    repositories {
        google() // this allow to lookup in the Google's maven repository
        jcenter()
    }
}

09-26 11:42