无法从外部gradle文件获取未知属性

时间:2017-10-03 19:22:20

标签: android gradle

在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>

1 个答案:

答案 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)