1,select, Native C++
Creates a new project with an Empty Activity configured to use JNI.
2, c++ Standard, select c++11
使用linux系统时,启动Android Studio的模拟器出现下面的提示,无法启动.
KVM is required to run this AVD. /dev/kvm device: permission denied. Grant current user access to /dev/kvm
$ sudo chown username -R /dev/kvm3,select project and right click, then select new Module
select: Android Library
4, update file: build.gradle of module library
apply plugin: 'com.android.library' android { compileSdkVersion 29 buildToolsVersion "29.0.2" defaultConfig { minSdkVersion 24 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles 'consumer-rules.pro' externalNativeBuild { cmake { cppFlags "-std=c++11" } } ndk { abiFilters 'arm64-v8a', 'armeabi-v7a' } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" version "3.10.2" } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } task fwHeaders(type: Sync) { delete '../distribution/include/framework' from("src/main/cpp/framework") { include "**/*.h" } into "../distribution/include/framework" } preBuild.dependsOn(fwHeaders)
app:build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 29 buildToolsVersion "29.0.2" defaultConfig { applicationId "com.example.meshapi" minSdkVersion 24 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "-std=c++11" } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" version "3.10.2" } } sourceSets { main { jniLibs.srcDirs = ['libs'] } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }