Recently I updated to 0.41.0-rc.0 and there has been a regression in regards to Proguard for Android. The following happens on a release build:
Warning: com.facebook.fbui.textlayoutbuilder.proxy.StaticLayoutProxy:
can't find referenced method 'StaticLayout(java.lang.CharSequence,int,int,android.text.TextPaint,int,android.text.Layout$Alignment,android.text.TextDirectionHeuristic,float,float,boolean,android.text.TextUtils$TruncateAt,int,int)'
in library class android.text.StaticLayout
react-native init TestProguardProjectreact-native-git-upgrade 0.41.0-rc.0react-native run-android --variant=release-dontwarn addition to proguard or better yet a -keep on the needed method would be best. Not a proguard expert so I'll leave this up for discussion, but can submit a PR if needed. I have to turn off proguard to build a release version after upgrade to RN0.41, do you have any workaround?
One solution is to ignore the warning by using:
-dontwarn com.facebook.fbui.textlayoutbuilder.proxy.StaticLayoutProxy
If that is the preferred route, we can add it to the React Native default proguard setup, however I'd like to get confirmation from some of the maintainers on whether it should be a dontwarn or a keep command.
RN 0.41 using proguard is failing for me too
We also had the same failure with a bunch of warnings from 0.41, but @jpshelley 's workaround was good enough.
The TextLayoutBuilder library has this in it's proguard rules (Fixed it for me):
# This library uses a non-public Android constructor within StaticLayout.
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
-dontwarn android.text.StaticLayout
https://github.com/facebookincubator/TextLayoutBuilder/blob/master/proguard-android.txt
it's helpful. Thanks
@AndrewJack Thank for the solution! It worked for me too. How did you find about this? Because proguard is not showing in the output what class it tried to find. I spent so much time on this issue :)
@henrikra I read in the proguard output that TextLayoutBuilder was the source of the issue (Admittedly a very hard to read output). I then found the TextLayoutBuilder repo on github. I saw it is built as a Jar and not an AAR, therefore the proguard files aren't supplied with it.
Why is this issue closed? If I create a project with react-native init and try to assembleReleaseit with proguard flag set to true, then the apk is not created successfully.
adding -dontwarn android.text.StaticLayout solves the problem, shouldn't it be added to the default proguard rules file
@guysegal the fix is in 0.44.0-rc, it'll work after that is stable https://github.com/facebook/react-native/commit/35046984db2c41ef740cb50e1e60a3dfdcd23056
greate thanks!
@AndrewJack This workaround works well. You saved my day !
As weird as it may sound, just tried to build a release version with RN 0.51 and the warning showed up again.
Adding that -dontwarn android.text.StaticLayout in the proguard rules solved it - but yeah weird, never had this issue before.
Most helpful comment
The TextLayoutBuilder library has this in it's proguard rules (Fixed it for me):
https://github.com/facebookincubator/TextLayoutBuilder/blob/master/proguard-android.txt