Compile native c binaries for Android - Eg: dosfsck - android

I am trying to compile the binary dosfsck and mkdosfs for Android, using Linux and Android NDK and SDK. I've setup NDK and SDK properly, the path to the NDK gcc is in my path. I've also downloaded the correct SDK for my device (HTC Desire).
I first tried compiling the file with a simple make:
make
CROSS_COMPILE=/home/droidzone/android/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
I need to be able to run the binary from my device. As it is, the app compiles and runs on Ubuntu, but not my device. I get the error message from sh: Cannot run binary
Could someone please explain how I can link libraries, where I should get them from (within the SDK) and what changes if any to make to the Makefile, and the final syntax to compile this properly for Android

I found this was easiest to do using the agcc script script which you can use by exporting CC=agcc. Lots of projects will not properly support CROSS_COMPILE as you have tried. The agcc script is oriented around using the Android build tree files so I modified it to use the NDK tools. With this you should be able to build most things using make CC=agcc or CC=agcc ./configure

Related

Building QT Android app: ..i686-linux-android-g++: No such file or directory

I am building the first application in QT Creator, and came to the step I don't understand.
I have Mac, Android Studio is installed, Android SDK and NDK are installed using Studio. PATH to $ANDROID_NDK_ROOT is set manually.
My application compiles for Desktop without problems but trying to compile it for Android gives me this error:
/bin/sh: /Users/drob/Library/Android/sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/darwin-x86_64/bin/i686-linux-android-g++: No such file or directory
/bin/sh: /Users/drob/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++: No such file or directory
/bin/sh: /Users/drob/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++: No such file or directory
Project ERROR: Cannot run target compiler '/Users/drob/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++'. Output:
===================
/bin/sh: /Users/drob/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++: No such file or directory
===================
Maybe you forgot to setup the environment?
Error while parsing file /Users/drob/OneDrive/DEVEL/PROJECTS/QT_Projects/btchat/btchat.pro. Giving up.
I found that I should do the following steps, but I am scared to completely crash the system:
1. Install G++ (but what is this and how to install it on Mac properly)
2. Create G++ toolchain using NDK script (unfortunately too complicated for me. Some guide will be welcome)
What I also found out is that normally QT for Mac uses Clang compiler from XCode that I also have got installed. Should I somehow make QT Creator use that compiler instead of G++?
Sorry for questions that might sound silly but I am really lost at that point
Using the trial and error method I found that it is practically impossible to make NDK r10e work with QT 5.9. I ended up installing latest NDK and latest QT (5.12.6)

How can I do command line debugging using Android NDK

I am trying to debug a C++ Android application using Android NDK r20.
The project used to use the old way of building using ndk-build and the android.mk file.
Now the project is migrated to using gradle and cmake. Because of this, the ndk-gdb script no longer works, since it uses the old build system which expects an android.mk file.
So how am I supposed to debug from the command line using the latest ndk along with a gradle/cmake build system? Is there a new script that is provided?
ndk-gdb doesn't know how to do it out of the box right now. You can set up some symlinks in a gradle project to make the directory layout match a standalone ndk-build project which will let ndk-gdb work. See https://android.googlesource.com/platform/ndk/+/refs/heads/master/samples/NdkGdbSample/ for an example.
ndk-gdb doesn't work at all with CMake though.
See https://github.com/android-ndk/ndk/issues/1024 (I assume that's actually you that filed it). I don't know when we'll be able to do it, but what's described there is essentially what we'll do. We'll keep the existing script, get it to work with gradle projects, and (eventually) switch it to lldb under the covers.
Using Android Studio is your best bet for native debugging on Android right now.

Cygwin for Android-NDK programming

I read about the requirements of NDK programming on Windows which said we require Cygwin.Read about Cygwin which said we require it coz it is a way to make Windows support some linux functionality.But my question is in which stage of programming(Where Exactly) Cygwin will be required and why? Addidtional info about this topic is most welcomed
Android NDK starting with revision 7 doesn't require Cygwin. See here: http://developer.android.com/sdk/ndk/index.html
You can now build your NDK source files on Windows without Cygwin by calling the ndk-build.cmd script from the command line from your project path. The script takes exactly the same arguments as the original ndk-build script. The Windows NDK package comes with its own prebuilt binaries for GNU Make, Awk and other tools required by the build. You should not need to install anything else to get a working build system.
It mentions you can not use ndk-gdb script without Cygwin. While that is true, you can actually use gdb executable directly without Cygwin, only then you'll need to set it up properly manually.
At least NDK-r8b, if you want to build your .so, you don't need Cygwin.
However, if you want to use ndk-gdb to debug your native code,you have to use Cygwin.
And, in my experiment, if you ndk-gdb your native under Cygwin to debug native code which is built from windows cmd, ndk-gdb seems cannot recognize the debug info. So, for debug purpose, I build native Cygwin.
Make command to execute Android.mk file.
Android.mk file consists of list of c/c++ files to be compiled and also the library name(.so).
(from NDK-r8e NDK-GDB document) At the moment 'ndk-gdb' requires a Unix shell to run. This means that Cygwin is required to run it on Windows. We hope to get rid of this limitation in a future NDK release.

NDK Automatic build in eclipse OSX Invoking autoreconf in build directory:

this time with a droid related question.
Im running Eclipse Helios and Mac OS X 10.6.8
I have been following a book and a few tutorials on building the NDK from both command line and Eclipse.
I am copying the source over there is no static library business. I can compile from the command line fine with the "ndk-build" executable and it works fine.
Though i need to compile inside Eclipse for the reasons i don't need to go into here.
Ive tried 2 techniques and the one i have seen working is to convert my Project to a c++ project and then in Project / Properties / c/c++ Build tab / Build Command i set to ndk-build , this is set to be visible in my path (hence why it compiles when i go to directory and use ndk-build from Terminal)
I then in the C/C++ General tab add the following locations as include directories :
/Users/Me/Code/Android/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/include
/Users/me/Code/Android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include
/Users/me/Code/Android/android-ndk-r7b/sources/android/native_app_glue
Then when i go to compile i don't get any out put i just get the following error:
Invoking autoreconf in build directory: /Users/me/Code/Android/DroidBlaster
sh -c autoreconf -i
autoreconf: `configure.ac' or `configure.in' is required
Configuration failed with error
Ive tried a few other tutorials but to no avail, if i could award a bounty on this is would as its urgent i get this fixed.
Cheers community :)
NOTE:
Ive worked out that it is using auto tools to build the project where this is incorrect as i should be building with the NDK , getting closer to an answer hopefully. Seems that i cant convert my Android project with CDT to a custom build configuration, might be a bug to do with Eclipse, trying a fresh install
Ok so i worked it out, it was because i was trying to compile using Auto tools when i should have set up the project when i should have been using "Convert to C/C++ project" didn't help though that eclipse installed CDT incorrectly and i had to reinstall to get the right plugins.

Build Rsync for Android

I have downloaded rsync from http://rsync.samba.org/
anyone knows how to compile the source code to be deployed in an Android Device?
You can compile without the NDK assuming you statically link. This works for me on Ubuntu 13.04 Raring Ringtail.
Install the cross compiler:
sudo apt-get install gcc-arm-linux-gnueabi
Download rsync:
wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
tar -zxv -f rsync-3.0.9.tar.gz
cd rsync-3.0.9
Compile with the cross compiler, using static linking:
./configure --host=arm-linux-gnueabi CFLAGS="-static"
make
You'll get some warnings along the lines of Using X in statically linked applications requires at runtime the shared libraries from the glibc version used for linking. But so far, rsync has worked for me.
And finally, install to your phone (assumes you are using SSHDroid):
scp -P 2222 rsync root#$PHONE_IP:/data/data/berserker.android.apps.sshdroid/dropbear
You'll need the Android NDK found here
There are examples included on the web page and download of how to compile C code for Android.
From the NDK Website:
The NDK provides:
A set of tools and build files used to generate native code libraries
from C and C++ sources
A way to embed the corresponding native
libraries into an application package file (.apk) that can be deployed
on Android devices A set of native system headers and libraries that
will be supported in all future versions of the Android platform,
starting from Android 1.5. Applications that use native activities
must be run on Android 2.3 or later. Documentation, samples, and
tutorials
I did also find this if it's close to what you want to achieve.

Categories

Resources