4

I'm trying to compile my React Native Android project using a local fork of react-native. I've followed the building from source guide and completed all steps (not using Android Studio).

When I try to run react-native run-android (from project root as normal), I get:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ReactAndroid:buildReactNdkLib'.
> Process 'command '/usr/local/opt/android-ndk/ndk-build'' finished with non-zero exit value 2

When I run ndk-build (from project root), I get:

Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/usr/local/Cellar/android-ndk/r12b/build/core/build-local.mk:151: *** Android NDK: Aborting    .  Stop.

Another SO thread pointed me in the direction of running ndk-build from ./android/app/src and create a jni directory there (I didn't have one), but I'm unsure how to obtain or create jni/Android.mk correctly or if this will even help me. I've tried creating jni/Application.mk with contents APP_BUILD_SCRIPT := Android.mk and jni/Android.mk with the setup described in that SO question. Running ndk-build from android/app/src exits with the following error:

Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: Android.mk
/usr/local/Cellar/android-ndk/r12b/build/core/add-application.mk:198: *** Android NDK: Aborting...    .  Stop.

I have the Android SDK and NDK installed with Homebrew and I have the following exports:

ANDROID_HOME=/usr/local/opt/android-sdk
ANDROID_SDK=/usr/local/opt/android-sdk
ANDROID_NDK=/usr/local/opt/android-ndk
ANDROID_NDK_HOME=/usr/local/opt/android-ndk

I feel like I'm close, but have no idea how to continue.

Community
  • 1
  • 1
Gert Hengeveld
  • 2,478
  • 1
  • 18
  • 13
  • No, you cannot run ndk-build from command line for react-native. Its gradle scripts download and configure a lot of dependencies, including boost. You can run `react-native --debug run-android` to find more about the failure of ':ReactAndroid:buildReactNdkLib'. I recommend to open an [issue on GitHub](https://github.com/facebook/react-native/issues?utf8=%E2%9C%93&q=is%3Aissue%20buildReactNdkLib). – Alex Cohn Oct 24 '16 at 12:59

2 Answers2

1

I think the issue is with android-ndk version. We need to use ndk version specified by react-native documentation. I tried with the latest version of andrid-ndk. I was not able to build the project, got similar error while running react-native run-android.

Then I tried with android-ndk-r10e version. It worked fine, I was able to build the project successfully.

Also you may find this react-native github issue discussion useful.

Jickson
  • 5,133
  • 2
  • 27
  • 38
0

I'm trying to compile React Native UIExplorer for Android.And I have same issue. Then I run ndk-build ,I get:

Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/usr/local/Cellar/android-ndk/r13b/build/core/build-local.mk:151: *** Android NDK: Aborting    .  Stop.

My android-ndk version is /android-ndk/r13b/,So I download android-ndk-r10e . I use the most direct way:

$ cd /usr/local/Cellar/android-ndk/r13b 
$ rm -rf ./*
$ mv YourUnZipPath/android-ndk-r10e/* ./

Then It worked fine, I was able to build the project successfully.