gpt4 book ai didi

android-studio - 在构建阶段找不到房间编译器错误

转载 作者:行者123 更新时间:2023-12-03 03:57:41 25 4
gpt4 key购买 nike

我正在尝试在我的 android 项目中添加 Room 支持。我已将所有依赖项添加到 gradle 文件中,并且它成功构建...一次。以下每个构建结果为 Could not find androidx.room:room-compiler:compiler
这是我的模块 gradle 文件:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
google()
}

buildscript{
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
google()
}
}

android {
//...
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
transitive = true
}
implementation 'com.airbnb.android:lottie:2.2.0'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'

def room_version = "2.1.0-alpha03"

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:compiler:$room_version"
}

这是我的项目 gradle 文件:
apply plugin: 'kotlin-android-extensions'
apply plugin: 'announce'
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}



allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url "https://maven.google.com" }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

task info {
doLast {
announce.announce "Running $it.name", 'local'
println gradle.gradleVersion
}
}

最后,这是完整的错误:
Could not find androidx.room:room-compiler:compiler.
Searched in the following locations:
- file:/home/miku/Android/Sdk/extras/m2repository/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- file:/home/miku/Android/Sdk/extras/m2repository/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- file:/home/miku/Android/Sdk/extras/google/m2repository/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- file:/home/miku/Android/Sdk/extras/google/m2repository/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- file:/home/miku/Android/Sdk/extras/android/m2repository/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- file:/home/miku/Android/Sdk/extras/android/m2repository/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- https://jcenter.bintray.com/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- https://jcenter.bintray.com/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- https://jitpack.io/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- https://jitpack.io/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- https://maven.google.com/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- https://maven.google.com/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- https://repo.maven.apache.org/maven2/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- https://repo.maven.apache.org/maven2/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- https://maven.fabric.io/public/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- https://maven.fabric.io/public/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
- https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/compiler/room-compiler-compiler.pom
- https://dl.google.com/dl/android/maven2/androidx/room/room-compiler/compiler/room-compiler-compiler-2.1.0-alpha03.jar
Required by:
project :fpcommonlib

Gradle 可以很好地同步,所以它看起来就像是在寻找所需的库一样。然而,构建应用程序会使 Android Studio 显示该错误消息,而不是实际构建应用程序。所以看起来 Gradle 和 Build 出于某种原因正在使用不同的存储库。
除此之外,Kotlin 代码也没有显示任何错误。

最佳答案

好的,所以经过一番忙碌后,我确实找到了解决方案

我创建了一个新项目并添加了原始项目中使用的所有其他依赖项。然后我将项目 Gradle 从新项目复制到旧项目中并且它工作。我不知道为什么,因为两个 Gradle 文件看起来都一样。

但只是为了保存(我可能会遗漏一些明显的东西)这里都是 Gradle 文件

工作一:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
google()
}

buildscript{
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
google()
}
}

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
//implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
transitive = true
}

implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'com.airbnb.android:lottie:2.8.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.core:core-ktx:1.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

def room_version = "2.1.0-alpha04"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
}

损坏之一:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
google()
}

buildscript{
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
google()
}
}

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
// implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
transitive = true
}
implementation 'com.airbnb.android:lottie:2.8.0'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
def room_version = "2.1.0-alpha04"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:compiler:$room_version"
}

关于android-studio - 在构建阶段找不到房间编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54251097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com