In Android Studio 0.6 I created an android test project with a very simple C function wrapped with the JNI. I set android:debuggable="true"
in the AndroidManifest.xml
.
I ran ndk-build NDK_DEBUG=1
. This generated a gdbserver
and a gdb.setup
file in the correct location.
However, when I built the project in Android studio, and ran ndk-gdb --debug
I got the following output:
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!
I looked inside the apk gradle generated to make sure gdbserver was there, but I couldn't find the gdbserver
or gdb.setup
files! Where did they go?? It looks like gradle isn't packaging them in my apk!
Here's my 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.+'
}
How can I get gradle to properly package the gdbserver in my apk? If you want to try it yourself, I put the full source on github. https://github.com/cypressf/testndk
I've experimented the same issue. Setting this:
android{
buildTypes {
debug {
jniDebuggable true
}
}
}
wouldn't help since you don't rely on the android-plugin NDK integration.
One (not-so-good) solution is to manually copy the gdbserver and gdb.setup files to your app's nativeLibraryPath
directory on the device, after your apk has been installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With