android jetpack project gives archlifecycleversion build error

前提是你 提交于 2019-12-02 01:11:52

问题


I am new to android development and just created my first "hello world" project in android studio 3.2 ( canary ) following this tutorial. https://developer.android.com/jetpack/docs/getting-started

and then I just did Build- > make project project tried to build and gave me following error.

Could not get unknown property 'archLifecycleVersion' for root project 'JetpackHelloWorld' of type org.gradle.api.Project.

UPDATE

Dependencies

following is the dependencies tag in my app folder build.gradle file

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

回答1:


Replace $rootProject.archLifecycleVersion with actual version, i guess this is 1.1.1 right now




回答2:


In your app Gradle file (build.gradle, you should see "app" to its right), you probably have

implementation 'android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion'

Change it to:

implementation 'android.arch.lifecycle:extensions:1.1.1'

or add this to the top of your implementation line

def archLifecycleVersion = 1.1.1



回答3:


I think part (if not all) of the code is taken from this codelab: https://codelabs.developers.google.com/codelabs/android-room-with-a-view/

In the third part of the codelab, titled "Update gradle files" they use these lines (in the module's build.gradle) to import Room and Lifecycle components:

// Room components
implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"

// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"

So, these "roomVersion" and "archLifecycleVersion" are variables that you have to define in the main build.gradle file. In the example they use these values:

ext {
   roomVersion = '1.0.0'
   archLifecycleVersion = '1.1.0'
}

But I've actually used "1.1.1" for both variables and it works.



来源:https://stackoverflow.com/questions/50329891/android-jetpack-project-gives-archlifecycleversion-build-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!