abusuioc / hms-gms-wrapper-location

Location wrapper on top of HMS and GMS.
MIT License
11 stars 4 forks source link

The debug version of apk runs, while the release version of apk hangs up. #2

Closed kust-wulin closed 4 years ago

kust-wulin commented 4 years ago

I cannot pinpoint what went wrong this time. My debug version of apk can run correctly, but the released version of apk just hangs up. No error message, never return. What files are you needed to help me to fix this issue?

abusuioc commented 4 years ago

@kust-wulin if it's production code, so I assume you cannot debug, could you add a couple of Log.i to understand what's going on in the code you're running and where the glitch happens? Otherwise, there are so many variables and I cannot give you a precise answer to your issue.

kust-wulin commented 4 years ago

@abusuioc thanks for the feedback. I can pinpoint the error now. In my code, I have a line of code: LocationData position = await _location.getLocation(); In debug version of the code, this call return position. However, in release version of the code, this call immediately throws an exception. PlatformException(UNEXPECTED_ERROR, -5:Core error, null) My cellphone is a Huawei's phone.

Do you know why I got this exception?

kust-wulin commented 4 years ago

I have checked the source code of location and changed the error message to find which line throws this exception. The line throws this exception is: FlutterLocation.java:417 sendError("UNEXPECTED_ERROR", e.getMessage(), null);

Since the debug version of the code works, I expect the release version will return the location instead of throwing an exception. In simulator, the code runs without error. My location version is 3.0.2

I have tested on:

Android 9, API Level 28, real device

kust-wulin commented 4 years ago

@abusuioc I have found the following two links that may solve my issue. https://stackoverflow.com/questions/63280882/flutter-hms-core-plugin-integration-error https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/configuration-obfuscation-script

I have checked the source code. I found file proguard-rules.pro is located at hms-gms-wrapper-location-1.0-beta-1\lib Does this mean I have to compile all the source codes by myself? Or you will update the hms-gms-wrapper-location-1.0-beta-1 and provide a new version which excludes hms from obfuscate.

Thanks a lot. Have a nice day.

kust-wulin commented 4 years ago

@abusuioc Thanks a lot for your sincere help. Now I have solved the issue. My solution is:

  1. Add the following lines in my build.gradle file at directory "project_home/android/app" buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }
  2. Add a text file named proguard-rules.pro in the same directory
  3. Inside proguard-rules.pro add the following lines -ignorewarnings -keepattributes Annotation -keepattributes Exceptions -keepattributes InnerClasses -keepattributes Signature -keepattributes SourceFile,LineNumberTable -keep class com.hianalytics.android.{*;} -keep class com.huawei.updatesdk.*{;} -keep class com.huawei.hms.{*;}

My project is created by Android Studio. So I guess my solution works for all Android Studio users. You may want to update your README.md, so that people using your library will not meet this issue again.

Thanks a lot again. Have a nice day.

abusuioc commented 4 years ago

@kust-wulin thanks a lot for your persistence in figuring out what the issue was.

Please try the 1.0-beta-2 ( implementation 'com.github.abusuioc:hms-gms-wrapper-location:1.0-beta-2' ). The issue is now fixed in the library and there is no need for you to modify your app code with the obfuscation configuration.

kust-wulin commented 4 years ago

@abusuioc Thanks. I should thank you for providing us a wonderful solution for the hms and gms issue. This solution helps us a lot. Contributing to it is our duty for using it.