LivePersonInc / developer-center

LivePerson’s Developer Center and Community
https://developers.liveperson.com/
31 stars 199 forks source link

Android SDK: LP attempts to replace my google maps API key in manifest merger #156

Closed bramley-turner-stride closed 6 years ago

bramley-turner-stride commented 6 years ago

I get the following error:

Error:Execution failed for task ':app:processAppThemeDebugManifest'.
> Manifest merger failed : Attribute meta-data#com.google.android.maps.v2.API_KEY@value value=(AIzaxxxxxxxxxxxxxxxxxuA) from AndroidManifest.xml:282:6-61
    is also present at [:messaging_ui:] AndroidManifest.xml:45:13-55 value=(@string/lp_google_maps_key).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:280:10-282:63 to override.

This is because I explicitly include my Google Maps API key in my app's manifest (I use maps for other purposes unrelated to LP in my app).

The messaging_ui.aar lib declares it's own maps API key in its manifest:

 <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/lp_google_maps_key" />

@string/lp_google_maps_key is empty, by the way.

While for me, the solution is simple (add tools:replace as the error message suggests), other consumers of this library could have much worse problems: -The google-services plugin, which applies the settings in the google-services.json file, is overrridden by the values in messaging_ui, without warning or error. This is true even for your own sample app. I have added some code to demonstrate the API key is empty in my fork of the sample. See here: https://github.com/bramley-turner-stride/Android-Messaging-SDK/commit/1093f881479750d8b694f4d76e7b9b9c754c1b58 . Run the app, and look at the footer text. It will show Maps API key: '' (empty string) -Consumers of this lib may be using the newer com.google.android.geo.API_KEY geo key instead. I'm not sure how the maps SDK handles having two conflicting API keys present in the manifest.

bramley-turner-stride commented 6 years ago

Correction: the google-services plugin does not write maps/geo api key to manifest.

If consumers of the LP lib are defining the newer com.google.android.geo.API_KEY key in their manifest, they will get this error when you try to open a map:

java.lang.RuntimeException: Unable to start activity ComponentInfo{au.com.myapp.dev/au.com.myapp.activity.MapPickerActivity}: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class fragment
...
 Caused by: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.geo.API_KEY in the <application> element of AndroidManifest.xml
dvillacis94 commented 6 years ago

Hi @bramley-turner-stride,

We're looking into this one.

dvillacis94 commented 6 years ago

Hi @bramley-turner-stride,

After reviewing this one, your assumptions are correct, as you can only have one API Key, and the correct place to put it would either int the AndroidManifest.xml or the google_maps_api.xml, we're checking with our R&D the possibility of changing this integration to follow Google Implementation.

The workaround for now would be to remove the API Key from both the AndroidManifest and the google_maps_api file, and include that one as a String under values/strings using the <string name="lp_google_maps_key">API_KEY</string> tag, that would let you use it without the crash.

dvillacis94 commented 6 years ago

Hi @bramley-turner-stride .

I'm closing this issue, if you have any more questions related to this feel free to reopen it, or create a new one for any new issues.

We're working on a new way to handle Google Maps Key.