flipper: Cannot build Android Release with react-native-flipper 0.48.0+

🐛 Bug Report

react-native-flipper 0.48.0 breaks building Android in Release, presumably due to https://github.com/facebook/flipper/commit/03b231703ba1e609d8b5d31d71d07c57be1f0b29

Version 0.47.0 did not have this problem, although it had the problem in #1274, which the above change was trying to address.

image

To Reproduce

Very simple.

  1. npx react-native init Test
  2. cd Test
  3. yarn add react-native-flipper
  4. Open project in Android Studio
  5. Set Build Variant to “release”
  6. Try to build project

The build will fail, but if you change the version of react-native-flipper from 0.48.0 to 0.47.0, then it will succeed.

Environment

Since this is a build failure with a default-initialized React Native project, the only variable being react-native-flipper itself, I can’t think of any relevant environment info to add, but feel free to ask if you think there’s something I’ve missed.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 18 (11 by maintainers)

Commits related to this issue

Most upvoted comments

The fix has been released as react-native-flipper@0.54.0.

@micnguyen if you’re using react-native-flipper dependency, install the 0.47.0 version

@ObidosDev I solved on my project, I sent a PR that can resolve this problem here

@micnguyen Note that @b3coded 's tip will fix the build but mean that your release APK includes a few MB of Flipper libraries.

If that concerns you, manual linking is an effective workaround… but it’s a little nontrivial and hopefully it won’t be too much longer to get the fix in for this 🤞

May be need to create debug folder and return module for auto linking by BuildConfig.DEBUG value and with reflection return FlipperModule instance if debug is true. (Very the same as for initializeFlipper from installation part)

Because root cause is auto generated PackageList.java

public ArrayList<ReactPackage> getPackages() {
    return new ArrayList<>(Arrays.<ReactPackage>asList(
      new MainReactPackage(mConfig),
      new FlipperPackage(),  // <- it is here in release 
...

Assumption:

List<NativeModule> createNativeModules(ReactApplicationContext reactContext)

if (BuildConfig.DEBUG) {
            try {
                Class<?> flipperModuleClass = Class.forName("com.facebook.flipper.reactnative.FlipperModule");

                return Collections.<NativeModule>singletonList((NativeModule)
                        flipperModuleClass
                                .getMethod("init", ReactApplicationContext.class)
                                .invoke(null, reactContext));

            } catch ...
public class FlipperModule extends ReactContextBaseJavaModule {

    public static final String NAME = "Flipper";

    public static FlipperModule init(ReactApplicationContext reactContext) {
        return new FlipperModule(FlipperReactNativeJavaScriptPluginManager.getInstance(), reactContext);
    } ...

Hope it make sense 🧑‍💻