HMS Map toolkit - onMapReady() not called after getMapAsync() calling

628 Views Asked by At

I am working with HMS Maps, for this I follow their documentation.
For this query I tried this link. I added SHA-256 key and agconnect-services.json file too.
The Steps which I did are:

dependency in app gradle: implementation 'com.huawei.hms:maps:6.0.0.301'
in app gradle: apply plugin: 'com.huawei.agconnect'
My root gradle is:

buildscript {
    repositories {
        maven { url 'http://developer.huawei.com/repo/' }
        google()
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.huawei.agconnect:agcp:1.2.1.301'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {url 'http://developer.huawei.com/repo/'}
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://jitpack.io'
        }

        maven {
            url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
        }

    }
}

I added SHA-256 key at AppGallery connect.
Enabled MapApi from AppGallery connect.
Downloaded and added "agconnect-services.json" file in my project.

After resolving some thread related issues, I am able to produce logcat errors and it is saying that "Illegal FingerPrint".
I know, it is about some integration issues with the AppGallery but I am unable to get it that what I am missing, I am following all the steps.
**Logcat is:**
2021-08-31 10:35:22.520 30490-30773/com.moody.poster E/HmsMapKit_AuthenticateClient_1074: Exception occur
    com.huawei.hms.maps.foundation.client.d: *1*0*2*:*I*L*G*L*F*N*E*P*I*T
        at com.huawei.hms.maps.foundation.client.d$d.c(:89)
        at com.huawei.hms.maps.foundation.client.c.d(:22556)
        at com.huawei.hms.maps.foundation.client.c.c(:88)
        at com.huawei.hms.maps.maproute.client.auth.e.d(:76)
        at com.huawei.hms.maps.maproute.client.auth.e.a(Unknown Source:0)
        at com.huawei.hms.maps.maproute.client.auth.b.a(Unknown Source:4)
        at com.huawei.hms.maps.foundation.client.c$a.e(:492)
        at com.huawei.hms.maps.maproute.client.auth.e.c(:1074)
        at com.huawei.hms.maps.maproute.cache.c$b.e(:298)
        at com.huawei.hms.maps.maproute.cache.c$b.call(:291)
        at eU.a(:42)
        at em.d(:12025)
        at fc$b.run(:96)
        at eq$c.run(:571)
        at fj.run(:66)
        at fj.call(:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2021-08-31 10:35:22.528 30490-30773/com.moody.poster E/HmsMapKit_ErrorTraceLogPusher_509: cache error trace log : ErrorTraceLogDTO{ scenario = ACCESS_SERVICE_ERROR', message='010002 : ILLEGAL_FINGERPRINT'}
    com.huawei.hms.maps.foundation.client.d: *1*0*2*:*I*L*G*L*F*N*E*P*I*T
        at com.huawei.hms.maps.foundation.client.d$d.c(:89)
        at com.huawei.hms.maps.foundation.client.c.d(:22556)
        at com.huawei.hms.maps.foundation.client.c.c(:88)
        at com.huawei.hms.maps.maproute.client.auth.e.d(:76)
        at com.huawei.hms.maps.maproute.client.auth.e.a(Unknown Source:0)
        at com.huawei.hms.maps.maproute.client.auth.b.a(Unknown Source:4)
        at com.huawei.hms.maps.foundation.client.c$a.e(:492)
        at com.huawei.hms.maps.maproute.client.auth.e.c(:1074)
        at com.huawei.hms.maps.maproute.cache.c$b.e(:298)
        at com.huawei.hms.maps.maproute.cache.c$b.call(:291)
        at eU.a(:42)
        at em.d(:12025)
        at fc$b.run(:96)
        at eq$c.run(:571)
        at fj.run(:66)
        at fj.call(:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2021-08-31 10:35:22.536 30490-30773/com.moody.poster E/HmsMapKit_AuthenticateCache_333: other err occur,errorCode : .010002 : ILLEGAL_FINGERPRINT
2021-08-31 10:35:22.775 30490-30490/com.moody.poster E/HmsMapKit_AccessTraceLogPusher_16: analyticsInstance is null
2021-08-31 10:35:22.778 30490-30490/com.moody.poster E/HmsMapKit_UserEventLogPusher_16: analyticsInstance is null


3

There are 3 best solutions below

0
On BEST ANSWER

I am not sure that why it is happening, I talked to Huawei developers regarding this issue, I was doing this in a fragment but when I tried this in an activity, it works perfectly. Now I am doing it in a separate Activity. (I created that activity with the built in method of HMS toolkit.)

1
On

I had a similar problem once when I was implementing HMS Map. In my case it was that I had the map on a fragment and was using the activity documentation. To fix it I had to use the SupportMapFragment and everything worked correctly after that.

8
On

Update

In your following log:

2021-08-31 10:35:22.528 30490-30773/com.moody.poster E/HmsMapKit_ErrorTraceLogPusher_509: cache error trace log : ErrorTraceLogDTO{ scenario = ACCESS_SERVICE_ERROR', message='010002 : ILLEGAL_FINGERPRINT'}

As Docs mentioned, The possible causes are as follows:

  • The app ID in your project is different from that in AppGallery Connect.

  • No signing certificate fingerprint is configured. You need to generate a signing certificate fingerprint and configure it in AppGallery Connect.

  • The AppGallery Connect configuration file of your app is not configured. You need to follow instructions in Adding the AppGallery Connect Configuration File of Your App to configure it.

  • The API key is not transcoded using encode.

Also you can follow this Docs: Generating a Signing Certificate Fingerprint, see if there's a problem.


The following Map kit codelab is for your reference. You could follow this to see if its works.

1.Declare relevant permissions in blocks at the same level as the application block in the AndroidManifest.xml file.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

2.Add MapView to the layout file. The file path is \mapdemo\app\src\main\res\layout\activity_main.xml.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    
    <com.huawei.hms.maps.MapView  
       xmlns:map="http://schemas.android.com/apk/res-auto" 
        android:id="@+id/mapView" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        map:cameraTargetLat="51" 
        map:cameraTargetLng="10" 
        map:cameraZoom="8.5" 
        map:mapType="normal" 
        map:uiCompass="true" 
        map:uiZoomControls="true" /> 
</LinearLayout>

3.Add the configuration for calling MapView to the activity file. The file path is \mapdemo\app\src\main\java\com\wz\android\mapdemo\MainActivity.java.

package com.wz.android.mapdemo; 
 
import androidx.appcompat.app.AppCompatActivity; 
 
import android.os.Bundle; 
import android.util.Log; 
 
import com.huawei.hms.maps.HuaweiMap; 
import com.huawei.hms.maps.MapView; 
import com.huawei.hms.maps.OnMapReadyCallback; 
 
/** 
* Map activity entrance class. 
*/ 
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback { 
 
    private static final String TAG = "MapViewDemoActivity"; 
    // Huawei map. 
    private HuaweiMap hMap; 
 
    private MapView mMapView; 
 
    private static final String MAPVIEW_BUNDLE_KEY = "MapViewBundleKey"; 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        // Obtain a MapView instance. 
        mMapView = findViewById(R.id.mapView); 
        Bundle mapViewBundle = null; 
        if (savedInstanceState != null) { 
            mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY); 
        } 
 
        // Please replace Your API key with the API key in  
        // agconnect-services.json. 
        MapsInitializer.setApiKey("Your API key"); 
        mMapView.onCreate(mapViewBundle); 
        // Obtain a map instance. 
        mMapView.getMapAsync(this); 
    } 
 
    @Override 
    public void onMapReady(HuaweiMap map) { 
        // Obtain a map instance from callback. 
        Log.d(TAG, "onMapReady: "); 
        hMap = map; 
    } 
}

4.Add the lifecycle methods of MapView. The file path is \mapdemo\app\src\main\java\com\wz\android\mapdemo\MainActivity.java.

@Override 
protected void onStart() { 
    super.onStart(); 
    mMapView.onStart(); 
} 
 
@Override 
protected void onStop() { 
    super.onStop(); 
    mMapView.onStop(); 
} 
 
@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    mMapView.onDestroy(); 
} 
 
@Override 
protected void onPause() { 
    mMapView.onPause(); 
    super.onPause(); 
} 
 
@Override 
protected void onResume() { 
    super.onResume(); 
    mMapView.onResume(); 
}

5.Verify that required permissions have been assigned. The file path is \mapdemo\app\src\main\java\com\wz\android\mapdemo\MainActivity.java.

private static boolean hasPermissions(Context context, String... permissions) { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) { 
        for (String permission : permissions) { 
            if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { 
                return false; 
            } 
        } 
    } 
    return true; 
}