How to set NDK Build path in OSX for Android studio

时光总嘲笑我的痴心妄想 提交于 2020-01-10 08:48:29

问题


I had set the ANDROID_NDK_HOME as /Users/Shajilshocker/Documents/Android/NDK/android-ndk-r10b using a mac osx application called Environment Variables.

I had confirmed that it set the path correctly in Terminal

echo $ANDROID_NDK_HOME

But when I run a shell file in a Android Studio project which invokes ndk-build I get the following error

ndk-build: command not found

How to make sure that ndk-build is in your build path ?

How to set ndk-build in my build path ?

Thanks for any help


回答1:


Well, this is actually not enough to make the system aware of the path. You must add this path to the PATH system variable. In your case, all you have to do is to add the following line to your terminal configuration file (which should be under your home directory, named .bashrc if you kept the default terminal, full path: ~/.bashrc):

export PATH=$PATH:/Users/Shajilshocker/Documents/Android/NDK/android-ndk-r10b

What this line does is actually adding the path to your Android NDK directory to the PATH variable. You export a variable named PATH with its current content plus the directory of your NDK.

Step by step:

  • Go in the home directory
  • Edit .bashrc
  • Add the line I showed above
  • Save, exit, then restart bash (you just have to type bash, then enter)



回答2:


For mac use this: Open your .bash_profile file with a text editor. .bash_profile is by default found in home directory. Eg /Users/john

the assumption is: you have downloaded the android sdk and ndk to /User/john/Android or you can find the path from Android Studio by going to

Project Structure > SDK Location, pay attention to Android SDK location & Android NDK location

export ANDROID_SDK=/Users/john/Android/sdk
export ANDROID_NDK=/Users/john/Android/sdk/ndk-bundle
export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK"

Then save the above lines to your .bash_profile file. Close it and try typing this on your terminal

ndk-build

if the response is like below, you are good to go

Android NDK: Could not find application project directory !    
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.    
/Users/john/Android/sdk/ndk-bundle/build/core/build-local.mk:143: ***   Android NDK: Aborting    .  Stop.

The assumption here is you have downloaded your android sdk to /Users/john/Android




回答3:


In case this helps anyone, I installed the Android NDK using Android Studio on MacOS by following the instructions on the android.com NDK webpage: I selected Tools --> Android --> SDK Manager and then selected NDK. Android Studio then installed the downloaded files under:

/Users/user.name/Library/Android/sdk/

That directory is the same one that is listed on the SDK Manager window inside Android Studio. Underneath that directory is another directory ndk-bundle, which has all the NDK tools.

Thus, I added this to my path:

/Users/user.name/Library/Android/sdk/ndk-bundle/



回答4:


  • cd to path you have to set.

  • Enter in Terminal: echo "export PATH=$PATH:$ANDROID_NDK_HOME" | sudo tee -a /etc/profile



来源:https://stackoverflow.com/questions/29795388/how-to-set-ndk-build-path-in-osx-for-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!