【问题标题】:How is android.json created in my Cordova app?如何在我的 Cordova 应用程序中创建 android.json?
【发布时间】:2018-06-22 07:13:16
【问题描述】:

所以我有一个使用 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 是如何构建的?编辑该文件是正确的做法,还是从中提取了一些我应该编辑的东西?

【问题讨论】:

    标签: android cordova cordova-plugins deep-linking


    【解决方案1】:

    很久没发这个了,但我也遇到了同样的问题,这是我的解决方法。

    如果您进入 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' 挂钩?)但这是我快速而肮脏的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 2022-10-01
      • 2011-02-08
      相关资源
      最近更新 更多