DEVELOPERS BLOG

Debugging Google Maps with Secure Work Space

google_maps

While many users may not initially consider Google Maps to be an enterprise application, it’s actually one of the more useful apps in Google Play for businesses, small and large alike, to leverage for a variety of use cases. Enterprises can use Google Maps to calculate mileage, determine the shortest distance to a job site, or even find an alternative route during a traffic jam.

Developers can even include an instance of Google Maps within their own application, which is called a MapView.

Recently within our Enterprise Solutions group, we have been working with a customer to assist them in their app deployment over BES12. During our engagement with their development team, an issue was brought to our attention regarding MapViews not loading any content, after their app was secured for deployment using the Secure Work Space solution for BES12.

We were able to confirm the developers’ findings, and wanted to share the experience with our BlackBerry Developer Community on how to properly take advantage of Google Maps within your own SWS environment.

Using Google Maps Android API

Google Maps are really easy to integrate when it comes to developing Android apps.  There are just a few steps to implement it properly, as documented within the Google Maps Introduction Guide.

  1. We need to register for a developer key, specific to the package name of our application. We can register for a key within the Google Developer Console.
  2. After we register for the key we need to put add the following code within an xml file.
    1
    2
    3
    4
    5
    <resources>
        <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
           ------ Your Key here -----------
        </string>
    </resources>
  3. Next step is to update the values in AndroidManifest file.
    1
    2
    3
    <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="@string/google_maps_key" />

Alternatively, we can choose the MapActivity option while creating a new activity and Android Studio will automatically add all the dependencies.

This will work only if you have Google Play Services present on your Android device. In the event that Goggle Play Services are not available (BlackBerry Runtime for Android apps, Amazon devices), it will show an error message as shown below.

google_services

Using your Google Maps application with Secure Work Space

As mentioned, while working with a customer’s development team, it was brought to our attention that while end-users were not being prompted with the same Google Play Services error message seen above, MapViews were not loading their content as expected.

Defect details:

  1. The application works as expected in the personal partition of the device (SWS is a secure container solution).
  2. After securing the APK file on the BES for deployment over SWS, MapViews were not being loaded as shown below.
  3. The initial assumption was that Google Play Services may not be available within SWS, due to its nature of being a secure container.

google_blank_page

Initial Investigation and issue reproduction

As a first step, we made a sample application to verify that Google Play Services were available within the SWS container. You can access our sample application here.

After running the aforementioned sample, we were able to conclude that SWS indeed supports Google Play Services. However, we were still being greeted with a white screen when attempting to load a MapView.

So, what should we do now?

Log Analysis

As our second step in root cause analysis, we referenced the associated logs when we launched the application within SWS.

Within these logs, we were able to notice that the package name of our application was throwing an error with respect to Google Maps failing to load our MapView.

This brought to light the fact that upon securing an app for deployment to SWS, that the BES actually appends “.SEC_APP” to the original package name. (com.blackberry.example -> com.blackberry.example.SEC_APP).

So, while requesting a particular MapView from the Google server does not recognize this new SEC_APP package name since we had only registered our original package name to use the required Google Maps API key.

What do we need to do now?

Since the Google Maps server will not recognize the appended package name, we’ll need to also add an additional Google Maps API Key for the new package name so that our application will work within an SWS environment.

google_map_api_key

This should work now. We had signed the application and deployed it from our BES12 test server. As soon as we launch the application though, we saw the white screen again!

So, what could be the problem now? Logs came to rescue again:

blackberry.googleplayservicestest E/b Authentication failed on the server.
blackberry.googleplayservicestest E/Google Maps Android API Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
blackberry.googleplayservicestest E/Google Maps Android API In the Google Developer Console (https://console.developers.google.com)
   Ensure that the “Google Maps Android API v2” is enabled.
   Ensure that the following Android Key exists:
   API Key:
   Android Application (<cert_fingerprint>;<package_name>):

The one piece that was missed was that when we generate a signed APK file for release, that the generated key should also be updated within the release directory of our project as well.

Example: GooglePlayServicesTestappsrcrelease esvaluegoogle_maps_api.xml

After making this final change, we were able to secure and sign the sample app once again, and after deploying the app to our test lab/devices, the content within our MapView was being loaded as expected without issue. Voila!

About narulasanam