Android Bionic and Libc libraries - android

I want to create small command interpreter for android (shell). It should perform only few features : 'scanf','printf','cd', 'pwd', 'echo','set', 'unset', 'exit' and should support internal path variables : 'path', 'home', 'status'.
Is it possible to fulfil this using Native Android Kit and bionic library.
I would be grateful for any help.
Thanks in advance.

Yes, you should just create an executable program binary with the NDK (e.g. use 'include $(BUILD_EXECUTABLE)' instead of 'include $(BUILD_SHARED_LIBRARY)')

Related

Unity: DllNotFoundException (Unity 2018.2; Android)

I have an Android native library (C++ code base) called:
libserverapp.so
And I cannot get the Android build to find it:
"DllNotFoundException: serverapp"
I am using an internal build system, but when I parse the output of the build process, I can see many calls of the form:
android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++.exe -march=armv7-a
After building my Android app, I inspect the resulting APK (renaming to .zip and extracting), and can see my library file here:
lib/armeabi-v7a/libserverapp.so
I can confirm that "ARMv7" is the target architecture in the Android Player settings, and I access the library, in C#, via:
[DllImport("serverapp", CallingConvention = CallingConvention.Cdecl)]
private static extern void run_sim(StringBuilder matchInput, StringBuilder results, int randomSeed);
I have built a Windows DLL of the C++ code, to use in the Editor, and everything works great. However, when I move to Android, the .so cannot be found. The import settings for libserverapp.so are:
Platform: Android; CPU: ARMv7; Path: Assets/Plugins/Android/libserverapp.so; Type: Native
Given that the final APK includes the .so where I expect it to be (lib/armeabi-v7a/), I assume my Unity settings are correct? Also, I am not using IL2CPP for the Android build.
Finally, when I do an object dump of the library file (using arm-linux-androideabi-objdump.exe), the file format of the library file is "elf32-littlearm".
I feel that the issue here is simply finding the .so, not the functionality within it. Any ideas on what's going on here?
Thanks!
I ended up solving the problem. I mentioned that was using an internal build system. Well, there seems to be a bug in it. I ported things over to official Android NDK makefiles, and then it "just worked". So in this case, the library could be found, but its contents weren't valid.

How to use Tensorflow for Android in Qt (QML) app?

Context
I work on an app for Android which should analyse in real time the camera input.
I chose Qt to develop the user interface, for portability reasons (the app may evolve to support other platforms than Android).
For image processing, my colleague is working on it using TensorFlow.
So I want to know how could I use TensorFlow for Android in Qt ?
What I've done :
Downloaded tensorflow the nightly precompiled version (#453) from http://ci.tensorflow.org/view/Nightly/job/nightly-android/lastSuccessfulBuild as suggered at https://www.tensorflow.org/versions/master/mobile/linking_libs#android (option 2)
Put the files in my qt project android/libs folder
Modified my *.pro file to add :
the given *.jar file with : DISTFILES += android_v453/libandroid_tensorflow_inference_java.jar
the given *.so file with : ANDROID_EXTRA_LIBS = $$PWD/android/libs/armeabi-v7a/libtensorflow_inference.so
But for now I'm confused. How should I call it in my Qt App ?
Note : I just noticed that TensorFlow Android interface is aimed only at inference, so no training would be available. (source)
Well, I think I figured it out !
The QAndroidJniEnvironment & QAndroidJniObject classes from Qt AndroidExtras seems to do all the big work.
Sample instanciation code:
QAndroidJniObject graph ("org/tensorflow/Graph");
QAndroidJniObject inferenceInterface("org/tensorflow/contrib/android/TensorFlowInferenceInterface", "(Lorg/tensorflow/Graph;)V", graph.object());
I know this works because tensorflow now logs data to the Qt console.

Compile and use boost for Android NDK R10e

How do I compile and use Boost for the Android NDK? I've tried everything I've found online, from Boost for Android to compiling it myself with the bjam file. However, I do not succeed. When I try compiling it with bjam, I get the following error:
error: toolset gcc initialization:
error: version 'androidR10e' requested but 'g++-androidR10e' not found and version '4.2.1' of default 'g++' does not match
error: initialized from /path/to/android-ndk-r10e/sources/boost/tools/build/v2/user-config.jam:86
Has anyone successfully used Boost with Android NDK R10e?
And when I can compile it, how should I do to use it in my Android app project?
We managed to compile it for NDKr10d. It should be the same for NDKr10e.
The project-config.bjam should point to the gcc compiler from the NDK. Ours looks like this :
import option ;
using gcc : arm : D:\\android\\ndk\\toolchains\\arm-linux-androideabi-4.9\\prebuilt\\windows-x86_64\\bin\\arm-linux-androideabi-g++.exe ;
option.set keep-going : false ;
Then just compile with b2, telling paths to android includes :
b2 --reconfigure <your options>
toolset=gcc-arm
include=<ndk folder>\sources\cxx-stl\gnu-libstdc++\4.9\include
include=<ndk folder>\sources\cxx-stl\gnu-libstdc++\4.9\libs\<target platform>\include
include=<ndk folder>\platforms\<android api version>\arch-arm\usr\include
install --libdir=stage\lib\<target platform>
We're about to move to ndkr10e. Could you tell if boost still works with it ? :)
The simplest way would be to use CrystaX NDK, which contains already built and ready-to-use Boost libraries. And here are examples how to use Boost with CrystaX NDK: 1, 2
Following the boost directions, I was able to build boost 1.60 with NDKr10e on Ubuntu 12.04 (although I suspect very little depends on the host system). Here are my notes:
get and unpack boost source tarball (i used 1.60): boost_1_60_0.tar.bz2
moskewcz#maaya:/scratch/moskewcz/android/src$ ll
total 74M
drwx------ 10 moskewcz moskewcz 4.0K Mar 9 14:14 boost_1_60_0
-rw-rw-r-- 1 moskewcz moskewcz 74M Jan 5 11:15 boost_1_60_0.tar.bz2
follow boost instructions in getting started on unix "Build Custom Binaries" section
use a fresh, empty root to install b2 i.e. /scratch/boost-build-root; use usr as prefix; again following the boost instructions:
moskewcz#maaya:/scratch/moskewcz/android/src/boost_1_60_0/tools/build$ ./bootstrap.sh
moskewcz#maaya:/scratch/moskewcz/android/src/boost_1_60_0/tools/build$ ./b2 install --prefix=/scratch/moskewcz/android/boost-build-root/usr
put b2 in path (again as per instructions)
export PATH=/scratch/moskewcz/android/boost-build-root/usr/bin:$PATH
in some jamfile (i had no ~/user-config.jam, so i created one and used that, maybe there's a better choice of jamfile to create/edit) add some jam-code (?) to define a gcc version (toolset) pointing to a g++ from a standalone toolchain. note that this is a toolchain created with the NDK in the normal fashion following its 'create a standalone toolchain' directions. i am NOT pointing to a g++ inside the NDK itself (that may or may not work, i dunno):
import option ;
using gcc : arm_linux_android_4.9 : /scratch/android-stc/bin/aarch64-linux-android-g++ ;
option.set keep-going : false ;
go to boost project root and build, mostly as per directions. --build-dir may be optional? also added -j8 to do || build
moskewcz#maaya:/scratch/moskewcz/android/src/boost_1_60_0$ b2 -j8 --build-dir=bin.v2 toolset=gcc-arm_linux_android_4.9 stage
note that this tries to build both static and shared libs by default, but building shared libs fails due to android not having librt.so -- according to my research, people claim that under android (some of?) the functionality of librt.so is inside libc.so -- so it may be okay to simply remove -lrt from the linking steps in order to build shared libs for android. i did not attempt this. see:
https://code.google.com/p/android/issues/detail?id=5730
Building Boost for Android with error "cannot find -lrt"
I only managed to build with 10d. Cross compiling Linux->Android using Boost for Android worked straight away with that.
To download a slightly outdated ndk, as not all ndk are immediately supported by Boost for Android, you can use this guide: Where do I find old versions of Android NDK?
Note: I also wanted to specify the toolchain. I had to do it in 2 places:
In build-android.sh, just after the line mentioned here above:
TOOLCHAIN=${TOOLCHAIN:-arm-linux-androideabi-4.9}
In the command line
bash build-android.sh [ndk location] --toolchain=arm-linux-androideabi-4.9
In fact, it worked better when I specified exactly which boost components I wanted with --with-libraries=[comma separated list].
If instead I would build everything, I would get:
...failed updating 38 targets...
...skipped 6 targets...
...updated 10568 targets...
ERROR: Failed to build boost for android!
Done!
Here: http://silverglint.com/boost-for-android/ you can find a simple and painless new way to build a modern (eg 1.64.0) version of boost for android.
Works with clang and gcc.
Also included is a sample app that shows you how to use the boost binaries thus built.

Compile linux tool perf for android

I want to compile pref for android device and i did that base on the guide the guide. One i set NDK environment use Android NDK r9
export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-
export NDK_SYSROOT=${NDK}/platforms/android-9/arch-arm
I run make with tool
make ARCH=arm CROSS_COMPILE=${NDK_TOOLCHAIN} CFLAGS="--sysroot=${NDK_SYSROOT}"
I recieve the error, so can you help me?
Android NDK: NDK_TOOLCHAIN is defined to the unsupported value android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-
Android NDK: Please use one of the following values: arm-linux-androideabi-4.6 arm-linux-androideabi-4.8 arm-linux-androideabi-clang3.2 arm-linux-androideabi-clang3.3 mipsel-linux-android-4.6 mipsel-linux-android-4.8 mipsel-linux-android-clang3.2 mipsel-linux-android-clang3.3 x86-4.6 x86-4.8 x86-clang3.2 x86-clang3.3
build/core/init.mk:555: * Android NDK: Aborting . Stop.
Android bundles the simpleperf tool which is almost a drop-in replacement for many usages of perf/linux-tool-perf.
https://developer.android.com/ndk/guides/simpleperf
Have you looked at external/linux-tools-perf/ inside android repository?
https://android.googlesource.com/platform/external/linux-tools-perf/
the error clearly says , you need select appropriate value while exporting ,
export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-
should be
export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-4.6
If it dosen't work , i recommend you recheck the overall path which $NDK_TOOLCHAIN contains.
Thanks , Jain

Issue with Uncompressing the .7z file in the Android evn

Getting "system.entrypointnotfoundexception: loadlibrary" While trying to use SevenZipLib.dll to uncompress the .7z file containing media contents/file in the Android evn.
Context:
-The whole program is written in c# as a MONO Android Project. No Build/Deployment Error/warnings.
While running the apk, its throwing "system.entrypointnotfoundexception: loadlibrary".
-Also tested the same code as windows project (not mono) - uncompressing in the windows evn.
Assumptions for the issue:
7zip internally might be using COM components & Mono frame work is not supporting.
Question:
Has anyone come across similar issue? Please suggest some alternative dll/framework which can be used by my apk for uncompressing the .7z file.
Assuming that SevenZipLib.dll is the SevenZipLib Library on CodePlex, the problem is SevenZipLib\SevelZipLib\SevenZipArchive.cs:
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern SafeLibraryHandle LoadLibrary(
[MarshalAs(UnmanagedType.LPTStr)] string lpFileName);
The project contains numerous P/Invokes into kernel32.dll (LoadLibrary(), GetProcAddress(), FreeLibrary()), ole32.dll (PropVariantClear()), oleaut32.dll (SafeArrayCreateVector()), and more.
In short, this library is intimately tied to Windows, and isn't going to work on a non-Windows platform in any meaningful fashion, not without a lot of work.
If you need 7z support in a Mono for Android application, you'll need to look into a different library. It looks like the 7-zip SDK includes C# source for reading LZMA files that doesn't rely on P/Invoke, so perhaps that would work?

Categories

Resources