Moc*_*cha 2 android deep-linking android-manifest
我正在尝试使用 build.gradle 将 url 架构和路径动态注入到我的 AndroidManifest.xml 文件中作为参考
但是,这不允许触发深度链接。
当我在 AndroidManifest.xml 中使用静态值时,我测试了深度链接的工作情况。
// AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="${appScheme}"
android:host="${hostName}"
android:path="/path2" />
<data
android:scheme="${appScheme}"
android:host="${hostName}"
android:path="/path1" />
</intent-filter>
// build.gradle (:app)
defaulConfig {
manifestPlaceholders = [
hostName: "www.host_name.com",
appScheme: "https"
]
}
demo {
resValue "string", "hostName", "www.host_demo.com"
resValue "string", "appScheme", "https"
}
staging {
resValue "string", "hostName", "www.host_staging.com"
resValue "string", "appScheme", "http"
}
Run Code Online (Sandbox Code Playgroud)
我认为你在这里可以做的是在 defaultConfig 中定义这些字符串,如下所示:
android {
...
defaultConfig {
...
flavorDimensions 'yourAppName'
resValue "string", "host_name", "www.live_demo.com"
resValue "string", "app_scheme", "http"
productFlavors {
demo {
dimension 'yourAppName'
resValue "string", "host_name", "www.host_demo.com"
}
staging {
dimension 'yourAppName'
resValue "string", "host_name", "www.host_staging.com"
}
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
重建后,如果您希望拥有像您在代码中定义的那样的产品风味,将为您生成host_name。app_scheme这对我处理的每个项目都适用:)
app/build/generated/res/resValues/debug/values/gradleResValues.xml
app/build/generated/res/resValues/demo/values/gradleResValues.xml
app/build/generated/res/resValues/staging/values/gradleResValues.xml
Run Code Online (Sandbox Code Playgroud)
然后AndroidManifest.xml,您可以从您的文件中调用@string/host_name而不是${hostName}.
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="@string/app_scheme"
android:host="@string/host_name"
android:path="/path2" />
<data
android:scheme="@string/app_scheme"
android:host="@string/host_name"
android:path="/path1" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
PS:我更喜欢用蛇形命名法定义字符串资源。:)
| 归档时间: |
|
| 查看次数: |
2765 次 |
| 最近记录: |