Android studio 顶级 build.gradle 文件 - 如何设置 属性 较低级别的构建文件
Android studio top level build.gradle file - how to set property of lower level build file
我在 android 工作室中的顶级 build.gradle 文件如下所示:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
setProperty("buildFile",'build-ca.gradle')//system complains its read-only
}
这里没什么特别的,只是我正在尝试为应用程序 build.gradle 设置一个新名称。当我调用 setProperty 时,它会抱怨 buildFile 是只读的 属性。如何更改 build.gradle 文件的名称?
所以要清楚我正在尝试使用位于 app 文件夹下的第二个 build.gradle 文件。我的最终目标是拥有两个构建文件,当我调用 setProperty 时,我可以在它们之间切换。
更新:感谢接受的答案,这是我想出的:
在 gradle.properties 我添加了这一行:
useOtherFile=true
然后在 settings.gradle 文件中它看起来像这样:
boolean isOtherFile = properties['useOtherFile'] == 'true'
if(!isOtherFile)
project(':app').buildFileName = 'build-other.gradle
唯一不好的是我发现我有时不得不去文件 --> 在 android 工作室中使 caches/restart 无效,以便 IDE 更新构建变体。
不一样。
据我所知,您不能使用 setProperty
方法定义 gradle 文件。
您可以在 settings.gradle
文件中定义自定义名称。
类似于:
include ':app'
project(':app').buildFileName = 'mybuild.gradle'
我在 android 工作室中的顶级 build.gradle 文件如下所示:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
setProperty("buildFile",'build-ca.gradle')//system complains its read-only
}
这里没什么特别的,只是我正在尝试为应用程序 build.gradle 设置一个新名称。当我调用 setProperty 时,它会抱怨 buildFile 是只读的 属性。如何更改 build.gradle 文件的名称?
所以要清楚我正在尝试使用位于 app 文件夹下的第二个 build.gradle 文件。我的最终目标是拥有两个构建文件,当我调用 setProperty 时,我可以在它们之间切换。
更新:感谢接受的答案,这是我想出的:
在 gradle.properties 我添加了这一行:
useOtherFile=true
然后在 settings.gradle 文件中它看起来像这样:
boolean isOtherFile = properties['useOtherFile'] == 'true'
if(!isOtherFile)
project(':app').buildFileName = 'build-other.gradle
唯一不好的是我发现我有时不得不去文件 --> 在 android 工作室中使 caches/restart 无效,以便 IDE 更新构建变体。
不一样。
据我所知,您不能使用 setProperty
方法定义 gradle 文件。
您可以在 settings.gradle
文件中定义自定义名称。
类似于:
include ':app'
project(':app').buildFileName = 'mybuild.gradle'