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

Roz*_*nyi 7 android deep-linking cordova cordova-plugins

所以我有一个使用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>
Run Code Online (Sandbox Code Playgroud)

但当我把它放在它的位置它工作正常:

<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>
Run Code Online (Sandbox Code Playgroud)

但是,每当我ionic prepare将覆盖我的修复回到原来的无功能方式.我试图在config.xmlcordova和plugin.xml parent/plugins/ionic-plugin-deeplinks文件夹的父级别中更改某些东西,它仍然会覆盖原始的破碎方式.然后我进去parent/platforms/android/android.json并改变了原始版本编写的地方作为我的版本,它一直很好.

所以我很高兴它有效,但我的问题是为什么它有效?怎么android.json建?编辑该文件是正确的事情还是有什么东西从我应该编辑而不是?

小智 0

这篇文章发布已经很久了,但我也遇到了同样的问题,以下是我解决它的方法。

如果您进入插件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>
Run Code Online (Sandbox Code Playgroud)

如果您在该文件中查看更高一点,则会将所有这些变量设置为空白或“/”。

这就是设置 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>
Run Code Online (Sandbox Code Playgroud)

我是 Cordova 的新手,所以我确信有更好的方法来做到这一点(也许使用“after”钩子?),但这是我快速而肮脏的解决方案。