diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index 2391ab56a9b6d5..247355407e1480 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -168,8 +168,6 @@ dependencies { // Build React Native from source implementation project(':ReactAndroid') - implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" - def hermesPath = '$projectDir/../../../../node_modules/hermes-engine/android/' hermesDebugImplementation files(hermesPath + "hermes-debug.aar") hermesReleaseImplementation files(hermesPath + "hermes-release.aar") @@ -178,14 +176,6 @@ dependencies { exclude group:'com.facebook.fbjni' } - debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { - exclude group:'com.facebook.flipper' - } - - debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { - exclude group:'com.facebook.flipper' - } - if (useIntlJsc) { jscImplementation 'org.webkit:android-jsc-intl:+' } else { diff --git a/RNTester/android/app/src/debug/java/com/facebook/react/uiapp/ReactNativeFlipper.java b/RNTester/android/app/src/debug/java/com/facebook/react/uiapp/ReactNativeFlipper.java index 4a9072566f642e..7f5f0b024c9e93 100644 --- a/RNTester/android/app/src/debug/java/com/facebook/react/uiapp/ReactNativeFlipper.java +++ b/RNTester/android/app/src/debug/java/com/facebook/react/uiapp/ReactNativeFlipper.java @@ -7,66 +7,18 @@ package com.facebook.react.uiapp; import android.content.Context; + import com.facebook.flipper.android.AndroidFlipperClient; import com.facebook.flipper.android.utils.FlipperUtils; import com.facebook.flipper.core.FlipperClient; -import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; -import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; -import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; -import com.facebook.flipper.plugins.inspector.DescriptorMapping; -import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; -import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; -import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; -import com.facebook.flipper.plugins.react.ReactFlipperPlugin; -import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; +import com.facebook.react.FlipperInitializer; import com.facebook.react.ReactInstanceManager; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.modules.network.NetworkingModule; -import okhttp3.OkHttpClient; public class ReactNativeFlipper { public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { if (FlipperUtils.shouldEnableFlipper(context)) { final FlipperClient client = AndroidFlipperClient.getInstance(context); - - client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); - client.addPlugin(new ReactFlipperPlugin()); - client.addPlugin(new DatabasesFlipperPlugin(context)); - client.addPlugin(new SharedPreferencesFlipperPlugin(context)); - client.addPlugin(CrashReporterPlugin.getInstance()); - - NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); - NetworkingModule.setCustomClientBuilder( - new NetworkingModule.CustomClientBuilder() { - @Override - public void apply(OkHttpClient.Builder builder) { - builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); - } - }); - client.addPlugin(networkFlipperPlugin); - client.start(); - - // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized - // Hence we run if after all native modules have been initialized - ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); - if (reactContext == null) { - reactInstanceManager.addReactInstanceEventListener( - new ReactInstanceManager.ReactInstanceEventListener() { - @Override - public void onReactContextInitialized(ReactContext reactContext) { - reactInstanceManager.removeReactInstanceEventListener(this); - reactContext.runOnNativeModulesQueueThread( - new Runnable() { - @Override - public void run() { - client.addPlugin(new FrescoFlipperPlugin()); - } - }); - } - }); - } else { - client.addPlugin(new FrescoFlipperPlugin()); - } + FlipperInitializer.initializeDefaultFlipperPlugins(context, client, reactInstanceManager); } } } diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 78a0a0d90f17b0..cb57a52f9719e9 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -464,6 +464,20 @@ dependencies { androidTestImplementation("androidx.test:runner:${ANDROIDX_TEST_VERSION}") androidTestImplementation("androidx.test:rules:${ANDROIDX_TEST_VERSION}") androidTestImplementation("org.mockito:mockito-core:${MOCKITO_CORE_VERSION}") + + implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" + + debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { + exclude group:'com.facebook.fbjni' + } + + debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { + exclude group:'com.facebook.flipper' + } + + debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { + exclude group:'com.facebook.flipper' + } } apply(from: "release.gradle") diff --git a/ReactAndroid/gradle.properties b/ReactAndroid/gradle.properties index 1d065d7d581765..fa46a536279e47 100644 --- a/ReactAndroid/gradle.properties +++ b/ReactAndroid/gradle.properties @@ -20,6 +20,7 @@ BOOST_VERSION=1_63_0 DOUBLE_CONVERSION_VERSION=1.1.6 FOLLY_VERSION=2020.01.13.00 GLOG_VERSION=0.3.5 +FLIPPER_VERSION=0.31.0 android.useAndroidX=true android.enableJetifier=true diff --git a/ReactAndroid/src/debug/java/com/facebook/react/FlipperInitializer.java b/ReactAndroid/src/debug/java/com/facebook/react/FlipperInitializer.java new file mode 100644 index 00000000000000..8aeb7256a23df8 --- /dev/null +++ b/ReactAndroid/src/debug/java/com/facebook/react/FlipperInitializer.java @@ -0,0 +1,68 @@ +/* + * 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.react; + +import android.content.Context; + +import com.facebook.flipper.core.FlipperClient; +import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; +import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; +import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; +import com.facebook.flipper.plugins.inspector.DescriptorMapping; +import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; +import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; +import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; +import com.facebook.flipper.plugins.react.ReactFlipperPlugin; +import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; +import com.facebook.react.bridge.ReactContext; +import com.facebook.react.modules.network.NetworkingModule; + +import okhttp3.OkHttpClient; + +public class FlipperInitializer { + public static void initializeDefaultFlipperPlugins( + Context context, FlipperClient client, ReactInstanceManager reactInstanceManager) { + client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); + client.addPlugin(new ReactFlipperPlugin()); + client.addPlugin(new DatabasesFlipperPlugin(context)); + client.addPlugin(new SharedPreferencesFlipperPlugin(context)); + client.addPlugin(CrashReporterPlugin.getInstance()); + + NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); + NetworkingModule.setCustomClientBuilder( + new NetworkingModule.CustomClientBuilder() { + @Override + public void apply(OkHttpClient.Builder builder) { + builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); + } + }); + client.addPlugin(networkFlipperPlugin); + client.start(); + + // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized + // Hence we run if after all native modules have been initialized + ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); + if (reactContext == null) { + reactInstanceManager.addReactInstanceEventListener( + new ReactInstanceManager.ReactInstanceEventListener() { + @Override + public void onReactContextInitialized(ReactContext reactContext) { + reactInstanceManager.removeReactInstanceEventListener(this); + reactContext.runOnNativeModulesQueueThread( + new Runnable() { + @Override + public void run() { + client.addPlugin(new FrescoFlipperPlugin()); + } + }); + } + }); + } else { + client.addPlugin(new FrescoFlipperPlugin()); + } + } +}