HERE Android SDK Developer's Guide

Development Tips

This section provides tips on building your application using the HERE Android SDK.

Logging the HERE SDK Version

For troubleshooting purposes, we recommend that you add the HERE SDK version number in your application logs. You can get the SDK version by calling com.here.android.mpa.common.Version.getSdkVersion().

Upgrading from Older Versions of HERE SDK

The HERE Android SDK is now packaged as an Android archive (AAR) file instead of separate JAR, native library and proguard components. If you are upgrading from an older HERE SDK release, the old components should be cleaned up before integrating the AAR version of the HERE SDK. To do so, follow these steps:

  1. Ensure the HERE-sdk.jar file is removed from your project and the compile entry is removed from your build.gradle file. The JAR may be located at app/libs/HERE-sdk.jar and included in your build.gradle file one of the following:
    compile files('libs/HERE-sdk.jar')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    Note that if you were previously using the Google GSON library with the HERE SDK, it is still required to be included separately.
  2. Remove the HERE SDK proguard file and the proguard entry specific to the HERE SDK from the build.gradle file. The file to remove is named proguard-here-sdk.txt, and the entry of the same name should also be removed from the proguardFiles property in your build.gradle file. The proguard instructions for newer versions of the HERE SDK are now applied automatically and are included in the AAR.
  3. Ensure all HERE SDK related native libraries are removed from your project. These files are now a part of the AAR file and do not need to be included separately. To locate these native libraries, check the app/src/main/jniLibs/armeabi-v7a folder in your project. If you are not using other standalone native libraries in your project, you can delete the entire armeabi-v7a folder. A list of the HERE SDK native libraries, as of SDK release 3.2.2, is:
  • libCertResourcesPkg.so
  • libcrypto_here.so
  • libgnustl_shared.so
  • libLohitIndicFontPkg.so
  • libMapsEngineResourcePkg.so
  • libMAPSJNI.so
  • libNanumGothicFontPkg.so
  • libNlpResourcePkg.so
  • libos_adaptation.context.so
  • libos_adaptation.network.so
  • libposclient.so
  • libPositioningResourcePkg.so
  • libPureArabicFontPkg.so
  • libPureChineseFontPkg.so
  • libPureIndicSouthFontPkg.so
  • libPureThaiFontPkg.so
  • libSdkResourcePkg.so
  • libssl_here.so

You can find further info on integrating the AAR version of the HERE SDK into your app in the Running the Sample Application section of the User Guide and the associated HERE-sdk/tutorial/BasicMapSolution/app/build.gradle file.

Troubleshooting SDK Initialization Errors

If you receive OnEngineInitListener.FILE_RW_ERROR or OnEngineInitListener.UNKNOWN when trying to initialize the SDK, it can be due to file system corruption or resource locking on the device. You can usually resolve this issue by restarting the device. If this is not practical, another option is to set a new isolated disk cache location using the method outlined in Using an Isolated Map Disk Cache with the Map Service.

If your app users are encountering this issue frequently, check whether your intended disk cache location is writable using standard Java APIs before setting it for the HERE SDK. If the location is not writable, set it to a different location which is writable.

Updating Map Data Without Using MapLoader

You can use the MapLoader to check and perform map data updates. However, if your application does not use MapLoader, you can periodically update map data by deleting the application map data cache located at the following location:
/sdcard/.here-maps/diskcache-v5/BundleStore
Deleting this cache forces the HERE SDK to download the latest map data.

"Disk Cleaner" Applications

Third-party memory cleaner apps may randomly delete files that are required by the HERE SDK. These apps may cause problems such as:
  • Deletion of the SSL certificates, causing network connections and map data downloads to fail
  • Unintended deletion of the map data cache
It is recommended for users to disable these types of apps while using an app that uses the HERE SDK.

Lapsed Listeners and Garbage Collection

The HERE SDK provides a number of listener interfaces, such as Map.OnSchemeChangedListener, Map.OnTransformListener, and MapGesture.OnGestureListener. To use these listeners, you are required to implement and create a listener instance, then register it with another object (using a method such as addSchemeChangedListener()) to receive event notifications. Unfortunately, this coding pattern can also lead to the lapsed listener problem, where available memory is consumed by listener objects that are not explicitly unregistered and not garbage collected.

To mitigate this problem, the HERE SDK, in some cases, accepts listener objects in WeakReference containers. This has the advantage of avoiding lapsed listeners, but it also means that you must be aware of registered listeners becoming garbage collected. To avoid any unintended issues with this coding pattern, be sure to retain a strong reference to your listener instances (for example, by assigning it to a class variable) if you would like to manage its garbage collection lifecycle. Listener objects are not garbage collected as long as a strong reference exists.

Working with Getters

Classes in the HERE SDK return copies of objects in its getters. For example, MapPolyline.getPolyline() does not return the same GeoPolyline instance that was used to construct the MapPolyline object; instead, a copy of the GeoPolyline is returned. Since this returned object is a copy, you cannot dynamically modify the MapPolyline instance by modifying this object. If you would like to make changes to MapPolyline, you must call setGeoPolyline(GeoPolyline) instead.

Map Object Limitations

The HERE SDK does not limit the number of map markers, polygons, and polylines that can be added to a map. However, rendering a large number of map objects can cause performance degradation in your application. It is recommended that you use techniques such as viewport clipping and marker clustering to avoid these issues.

Rendering Issue with Extruded Buildings

Devices using the MediaTek MT65XX or PowerVR SGX 5*MP* chipset family have a known GPU shader error where the rendering of extruded buildings causes flickers of random colors. It is advised to turn off extruded building rendering on these devices. For example:

private OnMapRenderListener m_renderListener = new OnMapRenderListener() {
  @Override
  public void onPreDraw() {
    String renderer = GLES20.glGetString(GLES20.GL_RENDERER);

    if(renderer.contains("PowerVR SGX 544MP"))
    {
      map.setExtrudedBuildingsVisible(false);
    }
  }
  @Override
  public void onPostDraw(boolean invalidated, long renderTime) {
  }
  @Override
  public void onSizeChanged(int width, int height) {
  }
  @Override
  public void onGraphicsDetached() {
  }
};

For more information, see the Map.setExtrudedBuildingsVisible(boolean) API Reference.

Doze and App Standby

If you are using Android 6.0 (API level 23) or above, be aware that the Doze and App Standby features may impact your HERE SDK app by disabling network access when the device is unplugged, stationary, and has the screen off for a period of time. While the HERE Android SDK has the ability to work offline, you should design your app with these operating system features in mind.

For more information about Doze and App Standby, including how to use notifications and whitelisting to ensure your app functions properly, see the Android article, "Optimizing for Doze and App Standby".

Native Libraries and ABI Splits

Your app may encounter an error if it also includes other dependencies that have unsupported ABIs. To get around this issue, enable ABI splits to only build for the armeabi-v7a architecture explicitly by modifying your app's build.gradle file:

android {
  (...)
  splits {
    abi {
      enable true
      reset()
      include 'armeabi-v7a'
      universalApk false
    }
  }
  (...)
}

For more information about the splits Gradle block, see Configure multiple APKs for ABIs in the Android Studio User Guide.