Add files needed to build gfxspy on android.

This first change only tries to build one file: gltrace.pb.cpp.
This change depends on having the project
android.googlesource.com/platform/external/protobuf in your tree.

Change-Id: Ib33e023fd1ab940f92b47bb6139d330677189c7f
diff --git a/cc/android/jni/Android.mk b/cc/android/jni/Android.mk
new file mode 100644
index 0000000..9b1a0bf
--- /dev/null
+++ b/cc/android/jni/Android.mk
@@ -0,0 +1,26 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# Use the pre-built protobuf library.
+SRC_FILE_LIST          := $(LOCAL_PATH)/../../../../../external/protobuf/prebuilts/arm/libprotobuf-cpp-2.3.0-lite.a
+LOCAL_MODULE           := libprotobuf
+LOCAL_SRC_FILES        := $(SRC_FILE_LIST:$(LOCAL_PATH)/%=%)
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+
+# TODO: Change this to *.cpp once all the files are ready to compile.
+SRC_FILE_LIST          := $(wildcard $(LOCAL_PATH)/../../src/gfxspy/gltrace.pb.cpp)
+
+LOCAL_MODULE           := gfxspy
+LOCAL_SRC_FILES        := $(SRC_FILE_LIST:$(LOCAL_PATH)/%=%)
+
+LOCAL_CPPFLAGS         := -DEGL_EGLEXT_PROTOTYPES -DGL_GLEXT_PROTOTYPES -DTARGET_OS_ANDROID -DANDROID_NDK -Ofast -DGOOGLE_PROTOBUF_NO_RTTI -DHAVE_SYS_UIO_H -DHAVE_PTHREADS -DGENERATE_API_WRAPPERS -DLOAD_HOOKS_AT_STARTUP -O0 -marm -fno-strict-aliasing -funswitch-loops -finline-limit=100 -fno-omit-frame-pointer -ffunction-sections -mfloat-abi=softfp -fpic -fstack-protector -funwind-tables -fno-short-enums -fno-exceptions
+
+LOCAL_C_INCLUDES       := /usr/local/include $(LOCAL_PATH)/../../../../../external/protobuf/src
+LOCAL_LDLIBS           := -lc -lm -llog
+LOCAL_STATIC_LIBRARIES := libprotobuf libstlport_static
+LOCAL_SHARED_LIBRARIES := -lgcc
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/cc/android/jni/Application.mk b/cc/android/jni/Application.mk
new file mode 100644
index 0000000..30e8357
--- /dev/null
+++ b/cc/android/jni/Application.mk
@@ -0,0 +1,10 @@
+APP_ABI := armeabi-v7a
+APP_CPPFLAGS += -std=c++11
+APP_PLATFORM := android-19
+APP_STL := stlport_static
+NDK_TOOLCHAIN_VERSION := clang
+APP_OPTIM := debug
+# libprotobuf was compiled with -fno-rtti, so we must do the same for gfxspy.
+# This can not go in Android.mk because ndk-build inserts -frtti after
+# $LOCAL_CPPFLAGS.  ndk-build does not insert any options after $APP_CPPFLAGS.
+APP_CPPFLAGS := -fno-rtti
diff --git a/cc/build.gradle b/cc/build.gradle
new file mode 100644
index 0000000..8fab5ec
--- /dev/null
+++ b/cc/build.gradle
@@ -0,0 +1,63 @@
+import org.apache.tools.ant.taskdefs.condition.Os
+
+buildscript {
+  repositories {
+    jcenter()
+  }
+  dependencies {
+    classpath 'com.android.tools.build:gradle:0.+'
+  }
+}
+
+def goPath = System.getenv('GOPATH')
+def temporaryDirectory = file(goPath+'/pkg/build').absolutePath
+def outputDirectory = file(goPath+'/bin')
+
+apply plugin: 'com.android.application'
+apply plugin: 'cpp'
+
+buildDir temporaryDirectory
+
+defaultTasks 'ndkBuild'
+
+android {
+  compileSdkVersion 20
+  buildToolsVersion '20.0.0'
+  defaultConfig.targetSdkVersion 20
+
+  buildTypes {
+    debug {
+      debuggable true
+      jniDebuggable true
+    }
+    release {
+      debuggable false
+      jniDebuggable false
+    }
+  }
+
+  task ndkBuild(type: Exec) {
+    def cmd = 'ndk-build' + (osFamily() == 'windows' ? '.cmd' : '')
+    commandLine cmd, '-C', file('android').absolutePath, 'NDK_OUT='+temporaryDirectory+'/obj',
+                'NDK_APP_DST_DIR='+temporaryDirectory+'/libs/$(TARGET_ARCH_ABI)', '-s'
+  }
+
+  task ndkClean(type: Exec) {
+    def cmd = 'ndk-build' + (osFamily() == 'windows' ? '.cmd' : '')
+    commandLine cmd, '-C', file('android').absolutePath, 'NDK_OUT='+temporaryDirectory+'/obj',
+                'NDK_APP_DST_DIR='+temporaryDirectory+'/libs/$(TARGET_ARCH_ABI)', '-s', 'clean'
+  }
+
+  tasks.withType(JavaCompile) { compileTask ->
+    compileTask.dependsOn ndkBuild
+  }
+
+  clean.dependsOn ndkClean
+}
+
+def osFamily() {
+  if (Os.isFamily(Os.FAMILY_MAC)) return 'mac'
+  if (Os.isFamily(Os.FAMILY_UNIX)) return 'linux'
+  if (Os.isFamily(Os.FAMILY_WINDOWS)) return 'windows'
+  return null
+}