From 3e95645f457de47c30bc5aca1c0c725e5543d674 Mon Sep 17 00:00:00 2001 From: Caleb Clarke Date: Mon, 24 Aug 2020 14:44:50 -0700 Subject: [PATCH] Fix release builds on Android, take 2 (#1329) Summary: Changelog: Fixed react-native-flipper causing Android release builds to fail https://github.com/facebook/flipper/issues/1325 made progress but did not quite fix https://github.com/facebook/flipper/issues/1303. Android Release builds would still fail because `PackageList` depended on `FlipperPackage` and couldn't find it in release builds. There doesn't appear to be a clear way to set up a debug-only package with React Native's Android autolinking (see https://github.com/react-native-community/cli/issues/1211), so this change creates an empty `FlipperPackage` to satisfy that dependency, while still avoiding bundling the Flipper library into the release build. (manual linking also works, but seems less-desirable for consumers of the library) ## Changelog Add an empty `FlipperPackage` to the `release` folder to satisfy the reference put in `PackageList` by the autolinker for release builds. Pull Request resolved: https://github.com/facebook/flipper/pull/1329 Test Plan: Verified that release builds did fail without this change (using ReactNativeFlipperExample app) Successfully built a React Native Android Release app from Android Studio using this library and verified that the APK still did not contain Flipper. Built debug and verified that Flipper still worked as before. Reviewed By: passy Differential Revision: D23292543 Pulled By: mweststrate fbshipit-source-id: cb897a0e6dcdc04e29d676596447ca9dd68182c8 --- .../flipper/reactnative/FlipperPackage.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 react-native/react-native-flipper/android/src/release/java/com/facebook/flipper/reactnative/FlipperPackage.java diff --git a/react-native/react-native-flipper/android/src/release/java/com/facebook/flipper/reactnative/FlipperPackage.java b/react-native/react-native-flipper/android/src/release/java/com/facebook/flipper/reactnative/FlipperPackage.java new file mode 100644 index 000000000..4587f1fa4 --- /dev/null +++ b/react-native/react-native-flipper/android/src/release/java/com/facebook/flipper/reactnative/FlipperPackage.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.flipper.reactnative; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; +import java.util.Collections; +import java.util.List; + +/** + * Exposes the react native modules that should be created per ReactApplicationContext. Note that an + * application context lives shorter than the application itself, e.g. reload creates a fresh one. + * + *

This is an empty implementation to keep Flipper out of release builds while still satisfying + * autolink's expectation to find a FlipperPackage. + */ +public class FlipperPackage implements ReactPackage { + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } +}