[android] Throwing new exception
willerrodrigo opened this issue · comments
Description
Hello, I'm receiving this error after building (expo dev client - sdk 50) and launching the app.
Edit: using version 2.3.0 it works.
thread.cc:2372] Throwing new exception 'no "I" field "height" in class "Lcom/unistyles/Dimensions;" or its superclasses' with unexpected pending exception: java.lang.NoSuchFieldError: no "I" field "width" in class "Lcom/unistyles/Dimensions;" or its superclasses
thread.cc:2372] at void com.unistyles.UnistylesModule.nativeInstall(long, com.unistyles.Dimensions, java.lang.String, java.lang.String, com.unistyles.Insets, com.unistyles.Dimensions, com.unistyles.Dimensions) (SourceFile:-2)
thread.cc:2372] at boolean com.unistyles.UnistylesModule.install() (SourceFile:-1)
thread.cc:2372] at void com.facebook.jni.NativeRunnable.run() (SourceFile:-2)
thread.cc:2372] at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:938)
thread.cc:2372] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:99)
thread.cc:2372] at void com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(android.os.Message) (SourceFile:-1)
thread.cc:2372] at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:201)
thread.cc:2372] at void android.os.Looper.loop() (Looper.java:288)
thread.cc:2372] at void com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run() (SourceFile:-1)
thread.cc:2372] at void java.lang.Thread.run() (Thread.java:920)
thread.cc:2372]
Steps to reproduce
- Build app with expo dev client
- Launch the app
Snack or a link to a repository (optional)
No response
Unistyles version
^2.4.0
React Native version
0.73.4
Platforms
Android
Engine
Hermes
Architecture
Paper (old)
Hey!
Did you forget to run yarn expo prebuild --clean
?
A lot has changed on native side, and you need to generate a new build.
Tested today on fresh project.
Yes, I did 🤔 .
Can you check one more time?
Yes, I tried many times, so weird...
Can you give me a repo with repro?
Of course: https://github.com/willerrodrigo/unistyle
Just to know, I used eas build --platform android --profile preview --local
to build the app.
Okay, I can confirm the issue. The problem arises from using ProGuard.
ProGuard modifies the names of the height and width fields in the Dimensions class, which JNI accesses. It's crucial to maintain their original names, as C++ expects to find height and width.
I will attempt to prepare the rule and add it to the documentation.
Cool! I'll be waiting.
Thank you.
Done, works as intended with proguard:
Here is the section in the docs: https://www.unistyl.es/reference/faq/#my-release-app-is-crashing-on-startup-android-with-proguard-enabled
And solution for you:
"android": {
"enableProguardInReleaseBuilds": true,
- "extraProguardRules": "-keep public class com.horcrux.svg.** {*;}",
+ "extraProguardRules": "-keep public class com.horcrux.svg.** {*;} -keep class com.unistyles.** { *; }",
"allowBackup": false
}
Thank you for the report and repo with reproduction 🙏