gpt4 book ai didi

android - Gradle 设置 : Invalid variable name. 必须以字母开头,但是:

转载 作者:行者123 更新时间:2023-12-03 04:22:16 25 4
gpt4 key购买 nike

在设置我的 android 项目时出现问题:

startup failed:
settings file '/home/user/StudioProjects/project/android/settings.gradle': 1: Invalid variable name. Must start with a letter but was: rootProject
. At [1:1] @ line 1, column 1.
rootProject.name = 'project'
^

1 error

Open File

但问题是我在“rootProject”变量名之前没有任何符号。
有什么想法吗?

最佳答案

如果您尝试在根目录中设置一些全局变量 gradle文件然后在您的模块中重用它们的build.gradle ,我如何让它工作的是:

  • 在根目录 build.gradle :
    buildscript {
    ... blah blah
    }

    // put HERE all your variables, they will automatically
    // be available as rootProject.xxx in the rest of build.gradles
    ext {
    name = "project"
    compileSdkVersion = 27
    targetSdkVersion = 27
    supportLibraryVersion = "27.0.2"
    buildToolsVersion = "26.0.1"
    googleServicesVersion = "11.8.0"
    }

    allprojects {
    ... blah blah
    }
    .
    .
  • 然后在你的APP(或模块)build.gradle ,您可以使用它们:
    apply plugin: 'com.android.application'

    android {

    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
    applicationId "xxxx"
    targetSdkVersion rootProject.targetSdkVersion
    .
    .
    }
  • 关于android - Gradle 设置 : Invalid variable name. 必须以字母开头,但是:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49669441/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com