android - 重建应用程序时,Cordova Android 未将自定义 URL 方案插件中的所有 xml 添加到 AndroidManifest
问题描述
我将插件https://github.com/EddyVerbruggen/Custom-URL-scheme添加到我的 cordova 项目中。
该插件在适用于 Android 的 plugin.xml 文件中包含以下内容:
<config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
<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="$URL_SCHEME"/>
</intent-filter>
<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="$ANDROID_SCHEME"
android:host="$ANDROID_HOST"
android:pathPrefix="$ANDROID_PATHPREFIX" />
</intent-filter>
</config-file>
安装插件时,我提供 CUSTOM_URL 变量的值:
cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=appscheme
然后我使用cordova run android --emulator 在模拟器中运行该应用程序。Android Manifest 正确生成,包括两个意图过滤器块:
<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"/>
</intent-filter>
<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=" " android:host=" " android:pathPrefix="/" />
</intent-filter>
事情按预期工作。
但是,如果我随后对我的项目进行任何更改,并通过再次运行 cordova run android 来重建应用程序,那么 Android Manifest 文件中缺少一个意图过滤器块,并且插件功能不起作用。
<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=" " android:host=" " android:pathPrefix="/" />
</intent-filter>
我需要删除插件,然后将其重新添加,以便正确生成 AndroidManifest.xml。
知道为什么它会在重建时删除一个意图过滤器块吗?
谢谢你的帮助!
解决方案
在阅读了这篇文章中接受的解决方案的第一条评论后,我找到了一个解决方案: Cordova Change AndroidManifest using Config.xml file
我需要从我的 config.xml 文件中删除这个:
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity[@android:name='MainActivity']">
<activity android:theme="@style/Full" />
</edit-config>
而是在项目中使用cordova-custom-config插件,并在config.xml中使用:
<custom-preference name="android-manifest/application/activity/@android:theme" value="@style/Full" />
现在一切都进入了 AndroidManifest.xml 文件。
推荐阅读
- c# - 如何在 WPF 数据网格中显示 N 个项目?
- python - 如何从数据框中获取以特定值开头的列列表?
- javascript - 如何使用 Javascript 在 Razor 页面中运行后台程序
- sql - 未定义的函数:“格式”。该函数既不是注册的临时函数也不是数据库中注册的永久函数
- git - Visual Studio:将分支推送到远程存储库时遇到错误:无法拉取以集成更改:拉取命令已禁用
- sql-server - 使用 WHERE 子句排除数据,但仅在某些条件下
- bash - 如何防止Expect输出CRLF?
- xamarin - 如何将文件选择器打开按钮文本更改为在 xamarin 表单 UWP 中发送?
- c# - 如何使用名称等属性覆盖 WPF 中特定列的数据网格单元格?
- unit-testing - 如果 ArrayList 已经包含回调,如何测试是否未添加回调 - 单元测试