I am trying to deploy a Qt app to an Android device, though I receive the error about missing stdlib.h. I found out that this library is actually inside sub directory tr1 of includes. I modified the include<stdlib.h> to include<tr1/stdlib.h>. After this I encountered the error for locale.h. This files doesn't seem to be present anywhere in the NDK.
The app works fine if build for Desktop as the Linux GCC has all files in proper hierarchy.
Any fixes?
Finally, I resolved the issue. It was just the wrong Android NDK build I downloaded. My system architecture is x86_64 and the Android architecture is x86. The build I downloaded was that x86_64 Android. Make sure when downloading the target platform is your Android architecture.
Also, one might find several solutions recommending to create stand-alone build using make-standalone-toolchain.sh script and setting CXX home to this build and as well as set "sysroot". Please do not do it. It's not at all required. Just set the NDK path from Android option from Qt itself. That shall be enough.
Related
I am trying to integrate Boost.Log in a QT/QML project that has to work on Windows, Linux and Android. While Win32 and Linux versions work like a charm, Android is giving me a few headaches.
I was able to build Boost library following instructions at https://github.com/moritz-wundke/Boost-for-Android.
However,
If I link my application statically to boost libraries, I get a bunch of linker errors, complaining that symbols are not found. Error messages are like: "error: undefined reference to 'boost::log::v2_mt_posix::core::get()', I get ~60 of them and I checked many times the file paths
If I link dynamically to boost, I can successfully generate my APK (the relevant .so files are included) but it crashes upon startup, both on a real device and on Android emulator
I'm new to Android development so it's entirely possible that I'm missing some key step here and I'm not really sure on what information may be relevant to provide here. Hope that someone can help.
I tried building with both ndk 20 and 21, Boost 1.70, Android SDK 26.
I plan to use QT 5.12 but did not add any QT code yet. I used QT Creator 4.10.2 (Windows) and 4.11.1 (Linux)
So i am try to build openSSL into my qt android app. and to all my efforts from using precompiled binary to installing ubuntu 18 and still failing i am getting desperate.
I have read from this thread:
QT + OpenSSL + Android
that i can get them from ANY existing apk, so how do i extract it from the apk? Because i do not find it in the android ndk and sdk. if its only selected apk, what program do i use indor for me to see it.
im using Qt 5.11 on windows, but i have linux OS too if needed :) Thank you!
I've built OpenSSL for android a few months ago, with zero issues. Just follow this guide for Linux:
export ANDROID_NDK_ROOT="/home/dev/android-ndk-r12b"
SR="$ANDROID_NDK_ROOT/platforms/android-16/arch-arm"
BR="$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-"
RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armeabi --prefix=$SR/usr --sysroot=$SR
ANDROID_DEV=$SR/usr make
make install
Obviously, you will have to replace the paths with your own depending on where and what NDK version you install, and you will already have downloaded and extracted the OpenSSL source. Also, keep in mind that Qt doesn't seem to work with the latest and "greatest" android toolchains. In fact, android has already switched to llvm, but for Qt you will need to use the older gcc toolchains.
You can use this script to build libcrypto.
There are many prebuilt binaries you can get online, without having to rummage about in apk files, for example this repo has openssl libcrypto for a bunch of platforms, including android.
Don't know where you got the idea that you could get the libs from any apk file, obviously, it has to be a package from an application that incorporates those libraries for dynamic linking.
Last but not least, if you still plan on getting pre-compiled binaries, keep in mind they have to be built with a version that is compatible with your compiler. Which is why it is best to build the libs yourself, with the same toolchain you are using for your application. There is also the danger of getting "bad" libs from an unknown source, they might be outdated or tampered with.
You can open them by simply changing their extension to ".zip" :) will update if i can find apps that has these files.
PS: No all apk has libcrypto.so and libssl.so.
I'm trying to figure out how to integrate my native lib into android code. I create a simple C++ function and it's work fine when running code on device. However my current goal is to make it work in unit-test env (junit), and I faced with problems:
So, in unit-test env System.loadLibrary("lib") not working, and I cange it to
System.load("/full/path/to/lib.so"), but now this line throw an exception:
java.lang.UnsatisfiedLinkError: app\build\intermediates\cmake\debug\obj\x86_64\liblib.so: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
Path is correct and there is a file by this path exists.
I tryed to use path to x86 based version of lib, but it's still throw the same exception.
I'm using latest Android NDK, Clang toolchain, running unit-tests on Windows 7 64 bit based laptop, CPU is Core i7, and java version in runtime also seems to be 64 bit.
So what could be the problem in this case and how to fix it?
I have a feeling that even having in mind fact that clang compile x86/x86_64 *.so files, they are still invalid in windows based env, but I don't have linux installed to quickly check this idea.
It can be obviously, but this message tells that your *.so library depends on some others libraries which are not presented on target platform (on android in your case).
Probably, your library using some thing from Windows API. I suggest to detect bad dependencies using tools like Dependency Walker
I'm trying to install some python packages (pillow) for QPython on Remix however I get the error that arm-linux-androideabi-gcc does not exist.
I googled and I think I need NDK, however looking at the website (https://developer.android.com/ndk/downloads/index.html) I couldn't find a way to do this on android.
Any help is much appreciated, thank you!
Installing the NDK on Android? As in running the NDK compilers on an Android device? We don't support Android as a host OS for the NDK.
Check out AIDE android ide from the Google playstore
Despite Dan's answer, which I respect. It's not entirely accurate. The Android ndk build system doesn't allow for for host to be set to the $TARGET_ARCH, but building it manually in much the same way you would for any custom toolchain is entirely possible.
I should note that I have only done this for gcc, and have not attempted to do so with clang.
From Googles ndk toolchain repo just take the essentials needed, gcc, binutils, gmp, mpfr, etc and set your host and target to the ndk toolchain gcc. Use the ndk sysroot as build-sysroot, and then just add your compiler flags and with a little fiddling you should get it.
Id be happy to post more, it's been a project of mine to build Android on Android, also i highly recommend adding static versions of the ndk libs, as the android system doesn't have a c++ lib, and a few others. You may have to build some manually using aosp build system
I built it with stage-one flags so that the binaries would be static, as you never know when android might remove a lib that your toolchain depends on.
I encourage you to try, as an added benefit you will then he able to build many useful android native binaries that usually aren't available without editing the aosp source. Also having the ability to build binaries on the fly is very useful
I've been running the Android SDK for a while now in Eclipse (MAC OSX). I've downloaded the NDK and installed the C/C++ tools in Eclipse, but could anyone guide me on using the NDK? For example, do I just create an Android project like normal and build it with the NDK instead?
Really could do with a decent tutorial if anyone know of any.
EDIT: OK so I have the NDK installed now (I think) but does anyone have any idea how to use it? I got as far as this (taken from here):
Run Terminal
cd ~/android-ndk-1.5_r1
make APP=hello-jni
In order to run the hello-jni sample application, but I get an error in terminal saying:
Android NDK: APP variable defined to
unknown applications: hellojni
Android NDK: You might want to use
one of the following:
build/core/main.mk:81: *** Android
NDK: Aborting . Stop.
Any ideas why?
As simply as I can describe it, building an Android app from within Eclipse that uses the NDK requires two steps.
First, inside your terminal you need to run the NDK build script on your project. cd into the root of your project directory and then execute the ndk-build script within that directory.
For example:
cd ~/workspace/hello-jni
./~/android-ndk-1.5_r1/ndk-build
After doing this, you should see some output that results in the creation of a *.SO file within the obj directory within your project directory.
Once you have the *.SO file, the final step to building an application with the Android NDK through Eclipse is to build it with Eclipse like you would any other application and then deploy it for testing.
If you make any changes to the C/C++ code you'll need to repeat step one and regenerate your *.SO file before building and deploying your application from within Eclipse again.
I would like to note that by using the Android NDK your android apps are still based upon Java. They're just communicating with code written in C/C++ by way of the Java Native Interface.
Finally, I am not aware of any Eclipse plugins that will aid with NDK development. Everything I know about the NDK I have learned the official Android NDK documentation. Please feel free to comment and let me know if there anything I can clear up in my response.
Native development and debugging support came into Eclipse environment as of ADT version 20. http://tools.android.com/recent/usingthendkplugin
Set path to NDK from Eclipse Preferences -> Android -> NDK
Right-click on your project and choose Android Tools -> Add Native Support
developer.android.com states you also need Cygwin.
http://developer.android.com/tools/sdk/ndk/index.html#Contents
Required development tools
For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.
A recent version of awk (either GNU Awk or Nawk) is also required.
For Windows, Cygwin 1.7 or higher is required. The NDK will not work with Cygwin 1.5 installations.
The docs directory in the NDK has some pretty good information on how to use the NDK itself. Read the overview, Application.mk, and Android.mk HTML docs. You'll want to google for the Sun JNI PDF, download it, and learn what JNI is all about before you go any further. This is because simply compiling a bunch of C/C++ code into libraries with the NDK is only part of the process. You have to write native Java code that calls your C/C++, and you have to create wrapper functions in C/C++ that adhere to JNI conventions that the native Java code can invoke. JNI has been around a long time, it's not Android specific by any means. So, you can, to learn about it, go quite far following tutorials geared towards JNI, using command line tools like javah and javac, and then return to integrating with the NDK after you know the basics. (For an example of what these C shims look like, take a look at the hello-jni sample in the NDK; the C source file there shows you typically what the shims look like. Using javah to generate these shims is the way to go, you create Java classes that have native methods, process them with javah, and it generates the C headers for you, then you code up C functions that adhere to the generated function prototypes).
Note: while the NDK docs would have you manually building from command line and then going into Eclipse to build your app (a laborious sequence of steps, to be sure, especially if you are changing the C/C++ code), it turns out you can integrate easily with Eclipse so that the NDK is run each time you build from Eclipse. To see how, read here.
This is for benefit of others who want to create the project from scratch from within eclipse: I followed steps mentioned here in this blog here and it works fine: http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/
To attempt to answer the question directly - you need to run ndk-build in the folder with the native code within your project folder. This creates the .so files found in the file explorer/resources tree under jni in Eclipse. These functions, if the syntax in the code is correct, can now be called from your java code.
I found many sources of help when install and getting to grips with Android Developer Tools and the NDK. I wrote a blog post to share my experiences and hopefully give back to the community that helped me get there which may help understand my answer: http://workingmatt.blogspot.co.uk/2013/03/set-up-android-sdk-and-ndk.html