android - 构建类型不是 jni 可调试错误

标签 android android-ndk

我想用android studio调试c++ ndk但是 当我创建“Android Native”运行配置时,出现错误“Build type isn't jni debuggable”。 我的构建.gradle:

import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "org.amk.test"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"


        ndk {
            moduleName "HelloJNI"
        }
        sourceSets.main {
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = [] //disable automatic ndk-build call
        }
        task ndkBuild(type: Exec) {
            if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                commandLine 'ndk-build.cmd', '-C', 'main','NDK_DEBUG=1'
            } else {
                commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath
            }
        }

        tasks.withType(JavaCompile) {
            compileTask -> compileTask.dependsOn ndkBuild
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            ndk {
                debuggable = true
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:palette-v7:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.jakewharton:butterknife:6.1.0'
}

我的配置:

enter image description here

我可以运行 c++ ndk 但无法调试

我能做什么?

最佳答案

对于初学者,我使用的是 Android Studio 1.5/gradle 2.8

我通过将 build.gradle 更改为

来解决这个问题
 buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            ndk {
                debuggable = true
            }

        }
        debug {
            debuggable = true
            jniDebuggable = true
        }

    }

所以,基本上,我只是添加了这些行

ndk {
        debuggable = true
}

发布,和

debug {
         debuggable = true
         jniDebuggable = true
}

到封闭的buildTypes

但此语法因您的 gradle 版本而异。看Herehere寻求其他 gradle 版本的帮助

关于android - 构建类型不是 jni 可调试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33537889/

相关文章:

android - 在 Android 中显示图像预览

android - 如何在 flutter 中创建按钮 ListView ?

android - 完成 Android 设置?

android-studio - Android Studio lldb 和 GDB 之间切换

c++ - 如何从基于 native 事件的项目链接到Android Studio中的SDL2?

android - 在 Android cmake 构建中覆盖 android.toolchain.cmake

Android NDK 无法交叉编译 SQLite - crtend_so.o : No such file or directory

java - Android 上带有 ListView 的 NullPointerException

Android - 应用程序未安装

android - 如何修复数组类型的可空接收器的不安全使用?