Index: pjproject/trunk/pjsip-apps/src/pjsua/android/.classpath
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/.classpath	(revision 5505)
+++ 	(revision )
@@ -1,9 +1,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="src" path="gen"/>
-	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
-	<classpathentry kind="output" path="bin/classes"/>
-</classpath>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/.project
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/.project	(revision 5505)
+++ 	(revision )
@@ -1,33 +1,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>pjsua</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-	</natures>
-</projectDescription>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/AndroidManifest.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/AndroidManifest.xml	(revision 5505)
+++ 	(revision )
@@ -1,47 +1,0 @@
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="org.pjsip.pjsua"
-    android:versionCode="1"
-    android:versionName="1.0" >
-
-    <uses-sdk
-        android:minSdkVersion="15"
-        android:targetSdkVersion="15" />
-
-    <uses-permission android:name="android.permission.INTERNET" />
-    <uses-permission android:name="android.permission.RECORD_AUDIO" />
-    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
-    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
-    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
-    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
-    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
-    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-    <uses-permission android:name="android.permission.WAKE_LOCK" />
-    <uses-permission android:name="android.permission.VIBRATE" />
-    <uses-permission android:name="android.permission.READ_LOGS" />
-    <uses-permission android:name="android.permission.USE_SIP" />
-    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-    <uses-permission android:name="android.permission.CAMERA" />
-
-    <uses-feature android:glEsVersion="0x00020000" android:required="false" />
-    
-    <uses-feature
-        android:name="android.hardware.microphone"
-        android:required="true" />
-
-    <application
-        android:icon="@drawable/main_image"
-        android:label="@string/app_name"
-        android:theme="@android:style/Theme.DeviceDefault.NoActionBar" >
-        <activity
-            android:name=".MainActivity"
-            android:windowSoftInputMode="stateHidden"
-            android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
-
-</manifest>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/build.gradle
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/build.gradle	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/build.gradle	(revision 5506)
@@ -0,0 +1,23 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 15
+    buildToolsVersion "23.0.3"
+
+    defaultConfig {
+        applicationId "org.pjsip.pjsua"
+        minSdkVersion 15
+        targetSdkVersion 15
+
+        ndk {
+            moduleName "libpjsua"
+        }
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+        }
+    }
+}
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/AndroidManifest.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/AndroidManifest.xml	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/AndroidManifest.xml	(revision 5506)
@@ -0,0 +1,47 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.pjsip.pjsua"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="15"
+        android:targetSdkVersion="15" />
+
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.RECORD_AUDIO" />
+    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
+    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.READ_LOGS" />
+    <uses-permission android:name="android.permission.USE_SIP" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.CAMERA" />
+
+    <uses-feature android:glEsVersion="0x00020000" android:required="false" />
+    
+    <uses-feature
+        android:name="android.hardware.microphone"
+        android:required="true" />
+
+    <application
+        android:icon="@drawable/main_image"
+        android:label="@string/app_name"
+        android:theme="@android:style/Theme.DeviceDefault.NoActionBar" >
+        <activity
+            android:name=".MainActivity"
+            android:windowSoftInputMode="stateHidden"
+            android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/java/org/pjsip/pjsua/MainActivity.java
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/java/org/pjsip/pjsua/MainActivity.java	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/java/org/pjsip/pjsua/MainActivity.java	(revision 5506)
@@ -0,0 +1,277 @@
+/* $Id: MainActivity.java $ */
+/*
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package org.pjsip.pjsua;
+
+import java.lang.ref.WeakReference;
+
+import android.app.Activity;
+import android.content.pm.ApplicationInfo;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.os.Handler;
+import android.os.Message;
+import android.widget.TextView;
+
+class CONST {
+    public static final String LIB_FILENAME = "pjsua";
+    public static final String TAG = "pjsua";
+    public static final Boolean AUTOKILL_ON_FINISH = true;
+    public enum MSG_TYPE {
+	STR_DEBUG,
+	STR_INFO,
+	STR_ERROR,
+	CLI_STOP,
+	CLI_RESTART,
+	QUIT
+    };
+}
+
+class LOG {
+    public static void DEBUG(Handler h, String str) {
+	Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_DEBUG.ordinal(), 
+				     str);
+	msg.sendToTarget();
+    }	
+    public static void INFO(Handler h, String str) {
+	Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_INFO.ordinal(), 
+				     str);
+	msg.sendToTarget();
+    }
+    public static void ERROR(Handler h, String str) {
+	Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_ERROR.ordinal(), 
+				     str);
+	msg.sendToTarget();
+    }
+}
+
+public class MainActivity extends Activity implements SurfaceHolder.Callback {
+    private MyHandler ui_handler = new MyHandler(this);
+    private static MyCallback callback;
+
+    private static class MyHandler extends Handler {
+	private final WeakReference<MainActivity> mTarget;
+
+	public MyHandler(MainActivity target) {
+	    mTarget = new WeakReference<MainActivity>(target); 
+	}
+
+	@Override
+	public void handleMessage(Message m) {
+	    MainActivity target = mTarget.get();
+	    if (target == null)
+		return;
+
+	    if (m.what == CONST.MSG_TYPE.STR_DEBUG.ordinal()) {
+		Log.d(CONST.TAG, (String)m.obj);	
+	    } else if (m.what == CONST.MSG_TYPE.STR_INFO.ordinal()) {
+		target.updateStatus((String)m.obj);
+		Log.i(CONST.TAG, (String)m.obj);				
+	    } else if (m.what == CONST.MSG_TYPE.STR_ERROR.ordinal()) {
+		target.updateStatus((String)m.obj);
+		Log.e(CONST.TAG, (String)m.obj);
+	    } else if (m.what == CONST.MSG_TYPE.CLI_STOP.ordinal()) {
+		pjsua.pjsuaDestroy();
+		LOG.INFO(this, "Telnet Unavailable");
+	    } else if (m.what == CONST.MSG_TYPE.CLI_RESTART.ordinal()) {
+		int status = pjsua.pjsuaRestart();
+		if (status != 0) {
+		    LOG.INFO(this, "Failed restarting telnet");
+		}
+	    } else if (m.what == CONST.MSG_TYPE.QUIT.ordinal()) {
+		target.finish();
+		System.gc();
+		android.os.Process.killProcess(android.os.Process.myPid());
+	    }
+	}
+    }
+
+    /** Callback object **/
+    private static class MyCallback extends PjsuaAppCallback {
+	private WeakReference<Handler> ui_handler;
+
+	public MyCallback(Handler in_ui_handler) {
+	    set_ui_handler(in_ui_handler);			
+	}
+
+	public void set_ui_handler(Handler in_ui_handler) {
+	    ui_handler = new WeakReference<Handler>(in_ui_handler);
+	}		
+
+	@Override
+	public void onStarted(String msg) {
+	    Handler ui = ui_handler.get();
+	    LOG.INFO(ui, msg);			
+	}
+
+	@Override
+	public void onStopped(int restart) {
+	    Handler ui = ui_handler.get();
+	    /** Use timer to stopped/restart **/
+	    if (restart != 0) {
+		LOG.INFO(ui, "Telnet Restarting");
+		Message msg = Message.obtain(ui, 
+			CONST.MSG_TYPE.CLI_RESTART.ordinal());
+		ui.sendMessageDelayed(msg, 100);
+	    } else {
+		LOG.INFO(ui, "Telnet Stopping");
+		Message msg = Message.obtain(ui, 
+			CONST.MSG_TYPE.CLI_STOP.ordinal());
+		ui.sendMessageDelayed(msg, 100);
+	    }
+	}
+    }
+
+    private void updateStatus(String output) {
+	TextView tStatus = (TextView) findViewById(R.id.textStatus);
+	tStatus.setText(output);        
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	LOG.DEBUG(ui_handler, "=== Activity::onCreate() ===");
+	super.onCreate(savedInstanceState);
+
+	init_view();
+
+	init_lib();
+    }
+
+    @Override
+    protected void onStart() {
+	LOG.DEBUG(ui_handler, "=== Activity::onStart() ===");
+	super.onStart();
+    }
+
+    @Override
+    protected void onRestart() {
+	LOG.DEBUG(ui_handler, "=== Activity::onRestart() ===");
+	super.onRestart();
+    }
+
+    @Override
+    protected void onResume() {
+	LOG.DEBUG(ui_handler, "=== Activity::onResume() ===");
+	super.onResume();
+    }
+
+    @Override
+    protected void onPause() {
+	LOG.DEBUG(ui_handler, "=== Activity::onPause() ===");
+	super.onPause();
+    }
+
+    @Override
+    protected void onStop() {
+	LOG.DEBUG(ui_handler, "=== Activity::onStop() ===");
+	super.onStop();
+    }
+
+    @Override
+    protected void onDestroy() {
+	LOG.DEBUG(ui_handler, "=== Activity::onDestroy() ===");
+	super.onDestroy();
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+	super.onSaveInstanceState(outState);
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+	super.onRestoreInstanceState(savedInstanceState);
+    }
+
+    private void init_view() {
+	setContentView(R.layout.activity_main);
+    }
+
+    private int init_lib() {        
+	LOG.INFO(ui_handler, "Loading module...");
+
+	// Try loading video dependency libs
+	try {
+	    System.loadLibrary("openh264");
+	    System.loadLibrary("yuv");
+	} catch (UnsatisfiedLinkError e) {
+	    LOG.ERROR(ui_handler, "UnsatisfiedLinkError: " + e.getMessage());
+	    LOG.ERROR(ui_handler, "This could be safely ignored if you "+
+		    		  "don't need video.");
+	}
+
+	// Load pjsua
+	try {
+	    System.loadLibrary(CONST.LIB_FILENAME);
+	} catch (UnsatisfiedLinkError e) {
+	    LOG.ERROR(ui_handler, "UnsatisfiedLinkError: " + e.getMessage());
+	    return -1;
+	}
+
+	// Wait for GDB to init, for native debugging only
+	if (false && (getApplicationInfo().flags & 
+	     	      ApplicationInfo.FLAG_DEBUGGABLE) != 0)
+	{
+	    try {
+		Thread.sleep(5000);
+	    } catch (InterruptedException e) {
+		LOG.ERROR(ui_handler, "InterruptedException: " + 
+			e.getMessage());
+	    }
+	}
+
+	// Set callback object
+	if (callback == null)
+	    callback = new MyCallback(ui_handler);
+
+	pjsua.setCallbackObject(callback);
+
+	SurfaceView surfaceView = (SurfaceView)
+				  findViewById(R.id.surfaceViewIncomingCall);
+	surfaceView.getHolder().addCallback(this);
+
+	LOG.INFO(ui_handler, "Starting module..");
+
+	int rc = pjsua.pjsuaStart();
+
+	if (rc != 0) {
+	    LOG.INFO(ui_handler, "Failed starting telnet");
+	}
+
+	return 0;
+    }
+    
+    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
+    {
+	pjsua.setIncomingVideoRenderer(holder.getSurface());
+    }
+
+    public void surfaceCreated(SurfaceHolder holder)
+    {
+	pjsua.setIncomingVideoRenderer(holder.getSurface());
+    }
+
+    public void surfaceDestroyed(SurfaceHolder holder)
+    {
+	pjsua.setIncomingVideoRenderer(null);
+    }
+    
+}
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/layout/activity_main.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/layout/activity_main.xml	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/layout/activity_main.xml	(revision 5506)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical" >
+
+    <TextView
+        android:id="@+id/textStatus"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentTop="false"
+        android:layout_centerHorizontal="true"
+        android:textIsSelectable="false" />
+
+    <SurfaceView
+        android:id="@+id/surfaceViewIncomingCall"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_above="@+id/imageApp"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginBottom="50dp" />
+
+    <TextView
+        android:id="@+id/textApp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_above="@+id/textStatus"
+        android:layout_centerHorizontal="true"
+        android:layout_marginBottom="126dp"
+        android:text="@string/app_name"
+        android:textSize="40sp"
+        android:typeface="serif" />
+
+    <ImageView
+        android:id="@+id/imageApp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_above="@+id/textApp"
+        android:layout_centerHorizontal="true"
+        android:contentDescription="@string/app_name"
+        android:src="@drawable/main_image" />
+
+</RelativeLayout>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values-v11/styles.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values-v11/styles.xml	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values-v11/styles.xml	(revision 5506)
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values-v14/styles.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values-v14/styles.xml	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values-v14/styles.xml	(revision 5506)
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values/strings.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values/strings.xml	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values/strings.xml	(revision 5506)
@@ -0,0 +1,6 @@
+<resources>
+
+    <string name="app_name">pjsua</string>
+    <string name="title_activity_main">MainActivity</string>
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values/styles.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values/styles.xml	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/app/src/main/res/values/styles.xml	(revision 5506)
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/build.gradle
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/build.gradle	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/build.gradle	(revision 5506)
@@ -0,0 +1,15 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+    repositories {
+        jcenter()
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:2.2.3'
+    }
+}
+
+allprojects {
+    repositories {
+        jcenter()
+    }
+}
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/gradle/wrapper/gradle-wrapper.properties
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/gradle/wrapper/gradle-wrapper.properties	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/gradle/wrapper/gradle-wrapper.properties	(revision 5506)
@@ -0,0 +1,6 @@
+#Mon Dec 28 10:00:20 PST 2015
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/gradlew
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/gradlew	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/gradlew	(revision 5506)
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+    echo "$*"
+}
+
+die ( ) {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=$((i+1))
+    done
+    case $i in
+        (0) set -- ;;
+        (1) set -- "$args0" ;;
+        (2) set -- "$args0" "$args1" ;;
+        (3) set -- "$args0" "$args1" "$args2" ;;
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+    JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/gradlew.bat
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/gradlew.bat	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/gradlew.bat	(revision 5506)
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Android.mk
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Android.mk	(revision 5505)
+++ 	(revision )
@@ -1,63 +1,0 @@
-# $Id$
-
-LOCAL_PATH	:= $(call my-dir)
-include $(CLEAR_VARS)
-
-# Get PJ build settings
-include ../../../../build.mak
-include $(PJDIR)/build/common.mak
-
-# Path to SWIG
-MY_SWIG		:= swig
-
-MY_MODULE_PATH  := $(PJDIR)/pjsip-apps/build/output/pjsua-$(TARGET_NAME)
-MY_MODULES      := $(MY_MODULE_PATH)/pjsua_app.o \
-		   $(MY_MODULE_PATH)/pjsua_app_cli.o \
-		   $(MY_MODULE_PATH)/pjsua_app_common.o \
-		   $(MY_MODULE_PATH)/pjsua_app_config.o \
-		   $(MY_MODULE_PATH)/pjsua_app_legacy.o
-
-# Constants
-MY_JNI_WRAP	:= pjsua_wrap.cpp
-MY_JNI_DIR	:= jni
-
-# Android build settings
-LOCAL_MODULE    := libpjsua
-LOCAL_CFLAGS    := -Werror $(APP_CFLAGS)
-LOCAL_LDFLAGS   := $(APP_LDFLAGS)
-LOCAL_LDLIBS    := $(MY_MODULES) $(APP_LDLIBS)
-LOCAL_SRC_FILES := $(MY_JNI_WRAP) pjsua_app_callback.cpp
-LOCAL_CPP_FEATURES += exceptions rtti
-
-# Copy Java Camera helper components from pjmedia/src/pjmedia-videodev/android
-src/org/pjsip/PjCamera.java:
-ifneq (,$(findstring PJMEDIA_VIDEO_DEV_HAS_ANDROID=1,$(ANDROID_CFLAGS)))
-	@echo "Copying Android camera helper components..."
-	cp $(PJDIR)/pjmedia/src/pjmedia-videodev/android/PjCamera*.java src/org/pjsip
-endif
-
-# Invoke SWIG
-$(MY_JNI_DIR)/$(MY_JNI_WRAP): src/org/pjsip/PjCamera.java
-	@echo "Invoking SWIG..."
-	$(MY_SWIG) -c++ -o $(MY_JNI_DIR)/$(MY_JNI_WRAP) -package org.pjsip.pjsua -outdir src/org/pjsip/pjsua -java $(MY_JNI_DIR)/pjsua.i
-
-.PHONY: $(MY_JNI_DIR)/$(MY_JNI_WRAP)
-
-include $(BUILD_SHARED_LIBRARY)
-
-
-# Add prebuilt libopenh264, if configured
-ifneq (,$(OPENH264_LDFLAGS))
-include $(CLEAR_VARS)
-LOCAL_MODULE := libopenh264
-LOCAL_SRC_FILES := $(subst -L,,$(filter -L%,$(OPENH264_LDFLAGS)))/libopenh264.so
-include $(PREBUILT_SHARED_LIBRARY)
-endif
-
-# Add prebuilt libyuv, if configured
-ifneq (,$(LIBYUV_LDFLAGS))
-include $(CLEAR_VARS)
-LOCAL_MODULE := libyuv
-LOCAL_SRC_FILES := $(subst -L,,$(filter -L%,$(LIBYUV_LDFLAGS)))/libyuv.so
-include $(PREBUILT_SHARED_LIBRARY)
-endif
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Application.mk
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Application.mk	(revision 5505)
+++ 	(revision )
@@ -1,2 +1,0 @@
-# It might be necessary to define APP_ABI if you are using other than armeabi, e.g: arm64-v8a
-# APP_ABI := arm64-v8a
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Makefile
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Makefile	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Makefile	(revision 5506)
@@ -0,0 +1,56 @@
+include ../../../../../build.mak
+include ../../../../../build/common.mak
+
+MY_MODULE_PATH  := $(PJDIR)/pjsip-apps/build/output/pjsua-$(TARGET_NAME)
+MY_MODULES      := $(MY_MODULE_PATH)/pjsua_app.o \
+		   $(MY_MODULE_PATH)/pjsua_app_cli.o \
+		   $(MY_MODULE_PATH)/pjsua_app_common.o \
+		   $(MY_MODULE_PATH)/pjsua_app_config.o \
+		   $(MY_MODULE_PATH)/pjsua_app_legacy.o
+
+OUT_DIR		:= ../build/jni
+LIBPJSUA_SO	:= ../app/src/main/jniLibs/armeabi/libpjsua.so
+
+# Env settings, e.g: path to SWIG, JDK, java(.exe), javac(.exe)
+MY_SWIG		:= swig
+MY_JNI_CFLAGS   := -D__ANDROID__
+MY_JNI_LDFLAGS  := -Wl,-soname,libpjsua.so
+SWIG_FLAGS      := -D__ANDROID__ -c++
+
+# Build settings
+MY_CFLAGS	:= $(PJ_CXXFLAGS) $(CFLAGS)
+MY_LDFLAGS	:= $(PJ_LDXXFLAGS) $(PJ_LDXXLIBS) $(LDFLAGS)
+MY_PACKAGE_NAME	:= org.pjsip.pjsua
+MY_PACKAGE_PATH := ../app/src/main/java/$(subst .,/,$(MY_PACKAGE_NAME))
+
+all: $(LIBPJSUA_SO) java
+
+$(LIBPJSUA_SO): $(OUT_DIR)/pjsua_wrap.o
+	mkdir -p ../app/src/main/jniLibs/armeabi
+	$(PJ_CXX) -shared -o $(LIBPJSUA_SO) \
+	$(OUT_DIR)/pjsua_wrap.o $(OUT_DIR)/pjsua_app_callback.o \
+	$(MY_MODULES) \
+		$(MY_CFLAGS) $(MY_LDFLAGS)
+
+$(OUT_DIR)/pjsua_wrap.o: $(OUT_DIR)/pjsua_wrap.cpp pjsua_app_callback.cpp Makefile
+	$(PJ_CXX) -c $(OUT_DIR)/pjsua_wrap.cpp -o $(OUT_DIR)/pjsua_wrap.o \
+		$(MY_CFLAGS)
+	$(PJ_CXX) -c pjsua_app_callback.cpp -o $(OUT_DIR)/pjsua_app_callback.o \
+		$(MY_CFLAGS)
+
+$(OUT_DIR)/pjsua_wrap.cpp: pjsua.i
+	mkdir -p $(MY_PACKAGE_PATH)
+	mkdir -p $(OUT_DIR)
+	swig $(SWIG_FLAGS) -java  -package $(MY_PACKAGE_NAME) \
+		-outdir $(MY_PACKAGE_PATH) \
+		-o $(OUT_DIR)/pjsua_wrap.cpp pjsua.i
+
+clean distclean realclean:
+	rm -rf $(LIBPJSUA_SO) $(OUT_DIR)/* \
+		$(MY_PACKAGE_PATH)/*.java
+
+java:
+ifneq (,$(findstring PJMEDIA_VIDEO_DEV_HAS_ANDROID=1,$(ANDROID_CFLAGS)))
+	@echo "Copying Android camera helper components..."
+	cp $(PJDIR)/pjmedia/src/pjmedia-videodev/android/PjCamera*.java $(MY_PACKAGE_PATH)/..
+endif
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua.i
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua.i	(revision 5505)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua.i	(revision 5506)
@@ -2,6 +2,6 @@
 
 %{
-#include "pjsua_app_callback.h"
-#include "../../pjsua_app.h"
+#include "../../jni/pjsua_app_callback.h"
+#include "../../../pjsua_app.h"
 
 #if defined(PJMEDIA_HAS_VIDEO) && PJMEDIA_HAS_VIDEO!=0
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/lint.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/lint.xml	(revision 5505)
+++ 	(revision )
@@ -1,3 +1,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<lint>
-</lint>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/proguard-project.txt
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/proguard-project.txt	(revision 5505)
+++ 	(revision )
@@ -1,20 +1,0 @@
-# To enable ProGuard in your project, edit project.properties
-# to define the proguard.config property as described in that file.
-#
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in ${sdk.dir}/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the ProGuard
-# include property in project.properties.
-#
-# For more details, see
-#   http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-#   public *;
-#}
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/project.properties
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/project.properties	(revision 5505)
+++ 	(revision )
@@ -1,14 +1,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-
-# Project target.
-target=android-16
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/settings.gradle
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/settings.gradle	(revision 5506)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/settings.gradle	(revision 5506)
@@ -0,0 +1,1 @@
+include ':app'
