Complete information is from http://developer.android.com/guide/developing/projects/projects-cmdline.html, here is summarized just the bare minimum (but entirely self-sufficient) to get everything compiled, if you are lazy to read the more complete document.
Necessary tools needed prior to compilation:
1. “ant” (http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html)
2. Android SDK (http://developer.android.com/sdk/index.html)
3. Android NDK (http://developer.android.com/sdk/ndk/index.html)
And the steps are as follows:
a. Due to the “awk” utility as provided by Android NDK is a 64-bit binary, it is necessary to first rename or delete it first (http://stackoverflow.com/questions/8116113/problems-with-android-ndk-7-and-awk).
b. Then traverse to the NDK’s samples directory, and further cd to any of the samples.
c. Then issue “../../ndk-build” to execute the ndk-build as provided by Android NDK.
d. Then issue the “android update” command (here my Android SDK is installed in the /opt directory):
/opt/android-sdk-linux/tools/android update project –path . –target android-10
The target to choose should match the Android version of the your phone: http://developer.android.com/guide/appendix/api-levels.html
For example, my Sony Ericsson Arc S is Android 2.3.4, so the target is “android-10” as above.
e. Next compile a debug version (you can compile a release version too, but that will require you to sign the application. (Please refer to http://developer.android.com/guide/publishing/app-signing.html for more info).
ant debug
f. Then after connecting the phone to the computer via USB, issue the following command to install the debug apk:
/opt/android-sdk-linux/platform-tools/adb install -r bin/xxxxxxx-debug.apk
where bin/xxxxxxx-debug.apk is the name of the apk generated in the “bin” subdirectory.
The full verbose output as follow:
../../ndk-build
+ dirname ../../ndk-build
+ PROGDIR=../..
+ cd ../..
+ pwd
+ PROGDIR=/opt/android-ndk-r7
+ [ -n /opt/android-ndk-r7/prebuilt/linux-x86/bin/make ]
+ which /opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ ABS_GNUMAKE=/opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ [ 0 != 0 ]
+ GNUMAKE=/opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ [ = cygwin ]
+ /opt/android-ndk-r7/prebuilt/linux-x86/bin/make -f /opt/android-ndk-r7/build/core/build-local.mk
Compile thumb : sanangeles <= importgl.c
Compile thumb : sanangeles <= demo.c
Compile thumb : sanangeles libs/armeabi/libsanangeles.so+ /opt/android-sdk-linux/tools/android update project –path . –target android-10
Updated project.properties
Updated local.properties
Updated file ./proguard.cfg
+ ant debug
Buildfile: /opt/android-ndk-r7/samples/san-angeles/build.xml-set-mode-check:
-set-debug-files:
-set-debug-mode:
-debug-obfuscation-check:
-setup:
[echo] Gathering info for DemoActivity…
[setup] Android SDK Tools Revision 16
[setup] Project Target: Android 2.3.3
[setup] API level: 10
[setup]
[setup] ——————
[setup] Resolving library dependencies:
[setup] No library dependencies.
[setup]
[setup] ——————
[setup]
[setup] WARNING: Attribute minSdkVersion in AndroidManifest.xml (4) is lower than the project target API level (10)-build-setup:
[echo] Creating output directories if needed…-pre-build:
-code-gen:
[echo] ———-
[echo] Handling aidl files…
[aidl] No AIDL files to compile.
[echo] ———-
[echo] Handling RenderScript files…
[renderscript] No RenderScript files to compile.
[echo] ———-
[echo] Handling Resources…
[aapt] No changed resources. R.java and Manifest.java untouched.-pre-compile:
-compile:
-post-compile:
-obfuscate:
-dex:
[dex] No new compiled code. No need to convert bytecode to dalvik format.-crunch:
[crunch] Crunching PNG Files in source dir: /opt/android-ndk-r7/samples/san-angeles/res
[crunch] To destination dir: /opt/android-ndk-r7/samples/san-angeles/bin/res
[crunch] Crunched 0 PNG files to update cache-package-resources:
[aapt] No changed resources or assets. DemoActivity.ap_ remains untouched-package:
[apkbuilder] No changes. No need to create apk.-do-debug:
[zipalign] No changes. No need to run zip-align on the apk.
[echo] Debug Package: /opt/android-ndk-r7/samples/san-angeles/bin/DemoActivity-debug.apkdebug:
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.propBUILD SUCCESSFUL
Total time: 1 second
+ /opt/android-sdk-linux/platform-tools/adb install -r bin/DemoActivity-debug.apk
453 KB/s (19858 bytes in 0.042s)
pkg: /data/local/tmp/DemoActivity-debug.apk
Success
Posted by Android development (without Eclipse) | Coding Tweaks on November 29, 2016 at 1:55 am
[…] more details: How to compile the Android NDK examples using command line tools android eclipse tutorial for […]
Posted by Android development (without Eclipse) | Coding Craze on December 14, 2016 at 11:35 pm
[…] more details: How to compile the Android NDK examples using command line tools android eclipse […]
Posted by Android development (without Eclipse) | Coding Tweaks on March 25, 2017 at 7:25 am
[…] more details: How to compile the Android NDK examples using command line tools android tutorials for beginners in […]