【发布时间】:2021-02-27 03:09:57
【问题描述】:
我正在通过 android studio 开发一个 Android 应用程序,并且我正在尝试实现一个 Room 数据库。我使用https://developer.android.com/training/data-storage/room 进行说明,但是我无法正确导入它。尝试import androidx.room.*; 返回cannot resolve symbol 'room'。我无法找到解决此问题的方法。
我试过了:
- 使用
https://maven.google.com作为存储库 - 使用不同版本的房间
- 使用
api代替implementation
项目 Gradle 文件:
allprojects {
repositories {
jcenter()
google()
}
}
应用 Gradle 文件:
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
def room_version = "2.2.6"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
}
在 gradle 同步时,我发现它在 Download room-runtime-2.2.6.pom... 上卡住了 10-15 分钟,完成后显示警告:
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.2.6.
Show Details
Affected Modules: app
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.room:room-runtime:2.2.6.
Show Details
Affected Modules: app
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.room:room-runtime:2.2.6.
Show Details
Affected Modules: app
单击显示详细信息并没有将其定向到任何地方
编辑:我通过更改应用程序 build.gradle 文件以将 https://maven.google.com 存储库用于 buildscript 和 allprojects 来解决问题,以便我的 gradle 文件可以读取
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
还有
buildscript {
repositories {
maven {
url "https://maven.google.com"
}
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
【问题讨论】:
标签: java android android-studio android-room