android jetpack 项目给出 archlifecycleversion 构建错误
android jetpack project gives archlifecycleversion build error
我是 android 开发的新手,刚刚按照本教程在 android studio 3.2 ( canary ) 中创建了我的第一个 "hello world" 项目。
https://developer.android.com/jetpack/docs/getting-started
然后我只是做了 Build-> make project project tryed to build and gave me following error.
Could not get unknown property 'archLifecycleVersion' for root project 'JetpackHelloWorld' of type org.gradle.api.Project.
更新
依赖关系
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'
}
用实际版本替换$rootProject.archLifecycleVersion
,我猜现在是1.1.1
在您的应用 Gradle 文件中(build.gradle,您应该会在其右侧看到 "app"),您可能
implementation 'android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion'
改为:
implementation 'android.arch.lifecycle:extensions:1.1.1'
或将其添加到实施行的顶部
def archLifecycleVersion = 1.1.1
我认为部分(如果不是全部)代码来自此代码实验室:https://codelabs.developers.google.com/codelabs/android-room-with-a-view/
在代码实验室的第三部分,标题为 "Update gradle files" 他们使用这些行(在模块的 build.gradle 中)导入 Room 和 Lifecycle 组件:
// 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"
因此,这些 "roomVersion" 和 "archLifecycleVersion" 是您必须在主 build.gradle 文件中定义的变量。在示例中,他们使用这些值:
ext {
roomVersion = '1.0.0'
archLifecycleVersion = '1.1.0'
}
但实际上我对两个变量都使用了“1.1.1”并且它有效。
我是 android 开发的新手,刚刚按照本教程在 android studio 3.2 ( canary ) 中创建了我的第一个 "hello world" 项目。 https://developer.android.com/jetpack/docs/getting-started
然后我只是做了 Build-> make project project tryed to build and gave me following error.
Could not get unknown property 'archLifecycleVersion' for root project 'JetpackHelloWorld' of type org.gradle.api.Project.
更新
依赖关系
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'
}
用实际版本替换$rootProject.archLifecycleVersion
,我猜现在是1.1.1
在您的应用 Gradle 文件中(build.gradle,您应该会在其右侧看到 "app"),您可能
implementation 'android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion'
改为:
implementation 'android.arch.lifecycle:extensions:1.1.1'
或将其添加到实施行的顶部
def archLifecycleVersion = 1.1.1
我认为部分(如果不是全部)代码来自此代码实验室:https://codelabs.developers.google.com/codelabs/android-room-with-a-view/
在代码实验室的第三部分,标题为 "Update gradle files" 他们使用这些行(在模块的 build.gradle 中)导入 Room 和 Lifecycle 组件:
// 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"
因此,这些 "roomVersion" 和 "archLifecycleVersion" 是您必须在主 build.gradle 文件中定义的变量。在示例中,他们使用这些值:
ext {
roomVersion = '1.0.0'
archLifecycleVersion = '1.1.0'
}
但实际上我对两个变量都使用了“1.1.1”并且它有效。