我是Android开发的新手,刚创建了我的第一个" hello world"本教程后面的android studio 3.2(canary)中的项目。 https://developer.android.com/jetpack/docs/getting-started
然后我就做了 Build-> make project 项目尝试构建并给了我以下错误。
无法获得未知的财产' archLifecycleVersion'对于根项目和JetpackHelloWorld'类型为org.gradle.api.Project。
更新
依赖关系
以下是我的app文件夹build.gradle文件中的dependencies标记
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'
}
答案 0 :(得分:3)
将$rootProject.archLifecycleVersion
替换为实际版本,我想现在是1.1.1
答案 1 :(得分:2)
在您的应用Gradle文件(build.gradle中,您应该看到右侧的“app”),您可能有
implementation 'android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion'
将其更改为:
implementation 'android.arch.lifecycle:extensions:1.1.1'
或将其添加到实施行的顶部
def archLifecycleVersion = 1.1.1
答案 2 :(得分:1)
我认为部分(如果不是全部)代码来自以下代码实验室:https://codelabs.developers.google.com/codelabs/android-room-with-a-view/
在代码实验室的第三部分标题为“更新gradle文件”中,他们使用以下行(在模块的build.gradle中)导入Room和Lifecycle组件:
$count = 1;
$total_rows = 13;
$total_level = 13;
$total_cols = 3;
$total_global = 3;
$active_rows = 0;
$active_cols = 0;
$active_levels = 0;
$active_global = 0;
$betArray = array();
$aciveChoice[$total_rows] = 0;
$globalChoice[$total_level] = 0;
while($active_rows < $total_rows){
while($active_cols < $total_cols){
while($active_global < $total_global){
while($active_levels < $total_level){
echo $active_rows.' - '.$active_levels.': Select:'.$active_cols.' - '.$active_global.'<br/>';
$active_levels++;
}
echo $count++.'<br /><br /><br />';
$active_levels = 0;
$active_global++;
}
$active_global = 0;
$active_cols++;
}
$active_cols = 0;
$active_rows++;
}
}
因此,这些“ roomVersion”和“ archLifecycleVersion”是必须在主build.gradle文件中定义的变量。在示例中,他们使用以下值:
// 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"
但是我实际上对两个变量都使用了“ 1.1.1”,并且可以正常工作。