如何解决无法解决:androidx
我正在使用其中一个代码实验室教程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()
}
}
,
我没有看到 build.gradle(app)和 build.gradle 的区别,这是一个愚蠢的错误。如果万一有人遇到相同的错误,请遵循此步骤。我需要两天时间才能接受我的回答,但对我有用。
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'
}```
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。