4

Seeing issue running Instant App in Android Studio when @string value is used for host name (getting "URL not defined in the manifest" error). For example:

<data android:scheme="https" android:host="@string/SOME_DOMAIN" />

This is working fine if android:host is set to raw domain string. I can work around this by setting that value to specific domain value when running/debugging from AS but not ideal (always danger of pushing code that contains the hard coded string!)

Also, this works fine if I build/deploy base and feature apks from command line and trigger using something like adb shell am start -W -a android.intent.action.VIEW -d "<my url>"

John O'Reilly
  • 10,000
  • 4
  • 41
  • 63
  • had tried that but no luck....looks like AS requires hard coded string in `android:host` – John O'Reilly Oct 21 '17 at 13:53
  • Note that this works if I build/run from command line.....it correctly interprets `@string/SOME_DOMAIN` ...issue is only if I run from AS – John O'Reilly Oct 21 '17 at 14:03
  • 2
    I've filed this at http://issuetracker.google.com/68084954 – dchai Oct 21 '17 at 22:41
  • 1
    @JohnO'Reilly Until this is fixed, depending on your needs you can consider using [manifest build variables](https://developer.android.com/studio/build/manifest-build-variables.html) instead. – Volo Oct 22 '17 at 18:09
  • @Idolon I see issue if I use manifest build variables instead. – John O'Reilly Oct 22 '17 at 19:20
  • @JohnO'Reilly what is the issue with manifest build variables? – Volo Oct 22 '17 at 19:26
  • @Idolon Same as original issue reported when I use `@string` resource – John O'Reilly Oct 22 '17 at 19:27
  • I cannot post comments right now, hence an aswer. Today, the bug of [comment](https://stackoverflow.com/questions/46863387/url-not-defined-in-the-manifest-when-running-instant-app-that-uses-string-for#comment80684795_46867821) that `` inside an `` does not support any string resources in Android Studio 3.1.3 on Ubuntu 18.04 still persists. – ManuelTS Jul 07 '18 at 14:57

3 Answers3

0

Maybe this is because it's not the main

Manifest.xml

, but the debug Manifest.. Try editing

app/src/main/Manifest

Note: host name matching in the Android framework is case-sensitive, unlike the formal RFC. As a result, you should always specify host names using lowercase letters.

Reference Android developer String Resources

Prags
  • 2,457
  • 2
  • 21
  • 38
0

The documentation is a bit unclear on whether android:host can contain a string resource, or just a simple string:

<data android:scheme="string"
      android:host="string"
      android:port="string"
      android:path="string"
      android:pathPattern="string"
      android:pathPrefix="string"
      android:mimeType="string" />

But according to Google employee @dchai:

String resources are supposed to be supported … This is a bug in Android Studio.

The bug in question has been fixed in Android Studio 3.2, so now it's possible to use string resource and manifest build variable as a value for data attributes.

Volo
  • 28,673
  • 12
  • 97
  • 125
  • String resources are supposed to be supported---Developer Console was updated to handle this case. This is a bug in Android Studio. – dchai Oct 21 '17 at 22:40
0

as alternative you can use manifestPlaceholders

<data android:scheme="https" android:host="${SOME_DOMAIN} />

in you build.gradle:

flavor {
   dimension "instant"
   manifestPlaceholders = [SOME_DOMAIN: "https://instantapp.example.com/"]
}
saroyama
  • 1
  • 1