I am using Android Studio 2.1.2 and I am not using Experimental Plugin for NDK.
I need to compile C++11 source into Android application.
I am done with all NDK setup done with sample JNI and NJI communication.
Now I need to try new keywords or features added in C++11 with Android.
Please check following files, and error I am getting.
I fixed the issue. I am editing files with working code. And the question is not duplicate.
HelloJni.cpp
char *pc = nullptr; // OK
int *pi = nullptr; // OK Checking C++11
Application.mk
APP_ABI := all
APP_STL := gnustl_static
APP_CFLAGS += -std=gnu++11
APP_OPTIM := debug
LOCAL_CPP_FEATURES += exceptions
NDK_TOOLCHAIN_VERSION := 4.9
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ndksampleapp
LOCAL_SRC_FILES := HelloJni.cpp
include $(BUILD_SHARED_LIBRARY)
build.gradle
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.example.m1035325.ndksampleapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
//jniLibs.srcDirs = [ 'src/main/libs' ]
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
I am getting following error
Warning:Native C/C++ source code is found, but it seems that NDK option is not configured. Note that if you have an Android.mk, it is not used for compilation. The recommended workaround is to remove the default jni source code directory by adding:
android {
sourceSets {
main {
jni.srcDirs = []
}
}
}
to build.gradle, manually compile the code with ndk-build, and then place the resulting shared object in src/main/jniLibs.
char *pc = nullptr; // OK
^
C:\Users\AndroidStudioProjects\NDKSampleApp\app\src\main\jni\HelloJni.cpp
Error:(10, 12) error: 'nullptr' was not declared in this scope
Error:(11, 12) error: 'nullptr' was not declared in this scope
int *pi = nullptr; // OK Checking C++11
^
make: *** [C:\Users\AndroidStudioProjects\NDKSampleApp\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/app/C_\Users\AndroidStudioProjects\NDKSampleApp\app\src\main\jni\HelloJni.o] Error 1
:app:compileDebugNdk FAILED
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd'' finished with non-zero exit value 2
Information:BUILD FAILED
Error is fixed. Now I am able to compile C++11 cpp code with Android NDK. Please refer the edited files above.