Suppose your install paths of sdk and ndk are
~/android-sdk-mac_x86 and ~/android-ndk-r5cSetup PATH
export PATH=${PATH}:~/android-sdk-mac_x86/tools:~/android-ndk-r5cndk-build
cd ~/android-ndk-r5c/samples/hello-jni
ndk-buildlist target (assume sdk installed)
android list targetupdate project with target 1
android update project -t 1 -p .list avd (suppose AVD4G created during sdk installation)
android list avdstart emulator
emulator -avd AVD4G -scale 0.5 &debug build
ant debuginstall to emulator
ant installuse ant uninstall to remove
If you want to code-sign the binary, first create the build.properties and self-signing certificate and compile release
create build.properties
# location of the keystore. This is used by ant release
key.store= /my-path-to-mykey/my.keystore
key.alias=mykeystore
create self-signing certificate and compile release
keytool -genkey -v -keystore /my-path-to-mykey/my.keystore -alias mykeystore -keyalg RSA -keysize 2048 -validity 10000
ant release
This is how to compile C++ program with stlport in ndk
cd ~/android-ndk-r5c/samples/test-libstdc++
modify jni/test-libstl.cpp to
#include <iostream>
using namespace std;
int main() {
cout << "hello, world\n";
return 0;
}
create jni/Application.mk with
APP_STL := stlport_static
modify jni/Android.mk with
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test-libstl
LOCAL_SRC_FILES := test-libstl.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_EXECUTABLE := test-libstl
run:
~/android-sdk-mac_x86/platform-tools/adb push libs/armeabi/$(LOCAL_MODULE) /data/local/bin/$(LOCAL_MODULE)
~/android-sdk-mac_x86/platform-tools/adb shell chmod 755 /data/local/bin/$(LOCAL_MODULE)
~/android-sdk-mac_x86/platform-tools/adb shell /data/local/bin/$(LOCAL_MODULE)
run with emulator
ndk-build clean && ndk-build
ndk-build run
For Windows, add this PATH in environment (path should not have spaces)
C:\Android\android-sdk\tools;C:\Android\apache-ant-1.8.2\bin;C:\Android\android-ndk-r6;
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_29
and you need cygwin to start ndk-build
.
.
.
0 comments:
Post a Comment