I'm trying to build android adb tool from the sources. Since file Android.mk is presented i'm running ndk-build tool to build it. But unfortunately i'm having following errors:
/Users/user/Documents/dev/tmp/adb/jni/Android.mk:95: /softdev/android-ndk-r10c/build/core/build-host-static-library.mk: No such file or directory
/Users/user/Documents/dev/tmp/adb/jni/Android.mk:183: /softdev/android-ndk-r10c/build/core/build-host-executable.mk: No such file or directory
Android NDK: Trying to define local module 'adbd' in /Users/user/Documents/dev/tmp/adb/jni/Android.mk.
Android NDK: But this module was already defined by /Users/user/Documents/dev/tmp/adb/jni/Android.mk.
/softdev/android-ndk-r10c/build/core/build-module.mk:34: *** Android NDK: Aborting. . Stop.
I've checked files (build-host-*-*.mk) are absent for some reason. I've found them in someone's git repo, but it's for windows. After copying build-host-*-*.mk to my local ndk folder i'm getting another errors:
Android NDK: /Users/user/Documents/dev/tmp/adb/jni/Android.mk:adb: Unknown LOCAL_MODULE_CLASS value: HOST_STATIC_LIBRARY
/softdev/android-ndk-r10c/build/core/build-module.mk:29: *** Android NDK: Aborting . Stop.
So it seems that just copying that files is not enough. How can i make it built?
adb is a host tool (which runs on your PC rather than on the Android device), and NDK has no support for building host executables. It does provide some stubs but the feature was never fully implemented.
The git repo you are linking to is not the official NDK r7b but a patched version with host target support added. This includes a bit more than just a single file – see the full diff here.
You will need to apply this patch (or copy all the scripts which were modified) to your local NDK setup. If you are running an NDK version other than r7b, you may have to make some additional modifications.
See also my question, in which I basically ran into the same issue.
Related
I've been doing a lot of attempts to get libpcap compiled for Android, and I don't see any pattern or any progress worth writing down.
I have a very simple sniffer (that works fine in a MIPS linux) that uses libpcap, so I thought to myself oh, ok... no biggie... I'll just compile libpcap for Android (in the end, Android is just a Linux)... and here's where the problems started. I have no idea on how to compile libpcap using ndk-build and the Android.mk and all that infrastructure.
I have the Android NDK in a directory. That NDK has the toolchains built (I have a lot of directories under ~/Documents/Projects/Android_NDK/toolchains/ ) but none of the toolchains has libpcap available.
I've tried with two different libpcap version or... branches:
The Android one, which is the one I'd like to use,
https://android.googlesource.com/platform/external/libpcap/
and the regular one:
http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz
All tries I've done have been very unsuccessful. I've seen the question Android NDK: Link using a pre-compiled static library which is similar, but I'm still getting various errors.
I have downloaded those pcap libraries to their own directories. Maybe is that the problem? Do I need to put the Android libpcap in some directory within the NDK root directory and re-create the toolchains?
I'm using NDK-r9 on a MacOSX 10.9.2 64bit.
Finally!!
After getting annoyed by the non existing headers in and stuff like that, I found this question, that pointed to a SVN repo (http://sourceforge.net/p/prueba-android/code/HEAD/tree/trunk/jni/) with a libpcap that compiled!
If someone else wants additional details on how my Android.mk and directory structure looks like, please add a comment and I'll extend this answer.
Please read an excellent article at http://blog.umitproject.org/2011/05/libpcap-for-android.html. There are instructions that will help you link to libpcap, but the most important takeaway is that you cannot use libpcap on non-rooted Android. So maybe it's not worth your effort.
On a rooted device, you can simply install a free sniffer like Shark for Root.
If anyone else is having problems compiling libpcap for Android using the NDK, there is version 1.5.2 here with a built Android.mk file in it: https://android.googlesource.com/platform/external/libpcap.git and instructions for compiling this using the NDK are here: http://ducbh.blogspot.co.uk/2013/12/cross-compile-libpcap-for-android.html . I can confirm this works using the current NDK (r10b)...although you may have to add AndroidManifest.xml (blank) and and Application.mk that points to your Android.mk file.
I don't think it would be that difficult to modify the .mk file for the current libpcap version (1.6.2)
In case anyone ends up here in 2022+. You can now cross-compile for Android from the official source. Steps:
First, setup the NDK:
Download Android NDK (I used r21e) and extract to a directory of your choosing:
$ cd ~
$ mkdir Android
$ unzip android-ndk-r21e-linux-x86_64.zip
Prepare the environment variables for cross-compilation by placing the commands below (replace <YOUR_USER>) into a file named setup_env.sh (can be saved anywhere):
export NDK=/home/<YOUR_USER>/Android/android-ndk-r21e
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=aarch64-linux-android
export API=21
export AR=$TOOLCHAIN/bin/$TARGET-ar
export AS=$TOOLCHAIN/bin/$TARGET-as
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/$TARGET-ld
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
Now, build libpcap:
Download libpcap tar ball (e.g. https://www.tcpdump.org/release/libpcap-1.10.1.tar.gz)
Extract (in a directory of your choosing): tar xf libpcap-1.10.1.tar.gz
Prepare your env: source <path_to>/setup_env.sh
Change into the extract libpcap directory and configure: ./configure --host=aarch64-linux-android
I found the Makefile generated had the wrong linker set (line 48), so I had to change it to: LD = /home/<YOUR_USER>/Android/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/ld
Finally, build: make
This build worked for me with running tcpreplay on a rooted Android, hopefully it works for other purposes as well!
I have followed these steps in order to compile the Foxit library:
1) Download and install the Eclipse IDE (http://www.eclipse.org/), the Android SDK, ADT plugin for Eclipse, and the Android NDK (http://developer.android.com/sdk/index.html).
a) For Windows use, also download and install Cygwin (http://www.cygwin.com/). During Cygwin setup, make sure to include the “Devel -> make” package.
2) Download the Foxit embedded SDK Package.
3) Extract the Foxit embedded SDK Package to any directory.
4) Place the Foxit embedded SDK library and header files in fpdfemb_android/examples/demos/bin and include directory.
5) Build the NDK layer.
a) Open the Android.mk makefile in fpdfemb_android/examples/demos/demo(like “demo_view”)/jni/ in a text editor and fill in the Foxit library name in the area designated for LOCAL_LDLIBS, dropping the lib prefix:
The demo is shipped as:
LOCAL_LDLIBS +=../bin/# fill in library name here
To add downloaded libfoxit.a from step 2, fill in as:
LOCAL_LDLIBS :=../bin/libfoxit.a
If the library provide is not named “libfoxit.a” please adjust accordingly.
b) Open Cygwin (Windows), or a terminal (Linux based), and navigate to the fpdfemb_android/examples/demos/demo(like “demo_view”) directory. Run “ndk-build –B” to build the NDK/JNI layer.
Example:
me#myStation /myProjectPath/ > ndk-build –B
This assumes that the ndk directory is part of the $PATH environment variable. The command can also be qualified with the path to the NDK directory.
But then I'm getting this error in the terminal:
Android NDK: WARNING:jni/Android.mk:fpdfembedsdk: non-system libraries in linker flags: jni/../../bin/libfoxit.a
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
make: * No rule to make target `–B'. Stop.
Could you please tell me if there is any way to resolve this?
Thank you.
I recommend trying Foxit's new MobilePDF SDK for Android which will provide most of the functionality found in the embedded PDF SDK that you've previously tried but it includes a user interface and can be integrated into your Android projects quickly.
http://www.foxitsdk.com/products/mobile-pdf-sdk/
This SDK replaces Foxit's embedded SDK.
I am trying to make a Live Wallpaper for android that plays an .mp4 video located on the device in android-asset (with the example I am using, it actually copies the file to the sdcard at runtime/doesn't matter)
I found this example
And using this post I was able to get my eclipse set up with NDK and building the project.
When building in eclipse using the NDK plugin I get this error in my problems window:
Description Resource Path Location Type
make: *** [libs/armeabi/libavcodec.so] Error 1 GLWallpaperVideoDemo-master C/C++ Problem
make: *** Deleting file `libs/armeabi/libavcodec.so' GLWallpaperVideoDemo-master C/C++ Problem
I get the same error if I try to run ndk-build from command prompt.
I downloaded the project from the link above and then imported into eclipse. I added the lib GLWallpaperService to the build path, and made sure my NDK was setup. Knowing that the lib folder changed to libs I also tried moving the GLWallpaperService to the libs folder, which didn't help.
The project builds without NDK just fine in eclipse but obviously errors when trying to run the wallpaper because the native libraries were not built.
How can I resolve this error?
The package you get by git clone https://github.com/frankandrobot/GLWallpaperVideoDemo.git is Linux oriented. The file jni\ffmpeg-android\build\ffmpeg\armeabi\lib\libavcodec.so and many others are simply symbolic links to actual files.
To make this all work easily on Windows, I suggest to go to the jni\ffmpeg-android\build\ffmpeg\armeabi\lib folder, and run
del *.so
copy libavcodec.so.52.99.1 libavcodec.so
copy libavcore.so.0.16.0 libavcore.so
copy libavdevice.so.52.2.2 libavdevice.so
copy libavfilter.so.1.69.0 libavfilter.so
copy libavformat.so.52.88.0 libavformat.so
copy libavutil.so.50.34.0 libavutil.so
copy libswscale.so.0.12.0 libswscale.so
The issue might be because of a corrupted so file. Try to build the ffmpeg library again or find another version. Because I have a different error in eclipse when I try to compile the project:
C:/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-strip:./libs/armeabi/libavcodec.so: File format not recognized
And when I search for this error it seems like the error is because of a corrupted file: NDK prebuilt shared library file format not recognized
Or the library is not in a format that Android can use:
Error in linking C++ static library with android ndk(Error: file format not recognized)
I am trying to build openssl on android (got from https://github.com/guardianproject/openssl-android). need to make .so file of this and use in another android project actually. When I try to add all folders of downloaded openssl and build in prompt through ndk-build command, I get an error like this:
Android NDK: Trying to define local module 'openssl' in workspace/project/apps/Android.mk.
Android NDK: But this module is was already defined by workspace/project/apps/Android.mk.
android-ndk-r8b/build/core/build-module.mk:34:
*** Android NDK: Aborting.. Stop.
Please let me know how to build .so file!!
Please check Android.mk, which is the make file for android. I think there is a silly mistake on that file.
I followed this tutorial on raywenderlich.com and I came into a stop on the part where I need to build the native C++ libraries for Android Development.
I am using Mac OS,Cocos2d-x v2.0.1 (latest version), have my Android SDK and NDK set up, and my Eclipse (Helios) with the correct plug-ins needed for C/C++. Now I'm have trouble building the Cocos2d-x libraries for Android development. I'm using the build-native.sh tool. If I use it on the terminal like so:
xxxxx-xxxxx-imac:proj.android xxxxx$ ./build-native.sh
I get the following:
Using prebuilt externals
Android NDK: WARNING: Ignoring unknown import directory: /Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/cocos2dx/platform/third_party/android/prebuilt
Android NDK: /Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/CocosDenshion/android/Android.mk: Cannot find module with tag 'cocos2dx' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
make: Entering directory `/Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/testproj2/proj.android'
jni/Android.mk:19: *** Android NDK: Aborting. . Stop.
make: Leaving directory `/Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/testproj2/proj.android'
I looked at /Users/xxxxx/Desktop/LANCE/COCOS2DX/cocos2d-2.0-rc2-x-2.0.1/cocos2dx/platform/third_party/android/prebuilt but this directory does not exist (the platform folder is missing from the cocos2dx folder)
How do I fix this?
Thanks in advance.
EDIT: After looking through the scripts, I noticed that the cocos2dx folder in the cocos2dx root folder does not have an Android.mk file.
A re-unpacking of the Cocos2d-x ZIP did the trick. Turns out the files needed were deleted (for some reason) in the Cocos2d-x root folder.
build_native tool is obsolete now, Cocos2d-Console is used instead.