It is impossible to add support for C ++ 11th version in Android studio 2.0. There is a need to use the thread and mutex libraries. I can not create an object of type thread constantly gets an error:
Error:(15, 5) error: 'thread' was not declared in this scope build.grade app file
apply plugin: 'com.android.model.application' model { android { compileSdkVersion = 23 buildToolsVersion = "23.0.2" defaultConfig.with { applicationId = "com.example.a1.enetndktest" minSdkVersion.apiLevel = 11 targetSdkVersion.apiLevel = 23 versionCode = 1 versionName = "1.0" } } android.ndk { moduleName = "EnetTest" stl = "gnustl_shared" cppFlags.add("-std=c++11") cppFlags.add("-Wall") cppFlags.add("-g") cppFlags.add("-libstdc++") cppFlags.add("-lsupc++") cppFlags.add("-pthread") cppFlags.add("-frtti") cppFlags.add("-fexceptions") cppFlags.add("-DANDROID") ldLibs.addAll(["android", "dl", "atomic", "log", "EGL", "GLESv2", "z"]) } android.buildTypes { release { minifyEnabled = false proguardFiles.add(file("proguard-rules.txt")) } } android.productFlavors { create("arm") { ndk.with{ abiFilters.add("armeabi") } } create("armv7") { ndk.with { abiFilters.add("armeabi-v7a") } } } // Our workaround compileOptions.with { sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 } } dependencies { compile fileTree(dir: "libs", include: [$/*.jar/$]) compile "com.android.support:appcompat-v7:23.1.1" } build.grade project file
buildscript { repositories { jcenter() } dependencies { classpath "com.android.tools.build:gradle-experimental:0.4.0" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } C ++ code file
#include <jni.h> #include "TestThreadClass.h" JNIEXPORT jint JNICALL Java_clib_ClibInt_enetinit(JNIEnv *env, jobject obj) { TestThreadClass t; t.threadFunction(); return 10; } Header file TestThreadClass.h
#ifndef ENETNDKTEST2_TESTTHREADCLASS_H #define ENETNDKTEST2_TESTTHREADCLASS_H #include <thread> using namespace std; class TestThreadClass { public: void threadFunction(); }; #endif //ENETNDKTEST2_TESTTHREADCLASS_H TestThreadClass.cpp file
#include "TestThreadClass.h" void threadFunction1() { int i = 0; while (i < 100000) { i++; } } void TestThreadClass::threadFunction(){ thread t(threadFunction1); t.join(); } Calling C ++ functions from java
package clib; public class ClibInt { static { System.loadLibrary("EnetTest"); } public native int enetinit(); }
thread**.h**? - D-sidethreadis. . - D-side