Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get record when it's in production #12

Open
kevinrisqi opened this issue May 30, 2023 · 5 comments
Open

can't get record when it's in production #12

kevinrisqi opened this issue May 30, 2023 · 5 comments

Comments

@kevinrisqi
Copy link

When the build apk (release) package has an error, after tracing it turns out that the error appears from the package used.

However, when the package was in debug (pre-release) mode, there were no errors, it turns out that there are methods that are asynchronous. Our assumption is that when in release mode, packages cannot handle data asynchronously.
The point is, if you haven't built the apk package, you can use it without any errors

Screenshot_2023-05-15-09-10-03-472_asia yoayo yoayo

@vaidotasstrazdas
Copy link

vaidotasstrazdas commented Jun 11, 2023

Yes, this package actually can not be used in the production. Basically, the reason for this lies here:
https://github.com/duynguyen242/flutter_health_connect/blob/master/android/src/main/kotlin/dev/duynp/flutter_health_connect/FlutterHealthConnectPlugin.kt . Any code where "replyMapper.convertValue" is being used will fail in production. Of course, there are some ways to overcome this problem. For instance, making sure this mapper is able to convert any value of any visibility: https://stackoverflow.com/questions/8367312/serializing-with-jackson-json-getting-no-serializer-found . And you can even make sure this library does not return an actual object, but returns JSON string itself actually which is pretty frequently used practice by Flutter developers developing packages with complex data types used due to working like that being much easier (maybe this gives a performance hit, but mostly it is not the problem, since this hit is not that big). It is pretty strange that in this package it was decided to go with such approach.

Moreover, if you even able to manage to make sure the Health Connect Client model data is converted to JSON, you will get in the production something like that (and dates will be lost). 😅
{"a":[{"a":{},"b":null,"c":{},"d":null,"e":{"i":109.00025939941406,"j":"KILOCALORIES", ...
Why? Because the Kotlin code gets built into the byte code which does not preserve the variable names, thus actually we should be very grateful that library such as Jackson is such a cool library being able to convert something like that.

All to sum up, this library is just not a real wrapper for the Android Health Connect. It just has a good start, such as not inventing new data types, and trying to be an actual wrapper for the Health Connect which is nice due to trying to extend the overall capabilities of Flutter framework. And one note for developers and potential contributors of this package. Probably, new converters can be added. Jackson library can be used here, just make sure it converts not the whole class instance which in production has completely different variable names, but an actual Map<String, Any>. Some code would be needed, but in this way nothing would be lost, and package could be used in production.

@owjoh
Copy link

owjoh commented Jul 4, 2023

@duynguyen242 Is there any plans for a fix for this?

@dnkoulouris
Copy link

dnkoulouris commented Jul 11, 2023

Fixed the error, needs the following to be added to proguard-rules.pro:

-keep public class androidx.health.** {
  public protected private *;
}
-dontwarn androidx.health.**

The idea behind the solution is that the Jackson package tries to parse the Helath Connect classes, which are its input. By adding Health Connect classes to ProGuard, these classes are not minified and, thus, transported as a map with known keys to the Flutter side. Thanks to @vaidotasstrazdas for the information.

Maybe an update to the documentation, @duynguyen242 ?

@owjoh
Copy link

owjoh commented Jul 11, 2023

-keep public class androidx.health.** {
public protected private ;
}
-dontwarn androidx.health.
*

Hey @dnkoulouris where do you find this file? Is this something you created?

@dnkoulouris
Copy link

-keep public class androidx.health.** {
public protected private ;
}
-dontwarn androidx.health.
*

Hey @dnkoulouris where do you find this file? Is this something you created?

https://stackoverflow.com/questions/38213918/how-to-prepare-a-proguard-file-and-whats-included-in-it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants