How is android.json created in my Cordova app?
Asked Answered
B

1

10

So I have a iOS/Android Ionic Cordova app that uses the ionic-plugin-deeplinks plugin. The plugin wasn't working when the AndroidManifest.xml had this in it:

<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>

but when I put this in its place it worked fine:

<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>

However, whenever I ionic prepare if would overwrite my fix back to the original non-functioning way. I tried to change somethings in the parent level config.xml for cordova as well as the plugin.xml parent/plugins/ionic-plugin-deeplinks folder and it would still be overwrite to the original broken way. Then I went in parent/platforms/android/android.json and changed where it wrote the original version to be my version and it consistently builds fine.

So I'm happy that it works but my question is why does it work? How is android.json built? Is editing that file the correct thing to do or is there something that it pulls from that I should edit instead?

Britton answered 12/1, 2018 at 19:22 Comment(0)
S
0

Long time since this was posted, but I was having the same problem, here is how I fixed it.

If you go into the plugins plugin.xml file you can see that it does this...

        <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>

If you look a bit higher up in that file it is setting all these variables to be either blank or '/'.

This is what sets the android.json and then in turn the AndroidManifest.xml.

To resolve the fact that this was screwing with the deep linking I put the following in my config.xml to overwrite these 'default' settings. It's probably worth mentioning that the below was placed on the same level as the tags such that it wasn't actually inside either of them.

    <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>

I'm new to Cordova, so I'm sure there is a better way to do this (perhaps with 'after' hooks?) but this was my quick and dirty solution.

Skyward answered 29/8, 2021 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.