-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encapsulate the prefab configuration for Android consumers
Summary: This moves the prefab/pickFirst configuration from the user's build.gradle to the React Native Gradle Plugin. As this configuration is entirely under our control, is safe to assume users won't need to tweak it (e.g. we control which libraries are built, etc.). Changelog: [Android] [Changed] - Encapsulate the prefab configuration for consumers Reviewed By: cipolleschi Differential Revision: D40094691 fbshipit-source-id: d1510a0a382d26e94e3d01f30661af39f7bedf52
- Loading branch information
1 parent
881f1de
commit b39e77b
Showing
6 changed files
with
125 additions
and
8 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
60 changes: 60 additions & 0 deletions
60
...act-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.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,60 @@ | ||
/* | ||
* 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.utils | ||
|
||
import com.android.build.api.variant.AndroidComponentsExtension | ||
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled | ||
import org.gradle.api.Project | ||
|
||
internal object NdkConfiguratorUtils { | ||
@Suppress("UnstableApiUsage") | ||
fun configureReactNativePrefab(project: Project) { | ||
if (!project.isNewArchEnabled) { | ||
return | ||
} | ||
project.pluginManager.withPlugin("com.android.application") { | ||
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext -> | ||
// We enable prefab so users can consume .so/headers from ReactAndroid and hermes-engine | ||
// .aar | ||
ext.buildFeatures.prefab = true | ||
|
||
// We set some packagingOptions { pickFirst ... } for our users for libraries we own. | ||
ext.packagingOptions.jniLibs.pickFirsts.addAll( | ||
listOf( | ||
// Hermes & JSC are provided by AAR dependencies we pre-bundle. | ||
"**/libhermes.so", | ||
"**/libjsc.so", | ||
// This is the .so provided by FBJNI via prefab | ||
"**/libfbjni.so", | ||
// Those are prefab libraries we distribute via ReactAndroid | ||
// Due to a bug in AGP, they fire a warning on console as both the JNI | ||
// and the prefab .so files gets considered. See more on: | ||
"**/libfabricjni.so", | ||
"**/libfolly_runtime.so", | ||
"**/libglog.so", | ||
"**/libjsi.so", | ||
"**/libreact_codegen_rncore.so", | ||
"**/libreact_debug.so", | ||
"**/libreact_nativemodule_core.so", | ||
"**/libreact_newarchdefaults.so", | ||
"**/libreact_render_componentregistry.so", | ||
"**/libreact_render_core.so", | ||
"**/libreact_render_debug.so", | ||
"**/libreact_render_graphics.so", | ||
"**/libreact_render_mapbuffer.so", | ||
"**/librrc_view.so", | ||
"**/libruntimeexecutor.so", | ||
"**/libturbomodulejsijni.so", | ||
"**/libyoga.so", | ||
// AGP will give priority of libc++_shared coming from App modules. | ||
"**/libc++_shared.so", | ||
)) | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.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,17 @@ | ||
/* | ||
* 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.utils | ||
|
||
import org.gradle.api.Project | ||
|
||
internal object ProjectUtils { | ||
internal val Project.isNewArchEnabled: Boolean | ||
get() = | ||
project.hasProperty("newArchEnabled") && | ||
project.property("newArchEnabled").toString().toBoolean() | ||
} |
43 changes: 43 additions & 0 deletions
43
...s/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.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,43 @@ | ||
/* | ||
* 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.utils | ||
|
||
import com.facebook.react.tests.createProject | ||
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class ProjectUtilsTest { | ||
|
||
@Test | ||
fun isNewArchEnabled_returnsFalseByDefault() { | ||
assertFalse(createProject().isNewArchEnabled) | ||
} | ||
|
||
@Test | ||
fun isNewArchEnabled_withDisabled_returnsFalse() { | ||
val project = createProject() | ||
project.extensions.extraProperties.set("newArchEnabled", "false") | ||
assertFalse(project.isNewArchEnabled) | ||
} | ||
|
||
@Test | ||
fun isNewArchEnabled_withEnabled_returnsTrue() { | ||
val project = createProject() | ||
project.extensions.extraProperties.set("newArchEnabled", "true") | ||
assertTrue(project.isNewArchEnabled) | ||
} | ||
|
||
@Test | ||
fun isNewArchEnabled_withInvalid_returnsFalse() { | ||
val project = createProject() | ||
project.extensions.extraProperties.set("newArchEnabled", "¯\\_(ツ)_/¯") | ||
assertFalse(project.isNewArchEnabled) | ||
} | ||
} |
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