react-native: Build from source fails at, could not find ANDROID_NDK_VERSION
Description
I am trying to build from source, and it seems I have set up everything correctly but the build still fails.with the following error. Any help would be appreciated
❯ ./gradlew clean
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/ashish/projects/tarana/node_modules/react-native/ReactAndroid/build.gradle' line: 450
* What went wrong:
A problem occurred evaluating project ':ReactAndroid'.
> Could not get unknown property 'ANDROID_NDK_VERSION' for extension 'android' of type com.android.build.gradle.LibraryExtension.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 6s
Version
0.67.2
Output of npx react-native info
❯ npx react-native info
warn Package lint-staged has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Users/ashish/projects/tarana/node_modules/lint-staged/package.json
info Fetching system and libraries information...
System:
OS: macOS 11.6.1
CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
Memory: 515.24 MB / 20.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 12.22.10 - ~/n/bin/node
Yarn: 1.22.11 - ~/n/bin/yarn
npm: 6.14.16 - ~/n/bin/npm
Watchman: 2022.01.03.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
API Levels: 28, 29, 30, 31, 32
Build Tools: 28.0.3, 29.0.2, 30.0.2, 31.0.0, 32.0.0, 32.1.0
System Images: android-29 | Google APIs Intel x86 Atom
Android NDK: 21.4.7075529
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7935034
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
I ran ./gradlew clean and it appeared
Snack, code example, screenshot, or link to a repository
Not available
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 24 (8 by maintainers)
Was experiencing a similar issue after upgrading to
react-native@0.68.1
The proposed addition to
settings.gradle
did not help:but using the following line
from the upgrade guide did help. https://react-native-community.github.io/upgrade-helper/?from=0.67.4&to=0.68.1
The fix for this specific issue is to update your
settings.gradle
as follows:The problem is that you’re using an older revision of the repo, therefore the wiki is updated to use the latest
main
. Building from source from different revision is generally not supported (i.e. you’re on your own) as there are those kinds of incompatibilities, and we can’t provide instructions for all the possible RN versions/branches.Adding this in build.gradle
throws this error
settings.gradle::
This helped a ton. I missed it out cause my brain was dead and I was filtering out changes that were for the new architecture which made me miss over that change while skimming
Does that mean that you need to add react-native-gradle-plugin inside your package.json dependencies ?
Not really, but we do have the reactnative.dev website which is versioned. So we could move this page there 👍
@afkcodes Actually this was not working as gradle.properties only supports strings and no function calls. The build.gradle of ReactAndroid suggest that we hardcode the NDK_VERSION and PATH in the properties file but that is not a good practice for an app that is maintained by a lot of developers. So I ended up modifying the code of build.gradle for ReactAndroid by using environment variables for both NDK_VERSION and PATH.
I added the following lines in their build.gradle file:
def ANDROID_NDK_VERSION = System.getenv(‘ANDROID_NDK_VERSION’) def ANDROID_NDK_PATH = System.getenv(‘ANDROID_NDK_PATH’).
Now the code syncs fine.
You might also need to use the ANDROID_NDK_PATH wherever the gradle file needs path for NDK if you experience NDK is not installed bug in their file like me.
You should follow this guide to setup the build from source: https://github.com/facebook/react-native/wiki/Building-from-source
One of the prerequisite of the guide is to
git clone
react native insidenode_modules
.We haven’t tested the wiki with a Github dependency such as
facebook/react-native#0.67-stable
.Also, why are you trying to build from
0.67-stable
. The assumption behind build from source is that you’ll use the latestmain
.Have you followed all the steps in the Wiki I linked? Also the changes to the
settings.gradle
file?