如何使gradle的构建参数与依赖项的build.gradle文件一起使用

时间:2018-03-21 06:25:55

标签: android android-studio gradle

在我的项目中,我添加了一个像

这样的依赖
  

compile'c​​n.coderyu:library:1.4.0-SNAPSHOT

并且在库的build.gradle文件中,我有配置

manifestPlaceholders.put("SECURITY_FILE",getSecurityFile())

String getSecurityFile() { 
    if (project.hasProperty('HTTPS_CATCHABLE') && project.HTTPS_CATCHABLE.toLowerCase() == 'true' ) { 
        return "@xml/network_security_config" 
     } 
     return "@null" 
}

并在库的清单文件中添加

    <application
        android:networkSecurityConfig="${SECURITY_FILE}"
        android:allowBackup="true" android:label="@string/app_name"
        android:supportsRtl="true">

当我运行构建命令

gradle assembleRelease -PHTTPS_CATCHABLE=true

发布的apk中的清单文件是

  <application
    android:networkSecurityConfig="@null"
    android:allowBackup="true" android:label="mytest"
    android:supportsRtl="true">

如果我将库作为子模块导入,则命令有效

0 个答案:

没有答案