I am implementing Map Kit on my Android app. After following the official documentation on installing the HMS Core SDK, I have:
- Enabled Map Kit, Location Kit and Site Kit on AppGallery Connect.
- Added agconnect-services.json
- Encoded my API key using
URLEncoder
andutf-8
. - Copied my SHA-256 certificate fingerprints for my release version AND debug version (using different keystore entries).
- Asked for location permission.
- Setting my API key on MapsInitializer before it's loaded.
In summary, my code looks like this:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
try {
API_KEY = URLEncoder.encode(
getString(R.string.api_key),
"utf-8"
)
MapsInitializer.setApiKey(API_KEY)
} catch (ignored: UnsupportedEncodingException) {
}
binding = ActivityMapBinding.inflate(layoutInflater)
setContentView(binding.root)
viewModel = ViewModelProvider(
this,
MapViewModel.MyViewModelFactory(application)
)[MapViewModel::class.java]
var mapViewBundle: Bundle? = null
if (savedInstanceState != null) {
mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY)
}
mMapView = binding.mapView
mMapView.onCreate(mapViewBundle)
mMapView.getMapAsync(this)
siteInfo = binding.siteInfo
siteInfo.visibility = View.GONE
// ...
}
But all I get when entering the activity is the blue point of my location over a blank map and a Toast
saying REQUEST_DENIED
.
Checking the logs, there seems not to be an API authentication or signing error, but most likely Petal Maps API being down:
E/HmsMapKit_ErrorTraceLogPusher_4: cache error trace log : ErrorTraceLogDTO{ scenario = ACCESS_SERVICE_ERROR', message='060001 : NETWORK_ERROR'}
com.huawei.hms.maps.foundation.client.mac: *e*v*r*A*d*e*s*f*o* *R* *s*e*p*y*
at com.huawei.hms.maps.foundation.client.mac$maa.b(Unknown Source:25)
This is disturbing, because there's no sign of this error code in the official Map Kit error codes documentation. Does anyone know what's going on? Thanks in advance!
Solved it! Here's my config:
HMS Core: latest version as of 14/03/2022 (6.4.0.306)
Map Kit: latest version as of 14/03/2022 (
implementation 'com.huawei.hms:maps:6.3.1.300'
)Main cause: my app signing configuration was missing in my
build.gradle
file.Steps to solve it:
Deleted my existing keystore (.jks). DISCLAIMER: you will lose the capacity to update your app if it's released in AppGallery. Please do it as a last resort.
Created a new keystore INSIDE my Android Studio project, under the
app
directory.Generated a signed APK for
release
and obtained the SHA-256 fingerprint.Replaced my former fingerprint with the new one in AppGallery Connect.
In my map activity, DIDN'T encode my API key (thanks shirley!)
Rebuilt my project.
Complete instructions are here.