
export OPENCV_PACKAGE_DIR=/home/pouique/Logiciels/Open-CV_Andro/OpenCV-2.3.1

export NDK_ROOT=/home/pouique/Logiciels/android-ndk-r7

export SDK_ROOT=/home/pouique/Logiciels/android-sdk-linux

echo "================================================"
echo "Compilation du JNI for $1"
echo "================================================"

cd $1

$NDK_ROOT/ndk-build
echo "================================================"
echo "remove old apk files"
echo "================================================"

ant clean

echo "================================================"
echo "Build Apk file"
echo "================================================"

$SDK_ROOT/tools/android update project --path .

ant debug

myApk=$(echo bin/*.apk) 
myApk=$(echo $a | cut -d " " -f 1)

echo "================================================"
echo "Install Apk"
echo "================================================"

$SDK_ROOT/platform-tools/adb -r install ./$myApk

echo "================================================"
echo "launch Apk"
echo "================================================"

packageName=$(awk -F "package=\"" '{ print $2 }' AndroidManifest.xml)
packageLength=$(expr length $packageName)
packageName=$(expr substr $packageName 1 $((packageLength-2)))

activityName=$(awk -F "activity android:name=\"" '{ print $2 }' AndroidManifest.xml)
activityLength=$(expr length $activityName)
activityName=$(expr substr $activityName 1 $((activityLength-2)))

$SDK_ROOT/platform-tools/adb shell "am start -a android.intent.action.MAIN -n $packageName/.$activityName"

