Skip to content

Commit 16201f8

Browse files
cortinicofacebook-github-bot
authored andcommitted
Move Flipper integration to a separate Gradle module inside ReactAndroid (#37688)
Summary: Pull Request resolved: #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
1 parent 0e80fdb commit 16201f8

File tree

19 files changed

+101
-115
lines changed

19 files changed

+101
-115
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ project.xcworkspace
3939
/packages/react-native/ReactAndroid/gradlew.bat
4040
/packages/react-native/ReactAndroid/external-artifacts/build/
4141
/packages/react-native/ReactAndroid/external-artifacts/artifacts/
42+
/packages/react-native/ReactAndroid/flipper-integration/build/
4243
/packages/react-native/ReactAndroid/hermes-engine/build/
4344
/packages/react-native/ReactAndroid/hermes-engine/.cxx/
4445
/packages/react-native/template/android/app/build/

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ tasks.register("publishAllToMavenTempLocal") {
9999
description = "Publish all the artifacts to be available inside a Maven Local repository on /tmp."
100100
dependsOn(":packages:react-native:ReactAndroid:publishAllPublicationsToMavenTempLocalRepository")
101101
// We don't publish the external-artifacts to Maven Local as CircleCI is using it via workspace.
102+
dependsOn(
103+
":packages:react-native:ReactAndroid:flipper-integration:publishAllPublicationsToMavenTempLocalRepository")
102104
dependsOn(
103105
":packages:react-native:ReactAndroid:hermes-engine:publishAllPublicationsToMavenTempLocalRepository")
104106
}
@@ -107,5 +109,6 @@ tasks.register("publishAllToSonatype") {
107109
description = "Publish all the artifacts to Sonatype (Maven Central or Snapshot repository)"
108110
dependsOn(":packages:react-native:ReactAndroid:publishToSonatype")
109111
dependsOn(":packages:react-native:ReactAndroid:external-artifacts:publishToSonatype")
112+
dependsOn(":packages:react-native:ReactAndroid:flipper-integration:publishToSonatype")
110113
dependsOn(":packages:react-native:ReactAndroid:hermes-engine:publishToSonatype")
111114
}

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ internal object DependencyUtils {
4545
/**
4646
* This method takes care of configuring the resolution strategy for both the app and all the 3rd
4747
* party libraries which are auto-linked. Specifically it takes care of:
48-
* - Forcing the react-android/hermes-android version to the one specified in the package.json
48+
* - Forcing the react-android/hermes-android/flipper-integration version to the one specified in
49+
* the package.json
4950
* - Substituting `react-native` with `react-android` and `hermes-engine` with `hermes-android`.
5051
*/
5152
fun configureDependencies(
@@ -68,6 +69,7 @@ internal object DependencyUtils {
6869
configuration.resolutionStrategy.force(
6970
"${groupString}:react-android:${versionString}",
7071
"${groupString}:hermes-android:${versionString}",
72+
"${groupString}:flipper-integration:${versionString}",
7173
)
7274
}
7375
}

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal object NdkConfiguratorUtils {
7878
) {
7979
if (!project.isNewArchEnabled) {
8080
// For Old Arch, we set a pickFirst only on libraries that we know are
81-
// clashing with our direct dependencies (FBJNI, Flipper and Hermes).
81+
// clashing with our direct dependencies (mainly FBJNI and Hermes).
8282
variant.packaging.jniLibs.pickFirsts.addAll(
8383
listOf(
8484
"**/libfbjni.so",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Make sure we never publish the build folders to npm.
2+
build/
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
plugins {
9+
id("com.android.library")
10+
id("maven-publish")
11+
id("signing")
12+
id("org.jetbrains.kotlin.android")
13+
}
14+
15+
group = "com.facebook.react"
16+
version = parent.publishing_version
17+
18+
repositories {
19+
// Normally RNGP will set repositories for all modules,
20+
// but when consumed from source, we need to re-declare
21+
// those repositories as there is no app module there.
22+
mavenCentral()
23+
google()
24+
}
25+
26+
android {
27+
compileSdk 33
28+
buildToolsVersion = "33.0.0"
29+
namespace "com.facebook.react.flipper"
30+
31+
defaultConfig {
32+
minSdk = 21
33+
}
34+
35+
compileOptions {
36+
sourceCompatibility = JavaVersion.VERSION_11
37+
targetCompatibility = JavaVersion.VERSION_11
38+
}
39+
40+
kotlin {
41+
jvmToolchain(11)
42+
}
43+
44+
dependencies {
45+
implementation project(':packages:react-native:ReactAndroid')
46+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
47+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
48+
exclude group:'com.squareup.okhttp3', module:'okhttp'
49+
}
50+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
51+
}
52+
53+
publishing {
54+
multipleVariants {
55+
withSourcesJar()
56+
allVariants()
57+
}
58+
}
59+
}
60+
61+
apply from: "../publish.gradle"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Version of flipper SDK to use for this integration
2+
FLIPPER_VERSION=0.182.0

packages/react-native/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.kt renamed to packages/react-native/ReactAndroid/flipper-integration/src/debug/java/com/facebook/react/flipper/ReactNativeFlipper.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
package com.helloworld
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.flipper
29

310
import android.content.Context
411
import com.facebook.flipper.android.AndroidFlipperClient
@@ -21,6 +28,7 @@ import com.facebook.react.modules.network.NetworkingModule
2128
* flavor of it. Here you can add your own plugins and customize the Flipper setup.
2229
*/
2330
object ReactNativeFlipper {
31+
@JvmStatic
2432
fun initializeFlipper(context: Context, reactInstanceManager: ReactInstanceManager) {
2533
if (FlipperUtils.shouldEnableFlipper(context)) {
2634
val client = AndroidFlipperClient.getInstance(context)

packages/react-native/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.kt renamed to packages/react-native/ReactAndroid/flipper-integration/src/release/java/com/facebook/react/flipper/ReactNativeFlipper.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
package com.helloworld
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.flipper
29

310
import android.content.Context
411
import com.facebook.react.ReactInstanceManager
@@ -9,6 +16,7 @@ import com.facebook.react.ReactInstanceManager
916
*/
1017
object ReactNativeFlipper {
1118
@Suppress("UNUSED_PARAMETER")
19+
@JvmStatic
1220
fun initializeFlipper(context: Context, reactInstanceManager: ReactInstanceManager) {
1321
// Do nothing as we don't want to initialize Flipper on Release.
1422
}

packages/react-native/settings.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ include(":packages:react-native:ReactAndroid:hermes-engine")
2929

3030
project(":packages:react-native:ReactAndroid:hermes-engine").projectDir =
3131
file("ReactAndroid/hermes-engine/")
32+
33+
include(":packages:react-native:ReactAndroid:flipper-integration")
34+
35+
project(":packages:react-native:ReactAndroid:flipper-integration").projectDir =
36+
file("ReactAndroid/flipper-integration/")

0 commit comments

Comments
 (0)