Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android studio 在生成阶段找不到文件室编译器错误_Android Studio_Gradle_Android Room - Fatal编程技术网

Android studio 在生成阶段找不到文件室编译器错误

Android studio 在生成阶段找不到文件室编译器错误,android-studio,gradle,android-room,Android Studio,Gradle,Android Room,我正在尝试在我的android项目中添加房间支持。我已将所有依赖项添加到gradle文件,并且它已成功构建。。。一旦中的每个后续生成结果都找不到androidx.room:room编译器:编译器 这是我的模块梯度文件: apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' re

我正在尝试在我的android项目中添加房间支持。我已将所有依赖项添加到gradle文件,并且它已成功构建。。。一旦
中的每个后续生成结果都找不到androidx.room:room编译器:编译器

这是我的模块梯度文件:

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"
}
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
    }
}
这是我的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"
}
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"
}

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

致以最良好的祝愿