Ubuntu环境下Android NDK编译报错求助:模块缺失与文件依赖问题
Hey Andy, let's tackle these two issues one by one—they're both basic setup snags that are easy to fix!
1. Error: ndk-build cannot find module with tag 'cxx-stl/system' in import path
First off, the system STL is the default runtime for NDK builds, so you don't need to explicitly import it with an import-module call. That line in your Android.mk is unnecessary and causing the error.
Here's what to do:
- Open your
jni/Android.mkfile. - Delete any line that looks like
$(call import-module,cxx-stl/system). - If you want to explicitly confirm you're using the system STL, add
LOCAL_STL := systemto your module definition (this is optional, since it's the default behavior).
Also, a quick heads-up: this error might also pop up if you're working directly with the compressed NDK archive instead of an extracted directory—we'll fix that in the next section.
2. Error: make: *** No rule to make target '/hello.c', needed by 'obj/local/armeabi/objs/helloARM/hello.o'. Stop.
Looking at your command path, you're trying to run ndk-build directly on the .tar.bz2 compressed file like it's a folder—that's the core issue here! The NDK needs to be extracted to a regular directory first, otherwise the build system can't find the example source files.
Follow these steps to fix this:
Extract the NDK archive:
Run this terminal command to unpack the NDK (adjust the path if your download is in a different location):tar -xvf ~/Downloads/android-ndk-r11-linux-x86_64.tar.bz2 -C ~/Downloads/This will create a directory named
android-ndk-r11in your Downloads folder.Verify the example files exist:
Navigate to the hello example's jni directory:cd ~/Downloads/android-ndk-r11/sources/hello/jniRun
lsto check forhello.c—you should see it alongsideAndroid.mk.Run ndk-build correctly:
From the jni directory, just run:ndk-buildIf you're running it from another location, use the
-Cflag to point to the hello example's root folder:ndk-build -C ~/Downloads/android-ndk-r11/sources/hello
Quick Final Check
To make running ndk-build easier long-term, you can add the NDK's root directory to your system PATH, or always call it using the full path:
~/Downloads/android-ndk-r11/ndk-build
内容的提问来源于stack exchange,提问作者Andy Lee

