I have editted parts of the zlib-1.2.13 library to add additional functionality.
I would like to compile this library and produce a static library that I can link to as part of an android app.
I am struggling to use CMAKE to compile the static library for the correct architecture.
My question is, how do I compile and generate a static library that I can link to as part of an android app?
I saw a similar question on here that led me to try compile the library using the following command, 'CC=gcc CHOST=arm64 ./configure', then 'sudo make' on my linux VM however the static library generated appears to still be for the linux architecture.
As well as this, when I try to run the CMAKE directly through android studio, pointing the build.gradle file directly at the zlib CMAKELists.txt file directly no libraries are generated.
Any help would be greatly appreciated! :)
Related
I am working on an Android application with NDK. My c++ code has some dependencies from c++ open source libraries, so I can download the source code of the dependencies and package them in my app. I have created my CMakeList files, but I don't know how to include the external library.
I would like to build the dependency to be able to use it in my own project, so the flow would be as follows:
cd external/library/path
./configure
make
build my app and link the built dependency
Is this possible? If so, how can this be done? Sorry if this is a dumb question, I'm new on C++ and Cmake.
The way I solved this was by cross compiling the libraries and adding them as static libraries. You can cross compile using the clang binaries included in the ndk directory, using the one that targets your app min sdk.
I am trying to use webrtc in Android Studio. The file libjingle_peerconnection_so.so is put int the folder src/main/jniLibs/arneabi-v7a. But when I put in a Java file:
import org.webrtc.DataChannel;
it tells me that can not resolve "Cannot resolve symbol webrtc". Any help appreciated.
First, its armeabi-v7a, not arneabi-v7a, but that alone will not solve your problem :)
You are going the hard way, so here is a little theory:
The file libjingle_peerconnection_so.so itself is not enough to use WebRTC in Java program. At least, you need the Java JNI wrapper for WebRTC core, which provides you all necessary Java classes to work with native WebRTC code. Default wrapper is usually libjingle_peerconnection.jar, which you should put in "libs" folder on the same level as your "src" folder. So, your project tree should have these files:
src/main/jniLibs/armeabi-v7a
libs/libjingle_peerconnection.jar
Also you need to tell your build system to build the .jar in your app. In Android Studio it's usually Gradle, so just add compile files('libs/libjingle_peerconnection.jar') into your dependencies.
But there is also the easy way! Good guys from pristine.io regularly build WebRTC for Android and publish some pre-built versions to Maven repository (see here). So, you can just add compile 'io.pristine:libjingle:10839#aar' to your Gradle dependencies, and go. No need to add .so files and all that. Here is their article on that (note the outdated WebRTC version, you can use 10839, for example)
I have some C++ code (interacts with micro controllers) written already by someone else. I learnt android & NDK and comfortable writing small sample programs. Now I need to integrate both.
So, How should I start proceeding on the integration part? How does the NDK actually works? Assuming I have 3 parts now A - C++ code, B - NDK native interface code, C - Android Activity/Class .
1) Should I compile A (g++ linaro) and then place the object file in Android project to be called by C through B?
(or)
2) Should I compile the A & B together using g++ (linaro) and then copy the .so file into the Android Eclipse project? (Not sure how complex it will be to mimic NDK-build command in normal eclipse).
(or)
3) Copy A into Android Eclipse project and generate java.h file, then generate .so file using the both A & B. (In this method I need to find the right place to put the whole CPP project files in the Android/NDK eclipse project).
PS: I tried to find examples that does this, but only seem to find the simple basic examples, which I am pretty comfortable creating already. I need help in the integration part, please post me tutorial if you know (Android/NDK/Eclipse/already_existing_C++_code).
You should compile A using the Android toolchain. Note that Android supports not only ARM (a.k.a. armeabi) but also armv7a, x86, mips, and recently - armeabi-v7a-hard. Soon, x86-64 will be released.
You can compile A with Android standalone toolchain, no need to adopt the NDK build system.
You can compile B as part of A, or separately. In the latter case, simply load A before B in your Java static constructor:
{
loadLibrary("A");
loadLibrary("B");
}
because libB.so will have dependencies on libA.so.
You can pack both libA.so and libB.so in the APK (in folders libs/armeabi, libs/x86, etc.)
First of all, I recommend you to read Android NDK documents. Android.mk is not hard to write in order to compile C++ code into shared library for JNI using NDK toolchain. The most difficult part might be that Android libc (bionic) is not the same as ordinary Linux libc.
So, try to compile A - C++ code using NDK toolchain first. If you failed it, you should port it to Android libc, or you should compile it and link statically it using linaro toolchain. Take a look at the documents to link static elf library using NDK toolchain. But the binary wouldn't work on Linux because Android Linux kernel is not the same as linaro.
Anyway if you got to compile a shared library, easy to integrate it to Android project. just put the shared library to libs/[arch], like libs/armeabi-v7a/libfoo.so.
I am developing an Android application which should support Devanagari Fonts. So I downloaded indic-text-renderer and tried to run it as per the instruction stated here and managed to successfully compile the NDK part.
But when I try to run the Android project on a gingerbread emulator I get following error
java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1311]: 33 cannot locate 'hb_buffer_create'...
I tried many solution but none of them helped me.
How can I fix this?
Has anyone used indic-text-renderer in Android successfully?
If yes, please help me and provide a complete Android project (if possible) as I am trying to install and compile this library. It needs to make, javah, autoconfig and many more...
I had the same problem. I managed to solve it by statically link harfbuzz to my ndk library. So try to statically link harfbuzz to your ndk lib.
e.g. in CMake:
add_library(harfbuzz SHARED ...)
to
add_library(harfbuzz STATIC ...)
I want to cross compile a c++ library to the android plateform and this library depends on other libraries (those librairies are included yet in the android plateform).
Actually ,i have downloaded the android source code (android 4.1), i have also the library source code and i just don't know how to cross compile this library with it dependencies?
I would be thankfull if someone can tell me the right way to do it.
I believe that the easiest path is to set up the standalone toolchain using latest Android NDK, and build your library and all its dependencies with that toolchain. Here is an example: http://trac.osgeo.org/gdal/wiki/BuildingForAndroid