Skip to content
Advertisement

HMS NoClassDefFoundError Android

I’m using HMS plugin for Android Studio.

I have a class called MyFirebaseMessagingService which receives notifications from Firebase.

it used to be like :

JavaScript

after conversion:

JavaScript

After converting the code, I had the following problem :

JavaScript

I found a suggested solution in Huawei support, but it didn’t work!

(Handle the exception) link : https://developer.huawei.com/consumer/en/doc/development/Tools-Guides/map-conversion-0000001050062227

Suggested solution :

Add the following configuration to app/build.gradle:

JavaScript

btw I already clean and rebuild the project. Also, I tried to restart and invalidate.

app/build.gradle. Before conversion:

JavaScript

build.gradle (:xmsadapter),. After conversion:

JavaScript

stack trace :

JavaScript

Advertisement

Answer

After trying almost everything I solved the problem. In order to help as many people as possible, I will write the steps you need to follow to get HMS map working :

  1. Create Huawei developer account: https://id5.cloud.huawei.com/CAS/portal/userRegister/regbyemail.html

  2. Create a project and an app in Huawei Developer console, then get agconnect-service.json (After downloading make sure it is .json) file: https://developer.huawei.com/consumer/cn/service/josp/agc/index.html#/

you can watch this video to help you: https://www.youtube.com/watch?v=BQbFlP4gRN8&t=1s

  1. Download and install HMS converter plugin from Android Market place. The plugin will ask you to restart Android Studio.

  2. Before converting the project make sure to create a backup locally or on Github.

  3. The following video will help you understand how to convert google APIs. Important note: @5:50 in the video the instructor will choose "To HMS API", You need to select "Add HMS API (GMS API First)". Also, @6:53 in the video the instructor will click on automatic convert for all files. From a Personal Experience, it is better to convert files one by one manually. Actually, auto-convert is the cause of the issue I encountered! https://www.youtube.com/watch?v=1b1Ap5xQHm4&t=357s

  4. Make sure HMS converter added the following lines to your build:gradle/Project:

    JavaScript
  5. Make sure HMS converter added the following lines to your build:gradle/App:

    JavaScript
  6. Make sure HMS converter added the following lines to your Settings.gradle:

    JavaScript
  7. Add the following rules to proguard-rules.pro in case minifyEnabled is true:

    JavaScript
  8. Clean then Rebuild the project, you may need to “restart and invalidate” Android studio.

  9. you can check this github project as a reference: https://github.com/AlineJo/AdapterMap

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement