【发布时间】:2019-05-08 13:13:25
【问题描述】:
我想在点击链接时打开一个活动(显示带有应用名称的操作选择器)。一切正常,我的应用程序会显示操作选择器,但前提是我不在 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。
我做错了什么?
【问题讨论】:
-
从您的 gradle.properties 变量中尝试这种方式:
manifestPlaceholders = [host: project.property('HOST_NAME_PROD')] -
“它不起作用”——“它不起作用”是什么意思?实际行为是什么?您收到哪些错误消息?
-
@CommonsWare 当我单击链接时打开带有上述意图过滤器的活动,但前提是我在 manifestPlaceholders (manifestPlaceholders = [host: "dev.mysite.com"]) 或字符串中使用字符串res (resValue "string", "host", HOST_NAME_PROD)
-
@JeelVankhede 仍然无法正常工作
标签: android gradle build manifest