Skip to content

Commit

Permalink
Allow specifying an architecture in RNTester and release builds
Browse files Browse the repository at this point in the history
Summary:
Setting `reactNativeDebugArchitectures` currently does not seem to work for RNTester, since it sets `abiFilters` which conflicts with the `splits` option we're already setting.

Gradle then complains:
```
neildhar@neildhar-mbp ~/f/x/j/react-native-github (default) >
./gradlew  -PreactNativeDebugArchitectures=x86_64 :packages:rn-tester:android:app:installJscDebug

> Configure project :ReactAndroid
Unable to detect AGP versions for included builds. All projects in the build should use the same AGP version. Class name for the included build object: org.gradle.composite.internal.DefaultIncludedBuild$IncludedBuildImpl_Decorated.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':packages:rn-tester:android:app'.
> com.android.builder.errors.EvalIssueException: Conflicting configuration : 'x86_64' in ndk abiFilters cannot be present when splits abi filters are set : x86_64,x86,armeabi-v7a,arm64-v8a
```

Consolidate everything with the `splits` option.

In addition, it's convenient to also be able to control the native architecture for release builds.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D31834075

fbshipit-source-id: c6375d2a1e242981d0017f6e0a9d428b074a3fbd
  • Loading branch information
neildhar authored and facebook-github-bot committed Nov 3, 2021
1 parent 8649174 commit 43c38cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
13 changes: 6 additions & 7 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,8 @@ def reactNativeInspectorProxyPort() {
}

def reactNativeArchitectures() {
def isDebug = gradle.startParameter.taskRequests.any {
it.args.any { it.endsWith("Debug") }
}
def value = project.getProperties().get("reactNativeDebugArchitectures")
return value != null && isDebug ? value : "all"
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def ndkBuildJobs() {
Expand Down Expand Up @@ -290,8 +287,7 @@ android {

externalNativeBuild {
ndkBuild {
arguments "APP_ABI=${reactNativeArchitectures()}",
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
arguments "NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
"THIRD_PARTY_NDK_DIR=$thirdPartyNdkDir",
"REACT_COMMON_DIR=$projectDir/../ReactCommon",
"REACT_GENERATED_SRC_DIR=$buildDir/generated/source",
Expand All @@ -304,6 +300,9 @@ android {
}
}
}
ndk {
abiFilters (*reactNativeArchitectures())
}
}

externalNativeBuild {
Expand Down
13 changes: 5 additions & 8 deletions packages/rn-tester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ def enableFabric = project.ext.react.enableFabric
def useIntlJsc = false

/**
* Architectures to build native code for in debug.
* Architectures to build native code for.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
def nativeArchitectures = project.getProperties().get("reactNativeArchitectures") ?
project.getProperties().get("reactNativeArchitectures").split(",")
: ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]

android {
compileSdkVersion 29
Expand Down Expand Up @@ -183,18 +185,13 @@ android {
enable enableSeparateBuildPerCPUArchitecture
universalApk false
reset()
include "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
include (*nativeArchitectures)
}
}
buildTypes {
debug {
debuggable true
signingConfig signingConfigs.release
if (nativeArchitectures) {
ndk {
abiFilters nativeArchitectures.split(',')
}
}
}
release {
debuggable false
Expand Down
14 changes: 5 additions & 9 deletions template/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);

/**
* Architectures to build native code for in debug.
* Architectures to build native code for.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")

def nativeArchitectures = project.getProperties().get("reactNativeArchitectures") ?
project.getProperties().get("reactNativeArchitectures").split(",")
: ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
android {
ndkVersion rootProject.ext.ndkVersion

Expand All @@ -142,7 +143,7 @@ android {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
include (*nativeArchitectures)
}
}
signingConfigs {
Expand All @@ -156,11 +157,6 @@ android {
buildTypes {
debug {
signingConfig signingConfigs.debug
if (nativeArchitectures) {
ndk {
abiFilters nativeArchitectures.split(',')
}
}
}
release {
// Caution! In production, you need to generate your own keystore file.
Expand Down

0 comments on commit 43c38cd

Please sign in to comment.