android how to make native zip application - android

I would like to create a zip file from files located on the sd card, I have managed to do that using java but I think that the result is too slow, so I thought of going native using the android NDK.
My questions are:
Does anyone know any C/C++ library to zip unzip files that will work on android?
How to know if the library will work on android?
Will this make any difference on performance?

With regard to your question "How to know if the library will work on Android" - it depends on the dependencies that the library has. The standard google NDK has very limited C++ support. If it's written in C you're probably OK, but if it's C++ you need to make sure it uses ONLY the following headers/libraries:
libc (C library) headers
libm (math library) headers
JNI interface headers
libz (Zlib compression) headers
liblog (Android logging) header
OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers
libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).
A Minimal set of headers for C++ support
(From homepage)
If you need full C++ support, you will need to use the Crystax NDK.
Be forewarned - the process of cross compilation is Very. Complicated. If you're not extremely comfortable on the command line and with the ins and outs of C compilation, linking, etc., I would look for an alternative solution.

I personally like 7zip, they are open sourced here. You can try compiling this within your app in Android NDK. gzip is also another good option.

Given how core zip files (apk files, jar files) are to android, I'd be very surprised if the java zip file functions aren't using native implementations of the actual algorithms.
Remember the SD card itself is slow compared to ordinary disks.

Related

JNI without C++ source file

I am working on a Android APP project with JNI. I have some source of the project, but i only have .so file and the .java file of the source. How can i use the JNI function without the C++ source file?
If you have the Java class that interfaces this .so, you don't need C++ sources to use it. You can even change the native methods from protected to public, if you need, or add in Java wrapper methods that can make using the native methods easier.
Speaking of Android, make sure that your .so file matches the platform (e.g. you cannot use an x86 library on ARM devices). Your .so must have been compiled with a compatible toolchain (e.g. you cannot use Linux compiler). And if your .so was built for certain platform, it may fail to load on older devices: NDK platforms are compatible forward, not backwards.

Make a library that is statically linked

So , I have installed Ubuntu(but still use the Android kernel) on my Android phone with the intention of using it to compile native code for the device using the glibc.
I made a library, which I plan to use it in an app which I want to make, using JNI, but I am using the math library. My question is:
Is there a way to include these libraries into the library that I
created so that my phone can use the glibc library instead of the
bionic(which is what the NDK uses) library?
NOTE: I have tried making a test program that uses the library and statically links to make sure that the compiled code would work on the android OS and not just Ubuntu, and I came to the conclusion that it does :) So any answer pertaining to my question would be a great help.
You can use ar to extract the original .o files from any .a files:
ar x libm.a
You can then select whichever .o files you like and link them into your own code.
.a library files can be viewed as tar files with extra symbol-index features (although I don't know how similar the internals are).
WARNING: in general, you can only use .o files from static libraries in your main application. If you try to link them into a shared library (.so file) you may be out of luck. The .o file needs to have been created with -fPIC for that to work, and this is often not the case for static libraries.

Code to display all exported functions by a shared library in Android

I want to write an Android application that is able to display list of exported functions by a shared library (.so).
nm/objdump/readelf tool is only available for Windows/Linux. So I have thought about compiling platfor_external_elfutils to get a toolchain with nm or objdump tool.
However, this is not a good solution considering the big dependencies the toolchain may cause (can be up to xx MB).
I want to ask if there is any available simple code to achieve the purpose without having to compile and attache the whole toolchain in my app.
This is probably too late for the original poster, but libelf can be built as a static library (libelf.a) from Android sources, at least since JB4.2. Just use
make libelf
In the main directory to build it.
If someone knows how to build it as a dynamic library/shared object that would be much appreciated.
You can use libelf library (from elftoolchain - it's BSD licensed) to parse the binary. libelf comes with source for elfdump utility that dumps various information about ELF file including export list. Just strip out the source you don't need and you're ready. Executable for this won't take more than 100KB.

Best way to build complex native + java libraries with Android SDK+NDK

I am building a multi-platform SDK for real time 3D applications. This SDK is programmed in C++ and works under Windows, Apple's iOs, MacOS, Linux and Android.
The project structure is complex, it consists in 3 native C++ static libraries, linked with some external static libraries in a complete shared library. This is very simple under all the managed OSes, except for Android.
The major problem in Android is bi-directional communication/calls between native code and Java code. I got this solved some time ago using SWIG to wrap the shared library's classes. To achieve that I wrote our my own build scripts (Makefiles) to handle native compilation with the ndk r4, swig code generation, java pre-compilation and jar creation.
Lately we added some callback/listener classes in the C++ layer, that we wanted to be derivable/overloadable in Java, for this we used SWIG's directors feature. But it appears that it needs JNI features (weak global references) that were not in the NDK r4b. So we need to switch to a newer Android NDK (r6b) that has these features. But since our custom build scripts were written for NDK r4b they won't work anymore.
My concern is to have everything built properly through Android's NDK/SDK (eventually through Eclipse) with Android.mk files so we don't have to rewrite everything from scratch each time we switch to a new NDK.
I'd like to know if there is a way to manage such complex project structure with standard Android.mk, ndk-build, ant and eclipse (including the SWIG part). And if so, how ?
Don't hesitate to ask for precisions, I am not sure I am being really clear.
Any help greatly appreciated.
Florent Lagaye.
I've been looking for a similar thing and, although I haven't figured it out yet, there is a good example with building gstreamer on Android.
http://cgit.collabora.com/git/user/derek/androgenizer.git/
It supposedly works with any libtoolized application.
Here is the directions for how to build:
http://gstreamer.freedesktop.org/wiki/GstreamerAndroid_InstallInstructions
What we ended doing is writing specific rules in the Android.mk file to manage swig interface generation.
Remember to add the generated c++ source to the list of source files before including BUILD_STATIC_LIB or BUILD_DYNAMIC_LIB, and to instruct swig to generate the java source in folder accessible by your Android java project.

Libraries available on Android NDK?

Are there any libraries available by default in the Android NDK? If not, can I use any c++/c library, as long as I include it myself?
In particular, I need compression, encryption, regex and sqlite. I was thinking of using zlib, crypto++, sqlite(duh!) and boost, but can use anything else if it is already available.
Also, if nothing is available built-in, would you recommend something other then my above choice (I prefer public-domain when possible, or BSD or similar)
SQLite is available on Android via abstracted database access in Java. The ‍.so itself is private. You can of course compile your own SQLite library if you require modifications, but in general you should access it from Java. I have done this for encryption purposes.
zlib is available to the NDK
crypto++ could of course be compiled via the NDK
Boost certainly works on Android/NDK (I'm currently using it heavily)
By default Android NDK delivers some libraries, so called 'stable native APIs' (http://developer.android.com/sdk/ndk/overview.html):
libc (C library) headers
libm (math library) headers
JNI interface headers
libz (Zlib compression) headers
liblog (Android logging) header
OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers
libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).
A Minimal set of headers for C++ support
OpenSL ES native audio libraries
Android native application APIS
First, I think you need to download the NDK package from here: http://developer.android.com/sdk/ndk/index.html and investigate the documentation from the package. I'm sure you will get the answers to most of your questions.
And quick answer to your questions. Yes there are libraries by default in the Android NDK. For example standard C and C++ libraries.
This is only a partial answer with respect to Crypto++....
Crypto++ has a wiki page with build instructions from the command line at Android (Command Line). The process will create the various libraries and show you how to build cryptest.exe to verify the library on a device. But you will still need to create you wrapper project using Android's build system.
Piotr Morgwai Kotarbiński has a page on building the Crypto++ library with Android's modified build system. See Building Crypto++ with NDK toolchain. I don't believe Piotr's article verifies the library on a device.

Categories

Resources