I've got a hold of a proprietary JNI application which I need to build for a MIPS device. I've read "Initializing a Build Environment", parts of the NDK docs, some Google Groups threads and numerous StackOverflow questions, but I'm still short of my answer.

So far, I've checked out the Android source using Google's repo script and have it under ~/AndroidSource. I've also separately downloaded the SDK under ~/AndroidSDK and the NDK under ~/AndroidNDK. The code I'm trying to build is in a separate location. The SDK and NDK binaries are in my path. For building, I tried to use two different versions of the NDK as well as the one under the Android source tree, and experienced different sets of problems. My current setup uses NDK r8b, downloaded separately from the Android source.

The application has its Android.mk and jni/Android.mk. However, several directives in the latter point to paths such as

frameworks/base/include
system/core/include

with no prefixes. I thought these were meant to point to the respective directories in the Android source, so I symlinked them to the current directory. After some more symlinking and makefile and source hacking, I got the application to compile, but am currently stuck on the linking phase with lots of references to missing method bodies. During the whole time I knew I was doing something wrong.

I'm on a Linux x86_64 host, if it is of any concern.

So my question is:

What is the proper method to set up a build environment for JNI applications? What environment variables, symlinks and/or path expansions should I set up? Do I need to call any scripts once or before each ndk-build invocation?

Also, I'd be happy if you corrected me on any concepts or terminology I've gotten wrong.

有帮助吗?

解决方案

Your approach wiyh symlinking the AOSP tree for system headers is correct. What you need now are the system libraries compiled for MIPS. The easiest way to get them is to adb pull them from a target device (or emulator image). But you can also build these libraries yourself, as part of the AOSP build (see build instructions for the source tree you downloaded).

If you still have any problems remaining, run your ndk-build with parameter V=1 and publish the link command and its results.

其他提示

I use the following in my build (YMMV).

  • Explicitly invoke arm-linux-androideabi-gcc as your compiler or linker (should be in PATH).
  • NDK_PLATFORM=/path/to/android-ndk-r*/platforms/android-14
  • Pass -I"$(NDK_PLATFORM)/arch-arm/usr/include" to the compiler
  • Pass -nostdlib -L"$(NDK_PLATFORM)/arch-arm/usr/lib/" -lgcc -lc -lm to the linker
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top