forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Flipper integration to a separate Gradle module inside `ReactAnd…
…roid` (facebook#37688) Summary: Pull Request resolved: facebook#37688 This moves the `ReactNativeFlipper` classes used to configure Flipper on Android from the template to a separate Gradle artifact that will be published under the coordinates: ``` com.facebook.react:flipper-integration:0.73.x ``` This reduces the footprint of Flipper on the app template and makes easier for user on 0.73 to migrate to Kotlin (as they will now have to migrate only 2 files rather than 4). Changelog: [Android] [Changed] - Move Flipper integration to a separate Gradle module inside `ReactAndroid` Reviewed By: huntie Differential Revision: D46441588 fbshipit-source-id: e197f29b7386b52091b8d38ed09bbd8f74a997df
- Loading branch information
Showing
14 changed files
with
146 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Make sure we never publish the build folders to npm. | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
plugins { | ||
id("com.android.library") | ||
id("maven-publish") | ||
id("signing") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
group = "com.facebook.react" | ||
version = parent.publishing_version | ||
|
||
repositories { | ||
// Normally RNGP will set repositories for all modules, | ||
// but when consumed from source, we need to re-declare | ||
// those repositories as there is no app module there. | ||
mavenCentral() | ||
google() | ||
} | ||
|
||
android { | ||
compileSdk 33 | ||
buildToolsVersion = "33.0.0" | ||
namespace "com.facebook.react.flipper" | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(11) | ||
} | ||
|
||
dependencies { | ||
implementation project(':packages:react-native:ReactAndroid') | ||
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") | ||
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { | ||
exclude group:'com.squareup.okhttp3', module:'okhttp' | ||
} | ||
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") | ||
} | ||
|
||
publishing { | ||
multipleVariants { | ||
withSourcesJar() | ||
allVariants() | ||
} | ||
} | ||
} | ||
|
||
apply from: "../publish.gradle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Version of flipper SDK to use for this integration | ||
FLIPPER_VERSION=0.182.0 |
62 changes: 62 additions & 0 deletions
62
...droid/flipper-integration/src/debug/java/com/facebook/react/flipper/ReactNativeFlipper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and 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.flipper | ||
|
||
import android.content.Context | ||
import com.facebook.flipper.android.AndroidFlipperClient | ||
import com.facebook.flipper.android.utils.FlipperUtils | ||
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.sharedpreferences.SharedPreferencesFlipperPlugin | ||
import com.facebook.react.ReactInstanceEventListener | ||
import com.facebook.react.ReactInstanceManager | ||
import com.facebook.react.bridge.ReactContext | ||
import com.facebook.react.modules.network.NetworkingModule | ||
|
||
/** | ||
* Class responsible of loading Flipper inside your React Native application. This is the debug | ||
* flavor of it. Here you can add your own plugins and customize the Flipper setup. | ||
*/ | ||
object ReactNativeFlipper { | ||
@JvmStatic | ||
fun initializeFlipper(context: Context, reactInstanceManager: ReactInstanceManager) { | ||
if (FlipperUtils.shouldEnableFlipper(context)) { | ||
val client = AndroidFlipperClient.getInstance(context) | ||
client.addPlugin(InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())) | ||
client.addPlugin(DatabasesFlipperPlugin(context)) | ||
client.addPlugin(SharedPreferencesFlipperPlugin(context)) | ||
client.addPlugin(CrashReporterPlugin.getInstance()) | ||
val networkFlipperPlugin = NetworkFlipperPlugin() | ||
NetworkingModule.setCustomClientBuilder { builder -> | ||
builder.addNetworkInterceptor(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 | ||
val currentReactContext = reactInstanceManager.currentReactContext | ||
if (currentReactContext == null) { | ||
reactInstanceManager.addReactInstanceEventListener( | ||
object : ReactInstanceEventListener { | ||
override fun onReactContextInitialized(context: ReactContext) { | ||
reactInstanceManager.removeReactInstanceEventListener(this) | ||
context.runOnNativeModulesQueueThread { client.addPlugin(FrescoFlipperPlugin()) } | ||
} | ||
}) | ||
} else { | ||
client.addPlugin(FrescoFlipperPlugin()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
...ges/rn-tester/android/app/src/debug/java/com/facebook/react/uiapp/ReactNativeFlipper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters