jni: Revert dependency on CrystaX 10.1.0 and fixes for new versions of NFD and ndn-cxx

The new CrystaX release has (yet unknown) issue that prevents code from
working properly

Change-Id: I5c34dc12ea653c7b7ec694640b5d0ecd6648b1d5
diff --git a/.gitmodules b/.gitmodules
index 9d8d438..c904635 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,10 +1,13 @@
 [submodule "app/src/main/jni/cryptopp"]
     path = app/src/main/jni/cryptopp
-    url = http://github.com/cawka/cryptopp
+    url = https://github.com/cawka/cryptopp
     branch = android
+[submodule "app/src/main/jni/sqlite3"]
+    path = app/src/main/jni/sqlite3
+    url = https://github.com/cawka/sqlite3-android.git
 [submodule "app/src/main/jni/ndn-cxx"]
     path = app/src/main/jni/ndn-cxx
-    url = ../ndn-cxx
+    url = https://github.com/named-data/ndn-cxx
 [submodule "app/src/main/jni/NFD"]
     path = app/src/main/jni/NFD
-    url = ../NFD
+    url = https://github.com/named-data/NFD
diff --git a/.jenkins.d/10-get-ndk.sh b/.jenkins.d/10-get-ndk.sh
index b6ed35d..5729869 100755
--- a/.jenkins.d/10-get-ndk.sh
+++ b/.jenkins.d/10-get-ndk.sh
@@ -3,7 +3,7 @@
 set -x
 
 URL=https://www.crystax.net/download/
-NDK=crystax-ndk-10.2.1
+NDK=crystax-ndk-10.1.0
 
 NDK_FILE="$NDK-linux-x86_64.tar.bz2"
 
diff --git a/.vagrant/Vagrantfile b/.vagrant/Vagrantfile
index f2d8374..58a6b30 100644
--- a/.vagrant/Vagrantfile
+++ b/.vagrant/Vagrantfile
@@ -10,9 +10,10 @@
 sudo dpkg --add-architecture i386;
 sudo apt-get update -qq; sudo apt-get install -y libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386
 
-wget -q https://www.crystax.net/download/crystax-ndk-10.2.1-linux-x86_64.tar.bz2
-tar jxf crystax-ndk-10.2.1-linux-x86_64.tar.bz2
-rm crystax-ndk-10.2.1-linux-x86_64.tar.bz2
+wget -q https://www.crystax.net/download/crystax-ndk-10.1.0-linux-x86_64.tar.bz2
+tar jxf crystax-ndk-10.1.0-linux-x86_64.tar.bz2
+rm crystax-ndk-10.1.0-linux-x86_64.tar.bz2
+find crystax-ndk-10.1.0 -name byteswap.h -exec sed -i -e 's/ swap/ bswap/g' {} \\;
 
 wget -q http://dl.google.com/android/android-sdk_r24.0.2-linux.tgz
 tar zxf android-sdk_r24.0.2-linux.tgz
@@ -29,12 +30,12 @@
 echo "y" | android update sdk --filter "android-19" --no-ui --all --force
 
 wget -q https://services.gradle.org/distributions/gradle-2.6-bin.zip
-unzip gradle-2.6.bin.zip
+unzip gradle-2.6-bin.zip
 rm gradle-2.6-bin.zip
 export PATH=$PATH:`pwd`/gradle-2.6/bin
 
 echo sdk.dir=`pwd`/android-sdk-linux > local.properties
-echo ndk.dir=`pwd`/crystax-ndk-10.2.1 >> local.properties
+echo ndk.dir=`pwd`/crystax-ndk-10.1.0 >> local.properties
 SCRIPT
 
 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
diff --git a/README.md b/README.md
index 782b9b2..fbd99b4 100644
--- a/README.md
+++ b/README.md
@@ -8,13 +8,18 @@
 To compile code, the following is necessary
 
 - Appropriate [Android SDK](http://developer.android.com/sdk/index.html)
-- [CrystalX Android NDK](https://www.crystax.net/en/download) version 10.2.1 or later
+- [CrystalX Android NDK](https://www.crystax.net/en/download) version 10.1.0 or later
+
+If version 10.1.0 is used, then the following patch needs to be applied:
+
+    find crystax-ndk-10.1.0 -name byteswap.h -exec sed -i -e 's/ swap/ bswap/g' {} \;
 
 Example script for Ubuntu 14.04 to get all dependencies, download SDK and NDK:
 
     sudo apt-get install -y build-essential git openjdk-7-jdk unzip
-    wget -q https://www.crystax.net/download/crystax-ndk-10.2.1-linux-x86_64.tar.bz2
-    tar jxf crystax-ndk-10.2.1-linux-x86_64.tar.bz2
+    wget -q https://www.crystax.net/download/crystax-ndk-10.1.0-linux-x86_64.tar.bz2
+    tar jxf crystax-ndk-10.1.0-linux-x86_64.tar.bz2
+    find crystax-ndk-10.1.0 -name byteswap.h -exec sed -i -e 's/ swap/ bswap/g' {} \;
 
     wget -q http://dl.google.com/android/android-sdk_r24.0.2-linux.tgz
     tar zxf android-sdk_r24.0.2-linux.tgz
@@ -43,7 +48,7 @@
 
     git clone --recursive http://gerrit.named-data.net/NFD-android
     echo sdk.dir=`pwd`/android-sdk-linux > NFD-android/local.properties
-    echo ndk.dir=`pwd`/crystax-ndk-10.2.1 >> NFD-android/local.properties
+    echo ndk.dir=`pwd`/crystax-ndk-10.1.0 >> NFD-android/local.properties
     cd NFD-android
 
     ../gradle/gradle-2.6/bin/gradle assembleRelease
diff --git a/app/build.gradle b/app/build.gradle
index c55ce1e..41a6db8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -133,18 +133,21 @@
     compile 'com.android.support:appcompat-v7:21.0.3'
     compile 'com.android.support:support-v4:21.0.3'
 
-    compile 'net.named-data:jndn:0.4'
-    compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
-
     compile('com.intel.jndn.utils:jndn-utils:0.9.7') {
-      force = true
-      exclude group: 'com.intel.jndn.mock'
+      exclude group: 'com.intel.jndn.mock', module: 'jndn-mock'
+      exclude group: 'net.named-data', module: 'jndn'
     }
-    compile('com.intel.jndn.management:jndn-management:0.9.7') {
-      force = true
-      exclude group: 'com.intel.jndn.jndn-utils'
-    }
-    compile 'com.google.protobuf:protobuf-java:2.6.1'
 
+    compile('com.intel.jndn.management:jndn-management:0.9.7') {
+      exclude group: 'net.named-data', module: 'jndn'
+      exclude group: 'com.intel.jndn.utils', module: 'jndn-utils'
+      exclude group: 'com.intel.jndn.mock', module: 'jndn-mock'
+    }
+
+    // compile('net.named-data:jndn-android:0.7') {
+    compile('net.named-data:jndn:0.4') {
+      exclude group: 'org.xerial'
+    }
+    compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
     compile 'joda-time:joda-time:2.7'
 }
diff --git a/app/src/main/jni/ndn-cxx.mk b/app/src/main/jni/ndn-cxx.mk
index fc758f6..8f6ecea 100644
--- a/app/src/main/jni/ndn-cxx.mk
+++ b/app/src/main/jni/ndn-cxx.mk
@@ -5,7 +5,7 @@
 LOCAL_MODULE := ndn-cxx
 NDN_CXX_BOOST_LIBS = system filesystem date_time iostreams program_options chrono random
 LOCAL_SHARED_LIBRARIES := cryptopp $(addsuffix _shared,$(addprefix boost_,$(NDN_CXX_BOOST_LIBS)))
-LOCAL_STATIC_LIBRARIES := sqlite3_static boost_regex_static
+LOCAL_STATIC_LIBRARIES := sqlite3 boost_regex_static
 NDN_CXX_SRC_FILES := \
     data.cpp \
     encoding/block.cpp \
@@ -115,6 +115,6 @@
 include $(BUILD_SHARED_LIBRARY)
 
 include $(LOCAL_PATH_SAVED)/cryptopp/Android.mk
+include $(LOCAL_PATH_SAVED)/sqlite3/Android.mk
 
 $(call import-module,boost/1.57.0)
-$(call import-module,sqlite/3)
diff --git a/app/src/main/jni/nfd-wrapper.cpp b/app/src/main/jni/nfd-wrapper.cpp
index a5544a8..d88413e 100644
--- a/app/src/main/jni/nfd-wrapper.cpp
+++ b/app/src/main/jni/nfd-wrapper.cpp
@@ -77,9 +77,10 @@
       "  strategy_choice\n"
       "  {\n"
       "    /               /localhost/nfd/strategy/best-route\n"
-      "    /localhost      /localhost/nfd/strategy/broadcast\n"
+      "    /localhost      /localhost/nfd/strategy/multicast\n"
       "    /localhost/nfd  /localhost/nfd/strategy/best-route\n"
-      "    /ndn/broadcast  /localhost/nfd/strategy/broadcast\n"
+      "    /ndn/broadcast  /localhost/nfd/strategy/multicast\n"
+      "    /ndn/multicast  /localhost/nfd/strategy/multicast\n"
       "  }\n"
       "}\n"
       "\n"
@@ -164,6 +165,7 @@
       std::unique_lock<std::mutex> lock(m_pointerMutex);
       m_io = &getGlobalIoService();
     }
+
     m_io->run();
     m_io->reset();
   }
@@ -249,6 +251,9 @@
     NFD_LOG_INFO("Use [" << nfd::g_params["homePath"] << "] as a security storage");
 
     nfd::g_thread = boost::thread([] {
+        nfd::scheduler::resetGlobalScheduler();
+        nfd::resetGlobalIoService();
+
         NFD_LOG_INFO("Starting NFD...");
         try {
           nfd::g_runner.reset(new nfd::Runner());
diff --git a/app/src/main/jni/sqlite3 b/app/src/main/jni/sqlite3
new file mode 160000
index 0000000..b2b9ab5
--- /dev/null
+++ b/app/src/main/jni/sqlite3
@@ -0,0 +1 @@
+Subproject commit b2b9ab529987de81585ce6bf7bcfab91917f37af