how to build ndk application? - android

hi how to build ndk application...now i am using linux os and i am new for android application please tell me simply....

This should hopefully help you out:
http://www.jondev.net/articles/Using_NDK_r4_with_the_Android_SDK_in_Netbeans
Shows you how to build a simple 'Hello World' app using the NDK.

Be aware that the NDK will not let you build applications. It will only let you build a shared library object (.so) that your SDK application will open at runtime in order to execute native code.
Instead of the standard way to build and install applications:
ant compile # (or ant debug)
ant install
You will have an extra step:
ndk-build # builds the .so files
ant compile # builds the Java app and embeds the .so within the final .apk
ant install

Related

Building with Address Sanitizer on Android but with CMake

I am trying to build a .so for android and I want to build with address sanitizer but the only instructions I see are for Android NDK based Makefiles, but I am using the newer endorsed CMake setup. Just adding the flag -fsanitize=address wasn't enough as the clang runtime library was missing.
what is the correct thing to add in my CMakeLists for Android built libraries?
You also need to prepare your device as described in documentation. You have to run asan_device_setup script from NDK. It will put asan .so on the device.

Android NDK Debug Library

I have a Java Android application project that includes a so library in libs/armeabi folder.
The c++ code of this library is in a different Android NDK project and is dependent on other different library NDK projects.
Is it possible to debug the c++ code of this library while the Java Android application is running?
In order to debug the native code in .so, first you need .so that was generated with debugging mode. (e.g., NDK_DEBUG = 1)
If you don't have source code and therefore no debuggable .so, there is no way to debug.
Also, please specify your environment such as Android NDK version, IDE, etc.
Assuming you are using Eclipse, this is detailed description how to debug native applications.

How to compile APK from command line?

I am interested in making Android apps on demand. Depending on the clients request, my web site would send me a JSON file direct to a Windows application that I have created in Delphi. This one would save the file inside the Android app source folder and then, execute a command line telling the Android compiler to generate the APK file and send it to my client, all that without my presence.
The Android project was made with MotoDev. And it uses the Android SDK that is in my root.
How should I configure the command line to achieve this from inside my Delphi program?
I will also need to change the manifest to put a new version number so it does not conflict with other clients version.
Android uses the Ant build system, so you can create a build.xml and build.properties file for your project.
You'll need to create the build.xml file first though:
android update project -p .
This will generate a build.xml file. You should probably customize the build steps and targets for your project. A good idea in your case would be to have the build.properties file generated by your website for the specific build... Then include it via the build.xml file. In particular, you will need to specify in the build.properties file where the signing keys are, and what the password is:
Build.Properties:
key.store=keystore.dat
key.alias=signing_key
key.store.password=password123
key.alias.password=password123
The build process using ant also allows you to do variable replacements in Java files, which might be another idea. It would allow you to customize the build process further on a client by client basis.
By default, the build is triggered by:
ant clean
ant release
Another neat idea: Have Ant copy the resulting APK file to a network share accessible by the website by placing a < copy ... /> line in the < target name="release" > section.
Create build.xml at project creation time
If you start a new project with:
android create project \
--target 1 \
--name MyName \
--path . \
--activity MyActivity \
--package com.yourdomain.yourproject
the build.xml file used by ant will be generated.
The android tool is present in the tools/ directory of the SDK which you downloaded.
Create debug releases
Besides:
ant release
for final releases, you can also create debug releases with:
ant debug
Location of generated apk
Generated apk are placed under bin/.
The most important outputs are:
MyName-debug.apk
MyName-release.apk
but some intermediate apks are also generated, in particular unaligned and unsigned versions.
But most of the time you can forget where they were created and just run:
ant debug install
ant release install
to get them installed. But make sure it is working with adb first: adb devices command not working
Tested on Ubuntu 15.10, Android 23.
Android doesn't directly use ANT build systems now. It uses Gradle, which is based on Groovy. You can learn more about build systems here.
You can see the list of available tasks you can run on using this command
gradlew tasks
To initiate a debug build, invoke the assembleDebug task
gradlew assembleDebug
You can install your app using the adb tool via this command
adb install path/to/your_app.apk
To learn more about building on command line, follow this comprehensive article.
Also you can read this article on "Why Build Your Java Projects with Gradle Rather than Ant or Maven?"

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.

Android and cross-compiling

I have a Linux library that needs to be compiled under Android. I understand that should be used to build this program: / home/user/android-ndk/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc and then compile a ndk-build . I think right? Assembly via the utility should work correctly?
You need to install the Native Development Kit (NDK) and read through the documentation in the NDK about the build process. The NDK basic info is at http://developer.android.com/sdk/ndk/index.html, and you'll need to install an appropriate version of Cygwin (if you're using Windows).
It comes with a prebuilt compiler, so you shouldn't have to rebuild that.

Categories

Resources