"manual" cross-compilation from Linux/x86-64 to Android/ARM? - android

(Perhaps a border-line question on S.O since I am not showing any source code!)
I want to be able to cross-compile (using the latest GCC trunk, i.e. 4.9) a hello world program in C, compiled on Linux/Debian/Sid/x86-64 for Android (4.4.2 on a rooted Nexus 7), and to be executed in an Android terminal emulator. My goal is to learn how to configure the entire cross-tool chain, probably GCC, binutils, and MUSL libc. So I specifically do not want to use any SDK or NDK for Android!
I guess that my Android is an arm-linux-gnueabi GCC 4.9 primary target platform for GCC & binutils. Is this correct?
Then once I compiled my (statically linked with MUSL libc) hello world, how should I transfer it on the tablet? (MTP probably).
PS. I am quite familiar with Linux (and GCC, to which I contribute, and binutils) but I am a complete Android newbie.
PPS: The real motivation is that I want to compile a plugin for a GCC cross-compiler, preparing a talk about GCC plugins

Related

Building Qt 5.12 LTS for Android with SSL and SQL support

With google deprecating GCC, Qt 5.12 for Android makes a transition away from it in favor of Clang. Which renders the existing building guides obsolete, as they are all GCC based.
The stock Qt build for Android is lacking some important functionality, and furthermore, the related documentation seems to be fairly outdated.
Additionally, 5.12 launches with a critical Android related bug, which pretty much mandates a custom build to incorporate the fix for the time being.
I myself haven't previously used Clang at all, and I am one of those people who really prefer to just make applications rather than to go through the often excruciatingly frustrating experience of trying to build the requisite tools.
Qt on Clang is here to stay, and 5.12 being a long term support release, I think a detailed step by step guide how to produce a working Qt build will be of benefit to a lot of people. It would definitely save me days of headaches and setbacks, and so I am willing to offer a generous bounty to the first reproducible answer, in addition to any bounties that may be required to promote the question visibility.
My personal requirements are SSL, MySQL and PostgreSQL support, although additional functionality is welcome. It would seem that a Linux based guide will be the most beneficial format, as it is also applicable to windows via MSYS.
I can't reply for all your requests, but I can say something about openssl:
Firstoff, even with Qt 5.12, if you are using the official android builds downloaded from Qt itself (via the Maintenancetool), then you still have to use the gcc toolchain and openssl 1.0.2. The Qt builds require 1.0.* and clang support has only been added to openssl since 1.1.1. Support for this version of openssl will hopefully come with Qt 5.13. See QTBUG-71391 for more details.
That beeing said, if you cross-compile Qt for Android yourself (or visit this post in the future, when Qt supports this), you can use openssl 1.1 and use clang to compile it.
The steps are documented on their github in NOTES.ANDROID. The steps are relatively straight forward and boil down to a few changes to PATH in order to build the library. A basic script, with switches for all android architectures provided by Qt, would be:
TOOLCHAIN_VERSION=4.9
HOST_ARCH=linux-x86_64
case "$ANDROID_TARGET_ARCH" in
arm64-v8a)
API_VERSION=21
ARCH_ID=android-arm64
TOOLCHAIN=aarch64-linux-android-$TOOLCHAIN_VERSION
;;
armeabi-v7a)
API_VERSION=16
ARCH_ID=android-arm
TOOLCHAIN=arm-linux-android-$TOOLCHAIN_VERSION
;;
x86)
API_VERSION=16
ARCH_ID=android-x86
TOOLCHAIN=x86-$TOOLCHAIN_VERSION
;;
*)
echo "Unsupported ANDROID_TARGET_ARCH: $ANDROID_TARGET_ARCH"
exit 1
;;
esac
export ANDROID_NDK=/path/to/ndk
export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_ARCH/bin/:$ANDROID_NDK/toolchains/$TOOLCHAIN/prebuilt/$HOST_ARCH/bin:$PATH
./Configure $ARCH_ID shared no-ssl3 -D__ANDROID_API__=$API_VERSION
make SHLIB_VERSION_NUMBER= SHLIB_EXT=.so build_libs
In this script, ANDROID_TARGET_ARCH is simply the value of the qmake variable with the same name, so this script could be invoked by qmake. The steps that need to be done in detail are:
Prepare some variables:
TOOLCHAIN_VERSION: Simply the version of the gcc toolchain to be used (yes, this is still needed, as some tools, linke ranlib etc. are still used from there). As of NDK v18 the toolchain version is still 4.9
HOST_ARCH: The architecture of the host system. The sample sets this to linux. If you are on window/macos adjust this accordingly.
API_VERSION: The Android SDK version openssl should build for. I set the values to the version that Qt uses for builds for these plattforms, but other versions should be fine as well
ARCH_ID: The name of the android architecture as used by openssl
TOOLCHAIN: The name of the gcc toolchain to be used
Ensure the ANDROID_NDK environment variable is set to wherever you installed the NDK
Update the path to contain both, the clang/llvm toolchain and the gcc toolchain for your specific plattform. In the script, the locations of the toolchains are derived from the previous variables
Explicitly run the Configure script - and not config. Pass the target architecture and additional flags. (I for example prefer to disable ssl3 for security reasons)
Run make to build the library. The SHLIB_VERSION_NUMBER= SHLIB_EXT=.so part is needed to ensure that the binaries created do not have a version number as part of their name, as android does not support that.
And thats it!

Is it possible to generate a dll with android ndk for testing purposes?

I am developing an app which uses a native library. I would like to test it using a non-android dependent framework like Robolectric.
The problem is, that the native functionality cannot be loaded using
System.loadLibrary("mylib");
because on Windows it looks for "mylib.dll", and I am only able to build libmylib.so which is not compatible with windows.
Is there a way to build a dll (it would be only used for testing purposes ofc)?
If you want to test your application on windows, then you need a *.dll. *.so files are unix "shared libraries" - same functionality as windows' dll.
You have to build your C++ sources with an IDE like Visual Studio, Code Blocks, or anything else that can build sources for windows.
In fact, when building with "ndk-build" for android, you are cross-compiling for an Unix system with an ARM architecture mostly.
When running on windows, you'll probably be on x86 / x86_64.

Deploying PyQt5 application to Android via pyqtdeploy and Qt5

Is it possible? I mean, yeah, pyqtdeploy intro page said: "pyqtdeploy is a tool for deploying PyQt applications. It supports deployment to desktop platforms (Linux, Windows and OS/X) and to mobile platforms (iOS, Android and Windows RT)."
I've installed Qt 5.3.0 for Android and all it's prerequisites (SDK, NDK, etc.). Also I made test project with simple button and label in QtCreator for testing deployment. Everything is fine. Next step was trying pyqtdeploy for making Qt project, pretty simple. But when I'm trying to build this project, linker said that there is no QtCore, QtWidget libraries. As I can recognize it, I've no static-linked PyQt libraries and that they must be compiled for arm architecture. Is it right? But then I've realised, that python library itself also must be arm compiled. And can I build this libraries from source in Qt?
Search did nothing. If this is true, why no one (riverbank, python) have no compiled libraries for arm?
Maybe I'm missunderstood something. In this case I got more global question.
How to deploy PyQt5.3 Python 3.4 application to Android with pyqtdeploy and Qt 5.3.0 for Android?
Wait for the next release of pyqtdeploy, which will probably give better instructions or include cross-compiled libraries. The pyqtdeploy project is being actively developed. Yes, you can use it for Android now, but you are on your own for cross-compiling many static libraries.

Ocaml and/or Haxe on Android?

I have not found much helpful information through my Web-searching and email-asking. I would like to compile Haxe on an Android device using a fully-functional Ocaml Android port. Binaries are available for Linux, Windows, and Macintosh, but all are x86. I have heard that Ocaml can cross-compile to ARM or something, but Android support was dead. Is that true? What has changed since 2012? I have Terminal IDE installed, so in theory it is possible for me to run command-line apps on my device. This should be sufficient for Haxe, but as an Ocaml program I assume that such would necessitate Ocaml's Android native code generator working flawlessly. Please fill me in on this, as I cannot find conclusive information in other channels.

Using vanilla GCC (or Clang) with android NDK

Android-NDK ships its own compiler to build the native code. The version shipped with my current android-NDK installation is arm-linux-androideabi-g++ (GCC) 4.6.x-google 20120106 (prerelease), I guess it's a fork of GCC 4.6.
What are the differences between it and a regular (vanilla) GCC 4.6? Is it producing better code for ARM platforms?
I'd like to use other compilers to build software for android, like vanilla GCC 4.7 or Clang, since they have a better support of C++11 and implement some features I'm struggling to use (like template aliases).
Is it possible to use the latest vanilla GCC or Clang, to build the native code for Android? What parameters should I use?
What are the cons of using a compiler different from the one shipped with android-SDK?
Android GCC is customized for the android as all the features in the GCC are not supported by the native Android. I dont think there is a possibility, you can post the same in the android ndk google groups where your answers will be replied by the Google Android Developers.
They were suggesting that we can make use of the cross compilers for compiling the android code with out using the android ndk.
Just a heads-up: google added clang3.1 in Revision 8c of the Android NDK. It's in "experimental" stage now, but easy to try out (and probably will be better supported in the near future, hopefully with a proper port of libc++, too).

Categories

Resources