在 Android Studio 0.6 中,我创建了一个带有 JNI 包装的非常简单的 C 函数的 android 测试项目。我设置android:debuggable="true"
在AndroidManifest.xml
.
我跑了ndk-build NDK_DEBUG=1
。这会在正确的位置生成一个gdbserver
和一个gdb.setup
文件。
但是,当我在 Android Studio 中构建项目并运行时,ndk-gdb --debug
我得到以下输出:
Android NDK installation path: /usr/local/android-ndk-r9d
Using default adb command: /Applications/Android Studio.app/sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using JDB command: /usr/bin/jdb
Using auto-detected project path: .
Found package name: com.example.testndk.app
ABIs targetted by application: armeabi-v7a
Device API Level: 19
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /usr/local/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found debuggable flag: true
Found gdb.setup under libs/armeabi-v7a, assuming app was built with NDK_DEBUG=1
Found data directory: '/data/data/com.example.testndk.app'
ERROR: Non-debuggable application installed on the target device.
Please re-install the debuggable version!
我查看了生成的 apk gradle 以确保 gdbserver 在那里,但我找不到gdbserver
orgdb.setup
文件!他们去哪儿了??看起来 gradle 没有将它们打包在我的 apk 中!
这是我的build.gradle
:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.example.testndk.app"
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs' // use the jni .so compiled from the manual ndk-build command
jni.srcDirs = [] //disable automatic ndk-build call
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
如何让 gradle 正确地将 gdbserver 打包到我的 apk 中?如果你想自己尝试一下,我把完整的源码放在了 github 上。https://github.com/cypressf/testndk