In terms of this link Convert Android Eclipse ADT game project into Android Studio project, I found it useful for importing the initial project into Android Studio and setting up the ndk.dir setting correctly.
In terms of actually building the project, I actually ended up having to edit the build files and ended up using a script called jnibuild.sh to build from the command line. It’s much simpler and easier to maintain, to simply edit the Android makefiles than to try to configure gradle to pass makefile related flags to the ndk layer.
In terms of edits to the build files, these are the changes that I made:
diff --git a/proj.studio/testgame/src/main/jni/Android.mk b/proj.studio/testgame/src/main/jni/Android.mk
index 75e64b0..da85a68 100644
--- a/proj.studio/testgame/src/main/jni/Android.mk
+++ b/proj.studio/testgame/src/main/jni/Android.mk
@@ -2,19 +2,38 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
-$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
-$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
+$(call import-add-path,/Users/gino/cocos2d-x-3.4)
+$(call import-add-path,/Users/gino/cocos2d-x-3.4/external)
+$(call import-add-path,/Users/gino/cocos2d-x-3.4/cocos)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
-LOCAL_SRC_FILES := hellocpp/main.cpp \
- ../../Classes/AppDelegate.cpp \
- ../../Classes/HelloWorldScene.cpp
+FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../../../Classes/*.cpp) \
+ $(wildcard $(LOCAL_PATH)/../../../../../Classes/*.c) \
+ $(wildcard $(LOCAL_PATH)/../../../../../Classes/swig/*.cpp) \
+
+
+
+LOCAL_SRC_FILES := hellocpp/main.cpp
+
+LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../../Classes \
+ $(LOCAL_PATH)/../../../../../Classes/swig
+
+
+# following flag will cause assert() to abort program execution:
+LOCAL_CFLAGS += -UNDEBUG
+
+# need to disable SSE instruction generation if we're compiling for x86:
+ifeq ($(TARGET_ARCH_ABI),x86)
+LOCAL_CFLAGS += -U__SSE__
+LOCAL_CPPFLAGS += -U__SSE__
+endif
+
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
diff --git a/proj.studio/testgame/src/main/jni/Application.mk b/proj.studio/testgame/src/main/jni/Application.mk
index 02b8eab..2783509 100644
--- a/proj.studio/testgame/src/main/jni/Application.mk
+++ b/proj.studio/testgame/src/main/jni/Application.mk
@@ -1,4 +1,5 @@
APP_STL := gnustl_static
+APP_PLATFORM := android-10
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 \
-fsigned-char \
@@ -8,6 +9,10 @@ APP_LDFLAGS := -latomic
#APP_ABI := armeabi armeabi-v7a x86
APP_ABI := x86
+#APP_ABI := armeabi
+
+NDK_TOOLCHAIN_VERSION := 4.9
+
(BTW, you can safely skip/ignore the references to the Classes/swig related directory. I use some swig generated code, which I kept under Classes/swig, which needed to be compiled in.)
Also, I needed to add:
sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call
to the file build.gradle, so that Android Studio would not try to build the jni source code at all.
Looks like Android Studio really doesn’t support ndk builds, aside from being instructed to ignore them, which makes it possible to just invoke ndk-build from the command line and not worry about Android Studio trying to recompile it on its own.