Skip to content

Instantly share code, notes, and snippets.

@cortinico
Last active April 12, 2022 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cortinico/6a297ac4c6a2a4633f58f1e4b375dd88 to your computer and use it in GitHub Desktop.
Save cortinico/6a297ac4c6a2a4633f58f1e4b375dd88 to your computer and use it in GitHub Desktop.
reproducer-rn-33611

To verify that facebook/react-native#33611 works correctly on windows, follow those steps:

  1. Create a new project on RN 0.68.0 with: npx react-native init RN068 --version 0.68.0 --skip-install
  2. Install packages with cd RN068 && yarn
  3. Opt-in for New Architecture by editing android/gradle.properties and setting newArchEnabled=true
  4. Verify that build is broken on Android on Windows: cd android && ./gradlew assembleDebug --scan
    1. This step will prompt to publish a Gradle Scan at the of the build. Type yes and publish it.
    2. Make sure that the build actually failed.
  5. Apply the fix33611-v3.patch attached to this Gist to your local environment: cd .. && git apply fix33611.patch
  6. Verify that build works correctly on Android on Windows now: cd android && ./gradlew assembleDebug --scan
    1. Again, publish the resulting build scan to verify that everything works correctly now.
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 97cfb110..ad31f484 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -159,6 +159,12 @@ android {
targets "rn068_appmodules"
}
}
+
+ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
+ arguments "NDK_OUT=$buildDir\\.cxx",
+ "NDK_APP_SHORT_COMMANDS=true"
+ }
+
}
}
diff --git a/node_modules/react-native/ReactAndroid/build.gradle b/node_modules/react-native/ReactAndroid/build.gradle
index 5a384f23..8fa5a070 100644
--- a/node_modules/react-native/ReactAndroid/build.gradle
+++ b/node_modules/react-native/ReactAndroid/build.gradle
@@ -318,6 +318,12 @@ android {
// This flag will suppress "fcntl(): Bad file descriptor" warnings on local builds.
arguments "--output-sync=none"
}
+
+ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
+ arguments "NDK_OUT=$buildDir\\.cxx",
+ "NDK_APP_SHORT_COMMANDS=true"
+ }
+
}
}
ndk {
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 97cfb110..3bae9794 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -1,6 +1,7 @@
apply plugin: "com.android.application"
import com.android.build.OutputFile
+import org.apache.tools.ant.taskdefs.condition.Os
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -157,6 +158,12 @@ android {
// Make sure this target name is the same you specify inside the
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
targets "rn068_appmodules"
+
+
+ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
+ arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx",
+ "NDK_APP_SHORT_COMMANDS=true"
+ }
}
}
}
diff --git a/node_modules/react-native/ReactAndroid/build.gradle b/node_modules/react-native/ReactAndroid/build.gradle
index 5a384f23..433f624c 100644
--- a/node_modules/react-native/ReactAndroid/build.gradle
+++ b/node_modules/react-native/ReactAndroid/build.gradle
@@ -318,6 +318,10 @@ android {
// This flag will suppress "fcntl(): Bad file descriptor" warnings on local builds.
arguments "--output-sync=none"
}
+ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
+ arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx",
+ "NDK_APP_SHORT_COMMANDS=true"
+ }
}
}
ndk {
diff --git a/android/build.gradle b/android/build.gradle
index 8a1d68f9..665991e2 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -1,3 +1,5 @@
+import org.apache.tools.ant.taskdefs.condition.Os
+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
@@ -6,7 +8,17 @@ buildscript {
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
- ndkVersion = "21.4.7075529"
+ if (System.properties['os.arch'] == "aarch64") {
+ // For M1 Users we need to use the NDK 24 which added support for aarch64
+ ndkVersion = "24.0.8215888"
+ } else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
+ // For Android Users, we need to use NDK 23, otherwise the build will
+ // fail due to paths longer than the OS limit
+ ndkVersion = "23.1.7779620"
+ } else {
+ // Otherwise we default to the side-by-side NDK version from AGP.
+ ndkVersion = "21.4.7075529"
+ }
}
repositories {
google()
diff --git a/node_modules/react-native/ReactAndroid/build.gradle b/node_modules/react-native/ReactAndroid/build.gradle
index 5a384f23..a77e8545 100644
--- a/node_modules/react-native/ReactAndroid/build.gradle
+++ b/node_modules/react-native/ReactAndroid/build.gradle
@@ -281,10 +281,13 @@ task androidSourcesJar(type: Jar) {
android {
compileSdkVersion 31
- // Used to override the NDK path & version on internal CI
- if (System.getenv("ANDROID_NDK") != null && System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) {
- ndkPath System.getenv("ANDROID_NDK")
- ndkVersion System.getenv("LOCAL_ANDROID_NDK_VERSION")
+ // Used to override the NDK path/version on internal CI or by allowing
+ // users to customize the NDK path/version from their root project (e.g. for M1 support)
+ if (rootProject.hasProperty("ndkPath")) {
+ ndkPath rootProject.ext.ndkPath
+ }
+ if (rootProject.hasProperty("ndkVersion")) {
+ ndkVersion rootProject.ext.ndkVersion
}
defaultConfig {
@mikehardy
Copy link

Your gradle commands and cd commands are unix-y, and do not work in powershell because of /' vs '\' and ./gradlew` vs 'gradlew.bat' because....windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment