在app目录中,我有 constants.gradle :
def APP_NAME_RELEASE = "My Project name"
在 app / build.gradle 中,我有:
apply from: 'constants.gradle'
println("APP_NAME_RELEASE = " + APP_NAME_RELEASE)
但是当我尝试构建时,我得到了错误:
Error:(2, 0) Could not get unknown property 'APP_NAME_RELEASE' for project ':app' of type org.gradle.api.Project.
<a href="openFile:myproject\app\build.gradle">Open File</a>
答案 0 :(得分:0)
您可以使用ExtraPropertiesExtension:
<强> constants.gradle 强>
ext.APP_NAME_RELEASE = "My Project name"
应用/的build.gradle 强>
apply from: 'constants.gradle'
println("APP_NAME_RELEASE = " + ext.APP_NAME_RELEASE)