简体   繁体   English

无法为 org.gradle.api.Project 类型的根项目“RoomWordSample”获取未知属性“roomVersion”

[英]Could not get unknown property 'roomVersion' for root project 'RoomWordSample' of type org.gradle.api.Project

I am trying to learn about Android room from https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/#3我正在尝试从https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/#3了解 Android 房间

Fourth part is about updating Gradle files.第四部分是关于更新 Gradle 文件。 It gives several code snippets to include in它提供了几个代码片段以包含在

build.gradle (Module: app) build.gradle(模块:app)

I have included all the implementations, plugins etc mentioned on the page.我已经包含了页面上提到的所有实现、插件等。

   apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.testing.roomwordsample"
        minSdkVersion 18
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/atomicfu.kotlin_module'
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    // Room components
    implementation "androidx.room:room-runtime:$rootProject.roomVersion"
    kapt "androidx.room:room-compiler:$rootProject.roomVersion"
    implementation "androidx.room:room-ktx:$rootProject.roomVersion"
    androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

// Lifecycle components
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
    kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.archLifecycleVersion"

// Kotlin components
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutines"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"

// Material design
    implementation "com.google.android.material:material:$rootProject.materialVersion"

// Testing
    testImplementation 'junit:junit:4.12'
    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
}

ext {
    roomVersion = '2.2.5'
    archLifecycleVersion = '2.2.0'
    coreTestingVersion = '2.1.0'
    materialVersion = '1.1.0'
    coroutines = '1.3.4'
}

But build has failed and gives this error.但是构建失败并给出了这个错误。

Could not get unknown property 'roomVersion' for root project 'RoomWordSample' of type org.gradle.api.Project.无法为 org.gradle.api.Project 类型的根项目“RoomWordSample”获取未知属性“roomVersion”。

This is what build window is showing.这就是构建 window 显示的内容。 Error window错误 window

Step 5 of the Codelab instructions indicate you should add the ext-block containing the version strings to the Project build.gradle . Codelab 说明的第 5 步表明您应该将包含版本字符串的 ext 块添加到项目build.gradle中。 You added it to the app module build.gradle .您已将其添加到应用程序模块build.gradle

Cut this text from the app module build.gradle and paste it into the project build.gradle :从应用程序模块build.gradle中剪切此文本并将其粘贴到项目build.gradle

ext {
    roomVersion = '2.2.5'
    archLifecycleVersion = '2.2.0'
    coreTestingVersion = '2.1.0'
    materialVersion = '1.1.0'
    coroutines = '1.3.4'
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法获取类型为 org.gradle.api.Project 的根项目“myApp”的未知属性“com” - ERROR: Could not get unknown property 'com' for root project 'myApp' of type org.gradle.api.Project 无法为 org.gradle.api.Project 类型的根项目“Socialize”获取未知属性“appCompatVersion” - Could not get unknown property 'appCompatVersion' for root project 'Socialize' of type org.gradle.api.Project 无法为 org.gradle.api.Project 类型的根项目“android”获取未知属性“android” - Could not get unknown property 'android' for root project 'android' of type org.gradle.api.Project 无法为org.gradle.api.Project类型的根项目“MyApplication3”获取未知属性“删除” - Could not get unknown property 'Delete' for root project 'MyApplication3' of type org.gradle.api.Project 无法为 org.gradle.api.Project 类型的根项目“FirebaseExample”获取未知属性“android” - Could not get unknown property 'android' for root project 'FirebaseExample' of type org.gradle.api.Project react-native-onesignal无法获得类型为org.gradle.api.Project的根项目“ weather”的未知属性“ android” - react-native-onesignal Could not get unknown property 'android' for root project 'weather' of type org.gradle.api.Project 无法获得类型为org.gradle.api.Project的根项目'quickblox-android-sdk-master'的未知属性'fabricToolsVersion' - Could not get unknown property 'fabricToolsVersion' for root project 'quickblox-android-sdk-master' of type org.gradle.api.Project 无法为 org.gradle.api.Project 类型的项目“:app”获取未知属性“defaultCompileSdkVersion” - Could not get unknown property 'defaultCompileSdkVersion' for project ':app' of type org.gradle.api.Project 无法为类型为 org.gradle.api.Project 的项目“:app”获取未知属性“localProperties” - Could not get unknown property 'localProperties' for project ':app' of type org.gradle.api.Project 无法为类型为 org.gradle.api.Project 的项目“:app”获取未知属性“android” - Could not get unknown property 'android' for project ':app' of type org.gradle.api.Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM