android studio中的顶级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工作室中的缓存/重启无效,以便IDE更新构建变体。
答案 0 :(得分:0)
不一样。
据我所知,您无法使用setProperty
方法定义gradle文件。
您可以在settings.gradle
文件中定义自定义名称。
类似的东西:
include ':app'
project(':app').buildFileName = 'mybuild.gradle'