记录: Android studio 3.1.2
NDK r16
SDK 28 Level
首先如果你的原有工程是CMake 编译的 那么没问题,直接上 : 工程右键菜单: Linker C++ project 选择原有CMakeList 文件.
然后工程配置需要修改,默认AS会编译所有交叉编译的平台
这里太慢配置一个常用的平台:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.chijing.myapplication"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
//'-LIBS="-lsupc++ -lstdc++'
cppFlags "-frtti -fexceptions -std=c++14"
arguments
'-DANDROID_STL=c++_shared ARCH=arm -ABI_TYPE=armeabi-v7a'
ndk {
//moduleName "jary" //生成的so名字
abiFilters "armeabi-v7a" //输出指定三种abi体系结构下的so库。
stl "c++_shared" //打开.c 的 debug (此句是打开的debug的关键)
}
}
}
}
buildTypes {
// release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// }
debug
{
jniDebuggable true
jniDebuggable = true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
externalNativeBuild {
cmake {
path 'D:/source/kernel/CMakeLists.txt'
//LIBS="-lsupc++ -lstdc++"
//ANDROID_CPP_FEATURES="rtti;exceptions"
//ANDROID_STL="c++_shared"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
配置完成后即可build完成.然后即可调试, 需要lldb插件
另外一个很重要的地方,要添加符号文件给lldb,不然是无法进入C++代码的.
如下