build: Update gradle to allow enabling debug mode of NDK builds

When NDK_DEBUG environment variable is set, it is passed to ndk-build,
which will build in debug mode and include appropriate version of gdbserver.

Change-Id: Ife8e4c6cd798f2dadcc4c00fc3b5f39dacb2e516
diff --git a/app/build.gradle b/app/build.gradle
index df49097..94fcb91 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -18,6 +18,10 @@
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
+        debug {
+            debuggable true
+            jniDebuggable true
+        }
     }
     sourceSets {
         main {
@@ -59,15 +63,23 @@
 
     // call regular ndk-build(.cmd) script from app directory
     task ndkBuild(type: Exec) {
-        def ndkBuildParallel = Runtime.runtime.availableProcessors()
+        def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]
+
         if (System.env.NDK_BUILD_PARALLEL != null) {
-            ndkBuildParallel = System.env.NDK_BUILD_PARALLEL
+           args.add("-j" + System.env.NDK_BUILD_PARALLEL)
         }
-        def ndkBuildAbi = "all"
+        else {
+           args.add("-j" + Runtime.runtime.availableProcessors())
+        }
+
         if (System.env.NDK_BUILD_ABI != null) {
-           ndkBuildAbi = System.env.NDK_BUILD_ABI
+           args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
         }
-        commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, '-j', ndkBuildParallel, "APP_ABI=" + ndkBuildAbi
+
+        if (System.env.NDK_DEBUG != null) {
+           args.add("NDK_DEBUG=1")
+        }
+        commandLine args
     }
 
     tasks.withType(JavaCompile) {