Gradle不会将gdbserver打包到apk中.ndk-gdb导致"错误:目标设备上安装了不可调试的应用程序"

Cyp*_*eld 10 android android-ndk ndk-gdb android-studio android-gradle-plugin

在Android Studio 0.6中,我创建了一个android测试项目,其中包含一个用JNI包装的非常简单的C函数.我订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!
Run Code Online (Sandbox Code Playgroud)

我查看生成的apk gradle内部以确保gdbserver在那里,但我找不到gdbservergdb.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.+'
}
Run Code Online (Sandbox Code Playgroud)

如何让gradle在我的apk中正确打包gdbserver?如果你想自己尝试一下,我把完整的源码放在github上.https://github.com/cypressf/testndk

ph0*_*h0b 13

我已经尝试了同样的问题.设置这个:

android{
  buildTypes {
    debug {
        jniDebuggable true
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

因为你不依赖于android-plugin NDK集成而无济于事.

一个(不那么好)的解决方案是nativeLibraryPath在安装apk之后手动将gdbserver和gdb.setup文件复制到设备上的应用程序目录中.