首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解决失败: androidx

解决失败: androidx
EN

Stack Overflow用户
提问于 2020-09-01 11:40:13
回答 2查看 791关注 0票数 0

我正在使用一个代码库教程https://codelabs.developers.google.com/codelabs/android-room-with-a-view/index.html?index=..%2F..index#3。在编辑buil.gradle (app)时使用的Int。我得到了未能解决: androidx未能解决: androidx.arch &未能解决: com.google.android

build.gradle

代码语言:javascript
复制
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"

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-01 16:07:00

我犯了一个愚蠢的错误,没有看到build.gradle(app)build.gradle的不同之处。如果有人遇到同样的错误,请跟随this.It,我需要两天时间才能接受我的答案,但这对我来说是有效的。

build.gradle(app)

代码语言:javascript
复制
    implementation "androidx.room:room-runtime:$rootProject.roomVersion"
    annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"
    androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

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

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

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

保留roomVersion、archLifecycleVersion、coreTestingVersion和materialVersion的原样,并在build.gradle中添加以下版本

build.gradle

代码语言:javascript
复制
    roomVersion = '2.2.1'
    archLifecycleVersion = '2.2.0'
    coreTestingVersion = '2.1.0'
    materialVersion = '1.0.0'
}```
票数 0
EN

Stack Overflow用户

发布于 2020-09-01 13:33:50

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

代码语言:javascript
复制
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()
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63686939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档