来自gradle.properties的Android manifestPlaceholders

时间:2019-05-08 13:13:25

标签: android gradle build manifest

我要在点击链接时打开一个活动(显示带有应用程序名称的操作选择器)。一切正常,动作选择器与我的应用程序一起显示,但前提是我未在manifestPlaceholder中使用属性名称,否则将打开默认浏览器(无任何错误)。

我在gradle.properties文件中有以下几行:

HOST_NAME_DEV="dev.mysite.com"
HOST_NAME_PROD="mysite.com"

我想要创建一个manifestPlaceholder:

// in manifest
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
        <data
             android:host="${host}"
             android:scheme="https" />
</intent-filter>

//in build.gradle
productFlavors {
        production {
            manifestPlaceholders = [host: HOST_NAME_PROD]
        }
        develop {
            manifestPlaceholders = [host: HOST_NAME_DEV]
        }
}

它不起作用。

但是,如果我将字符串粘贴到manifestPlaceholder中,则一切正常:

productFlavors {
        production {
            manifestPlaceholders = [host: "mysite.com"]
        }
        develop {
            manifestPlaceholders = [host: "dev.mysite.com"]
        }
}

通过这种方式,一切都很好:

productFlavors {
        production {
            resValue "string", "host", HOST_NAME_PROD
        }
        develop {
            resValue "string", "host", HOST_NAME_DEV
        }
    }

// and in manifest
android:host="@string/host"

但是我想使用manifestPlaceholders。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

问题:清单中插入了“(双引号)的数据。

解决方案:从gradle.properties的值中删除“(双引号)。 就是这样:

HOST_NAME_DEV=dev.mysite.com
HOST_NAME_PROD=mysite.com
相关问题