android - 如何在我的 Cordova 应用程序中创建 android.json?

标签 android cordova cordova-plugins deep-linking

所以我有一个使用 ionic-plugin-deeplinks 插件的 iOS/Android Ionic Cordova 应用程序。当 AndroidManifest.xml 中包含以下内容时,该插件无法正常工作:

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:host="synapticforce.com" android:pathPrefix="/" android:scheme="https" />
    <data android:host=" " android:pathPrefix="/" android:scheme=" " />
    <data android:host=" " android:pathPrefix="/" android:scheme=" " />
    <data android:host=" " android:pathPrefix="/" android:scheme=" " />
    <data android:host=" " android:pathPrefix="/" android:scheme=" " />
</intent-filter>

但是当我把它放在它的地方它工作正常:
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="yourekamobile" />
</intent-filter>

但是,每当我 ionic prepare如果将我的修复覆盖回原来的无效方式。我试图更改父级中的某些内容 config.xml对于 cordova 以及 plugin.xml parent/plugins/ionic-plugin-deeplinks文件夹,它仍然会被覆盖到原来的损坏方式。然后我进去了parent/platforms/android/android.json并将原始版本的编写位置更改为我的版本,并且始终可以正常构建。

所以我很高兴它有效,但我的问题是它为什么有效? android.json怎么样建?编辑该文件是正确的做法,还是它从中提取了一些我应该编辑的东西?

最佳答案

很久没发这个了,但是我也遇到了同样的问题,下面是我的解决方法。
如果您进入 plugins 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 android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="$DEEPLINK_SCHEME" android:host="$DEEPLINK_HOST" android:pathPrefix="$ANDROID_PATH_PREFIX" />
                <data android:scheme="$DEEPLINK_2_SCHEME" android:host="$DEEPLINK_2_HOST" android:pathPrefix="$ANDROID_2_PATH_PREFIX" />
                <data android:scheme="$DEEPLINK_3_SCHEME" android:host="$DEEPLINK_3_HOST" android:pathPrefix="$ANDROID_3_PATH_PREFIX" />
                <data android:scheme="$DEEPLINK_4_SCHEME" android:host="$DEEPLINK_4_HOST" android:pathPrefix="$ANDROID_4_PATH_PREFIX" />
                <data android:scheme="$DEEPLINK_5_SCHEME" android:host="$DEEPLINK_5_HOST" android:pathPrefix="$ANDROID_5_PATH_PREFIX" />
            </intent-filter>
        </config-file>
如果您在该文件中看起来更高一点,它会将所有这些变量设置为空白或“/”。
这就是设置 android.json 和 AndroidManifest.xml 的原因。
为了解决这与深度链接有关的问题,我在 config.xml 中添加了以下内容以覆盖这些“默认”设置。可能值得一提的是,以下内容与标签放置在同一级别,因此它实际上不在其中任何一个内部。
    <plugin name="ionic-plugin-deeplinks" spec="1.0.22">
      <variable name="URL_SCHEME" value="myapp" />
      <variable name="DEEPLINK_SCHEME" value="https" />
      <variable name="DEEPLINK_HOST" value="temp-site.ngrok.io" />
      <variable name="ANDROID_PATH_PREFIX" value="/app-auth" />
      <variable name="DEEPLINK_2_SCHEME" value="https" />
      <variable name="DEEPLINK_2_HOST" value="temp-site.ngrok.io" />
      <variable name="ANDROID_2_PATH_PREFIX" value="/app-auth" />
      <variable name="DEEPLINK_3_SCHEME" value="https" />
      <variable name="DEEPLINK_3_HOST" value="temp-site.ngrok.io" />
      <variable name="ANDROID_3_PATH_PREFIX" value="/app-auth" />
      <variable name="DEEPLINK_4_SCHEME" value="https" />
      <variable name="DEEPLINK_4_HOST" value="temp-site.ngrok.io" />
      <variable name="ANDROID_4_PATH_PREFIX" value="/app-auth" />
      <variable name="DEEPLINK_5_SCHEME" value="https" />
      <variable name="DEEPLINK_5_HOST" value="temp-site.ngrok.io" />
      <variable name="ANDROID_5_PATH_PREFIX" value="/app-auth" />
    </plugin>
我是 Cordova 的新手,所以我确信有更好的方法来做到这一点(也许使用 'after' 钩子(Hook)?)但这是我快速而肮脏的解决方案。

关于android - 如何在我的 Cordova 应用程序中创建 android.json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48232782/

相关文章:

Android 广告大大降低了性能

android - 将 cordova 插件依赖项添加到 build.gradle

angularjs - 使用 Ionic 和 Cordova 创建相机图像过滤器

cordova - 安装 cordova 插件时出错

java - 当 http 连接超时时为 TextView 设置文本

android - 如何在EditBox上获取语音识别结果?

android - Cordova Android - 无法打开相机 - READ_EXTERNAL_STORAGE

javascript - Phonegap RSS 提要,Javascript

javascript - 使用 ionic 框架的 $cordova ImagePicker 插件时出现错误

Android 不获取 res/layout-land 中的布局文件