如何解决找不到android.arch.lifecycle:编译器?

时间:2017-09-27 07:35:25

标签: android-lifecycle

我正在尝试使用Android生命周期,但我正在加入生命周期编译器依赖。

这是模块build.gradle,

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    dataBinding {
        enabled = true
    }
    defaultConfig {
        applicationId "com.example.jj.mvvm"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    kapt 'com.android.databinding:compiler:2.3.3'

    implementation "android.arch.lifecycle:runtime:1.0.0"
    implementation "android.arch.lifecycle:extensions:1.0.0-beta1"
    kapt "android.arch.lifecycle:compiler:1.0.0-beta1"
}
repositories {
    mavenCentral()
}

我收到了以下错误,

Error:Could not find android.arch.lifecycle:compiler:1.0.0-beta1.
Searched in the following locations:
    file:/C:/Users/jj/AppData/Local/Android/android-sdk/extras/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.pom
    file:/C:/Users/jj/AppData/Local/Android/android-sdk/extras/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.jar
    file:/C:/Users/jj/AppData/Local/Android/android-sdk/extras/google/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.pom
    file:/C:/Users/jj/AppData/Local/Android/android-sdk/extras/google/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.jar
    file:/C:/Users/jj/AppData/Local/Android/android-sdk/extras/android/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.pom
    file:/C:/Users/jj/AppData/Local/Android/android-sdk/extras/android/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.jar
    file:/C:/Program Files/Android/Android Studio/gradle/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.pom
    file:/C:/Program Files/Android/Android Studio/gradle/m2repository/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.jar
    https://jcenter.bintray.com/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.pom
    https://jcenter.bintray.com/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.jar
    https://repo1.maven.org/maven2/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.pom
    https://repo1.maven.org/maven2/android/arch/lifecycle/compiler/1.0.0-beta1/compiler-1.0.0-beta1.jar
Required by:
    project :app

这是项目build.gradle文件,

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.1.50'

    repositories {
        jcenter()
        google()
    }
    dependencies {
        // classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.android.tools.build:gradle:3.0.0-beta4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

你能否回顾一下我做错了什么?

**我的Android工作室版本是2.3.3,我正在使用Kotlin

4 个答案:

答案 0 :(得分:2)

尝试将maven { url 'https://maven.google.com' }添加到构建脚本存储库:

buildscript {
    ext.kotlin_version = '1.1.50'

    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        google()
    }

注意,如果您使用的是Java 8,则不再需要android.arch.lifecycle:compiler:1.0.0-beta1You can use android.arch.lifecycle:common-java8:1.0.0-beta1 instead

答案 1 :(得分:1)

您必须替换当前版本的LifeCycle。

implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.1.0"

在这里您可以看到依赖关系的当前版本 https://developer.android.com/jetpack/androidx/releases/lifecycle

答案 2 :(得分:0)

对于我的Cordova项目,我将maven { url 'https://maven.google.com' }放在jcenter()之前:

buildscript {
    repositories {
         maven {
            url "https://maven.google.com"
        }
        jcenter()
    }

这解决了我的问题

答案 3 :(得分:0)

在我的情况下(找不到 core-runtime-2.1.0.aar) 2H 搜索后解决

allprojects {
repositories {
    google() // TOP 
    ........
    ........
    ........
}

}