4

I tried following the instructions in the official codelab Here's a link to the corresponding source code: https://github.com/huaweicodelabs/MapKit

What I did:

  • Modified the packagename(AppGallery Connect portal doesn't allow apps with package-names that have already been claimed by someone else for their app)
  • Created a keystore file for signing (Used the Build->'Generate signed APK' flow to create it)
  • updated the attributes inside signingConfigs{release{...}} section with:
storeFile file("/Users/myuser/mydir/mykeystorexyz") // no .jks extension as it's unimportant
storePassword "mypass123"
keyAlias "mykeystorexyz" //I had kept the name and alias of the file to be same
keyPassword "mypass123"
v2SigningEnabled true
  • Created a Project and App on Huawei Appgallery Connect with the new packagename. Also Enabled the Mapkit API from the user interface.
  • Downloaded agconnect-services.json inside the app directory of the project
  • Copied the long API key inside agconnect-services.json and passed it as a parameter to MapsInitializer.setApiKey() inside MainActivity.java.
  • Used the keytool -list -v -keystore /Users/myuser/mydir/mykeystorexyz command to get keystore information and copied the SHA256 fingerprint. Pasted this fingerprint inside the App Information section on the 'AppGallery Connect' portal.
  • I then installed and ran the debug APK on my Pixel 5A(Android 12) device with latest version of HMS Core installed(I tried version 6.6.0.331 from APKMirror). Map did not get displayed and I could see a very high number of errors on Logcat. Hence I decided to increment library versions and started using com.huawei.hms:maps:6.5.1.300 and com.huawei.agconnect:agcp:1.6.0.300. This greatly reduced the number of runtime errors but the map would still not get displayed and I would see the following error message inside Logcat:
E/HmsMapKit_MapView_15: MapsInitializer is not initialized.
E/HmsMapKit_MapView_8: MapsInitializer is not initialized.

I'm not sure about what's going wrong in this case. Why is the MapsInitializer not being initialized ?

Is there a mismatch between the versions of the core HMS SDK and the MapKit SDK I'm using ?

I tried running the APK on a Huawei Cloud Device but got the same results.

Can anybody point any possible causes of this error ? I wasn't expecting to run into any issues since I made minimal changes to the source code of the official code lab.

Edit: I went through the documentation and realized that MapsInitializer.initialize(this); needs to be added before the call to MapsInitializer.setApiKey() for newer versions of HMS Map Kit. This got rid of the MapsInitializer is not initialized error but the map is still not getting displayed.

Now, whenever I run the app I end up seeing a prompt to update HMS core to the latest version. The update always fails with the following message: Unable to update at the moment. Please try again later (Error 102)

I figured that it may be an issue with my Google Pixel 5A phone running on Android 12 and hence attempted to upload the App's APK to the Mobile Cloud Debugging Console which has Huawei-supported Android devices. I made 2 different attempts. First, I tried uploading the APK using the Appgallery Connect's UI interface and running the APK there - however the same error message would show up (I was able to verify that a version of HMS Core was pre-installed on these devices). I also tried cloud debugging using the HMS Core plugin for Android Studio - but that service seems to be down.

Attempt to update HMS Core always fails

Unable to connect to devices using Cloud Debugging

Umang Mathur
  • 833
  • 1
  • 10
  • 32
  • Could you please share the full log obtained when the issues occurred ? also It would be nice if you could provide us with your test apk for check. You can send your apk to hmscore@huawei.com. – zhangxaochen Aug 08 '22 at 02:50
  • Same comment as above. Please share more log info/apk if possible. – Zinna Aug 08 '22 at 18:31
  • As per my observation, this behavior depends on device. I did observe both normal behavior and your behavior inside Cloud Debugging env - which I think you're using, as per screenshot. – ror Apr 11 '23 at 17:51
  • Any update here? – Enes Zor Aug 01 '23 at 10:57

1 Answers1

0

I had the same problem with Huawei MapKit and solved it by adding apiKey using AGConnectOptionsBuilder. You need to add it and MapsInitializer.setApiKey() before initialize() call function as I show below

    val apiKey = AGConnectOptionsBuilder().build(this).getString("client/api_key")

    MapsInitializer.setApiKey(apiKey)
    MapsInitializer.initialize(applicationContext)
    mMapView.onCreate(mapViewBundle)
    mMapView.getMapAsync(this)

It's the only I added to official source code and now it works to me