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

时间:2019-01-18 09:35:07

标签: android-studio gradle android-room

我正在尝试在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代码也不显示任何错误。

2 个答案:

答案 0 :(得分:0)

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

我创建了一个新项目,并添加了原始项目中已使用的所有其他依赖项。然后,我将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"
}

答案 1 :(得分:0)

也许有点晚了,但是对我来说,删除项目文件夹中的.idea /和.gradle /目录就足够了。

最诚挚的问候!