我正在使用一个代码库教程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
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"
}发布于 2020-09-01 16:07:00
我犯了一个愚蠢的错误,没有看到build.gradle(app)和build.gradle的不同之处。如果有人遇到同样的错误,请跟随this.It,我需要两天时间才能接受我的答案,但这对我来说是有效的。
build.gradle(app)
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
roomVersion = '2.2.1'
archLifecycleVersion = '2.2.0'
coreTestingVersion = '2.1.0'
materialVersion = '1.0.0'
}```发布于 2020-09-01 13:33:50
可能是因为在项目级别的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()
}
}https://stackoverflow.com/questions/63686939
复制相似问题