简体   繁体   English

无法启用JNI调试器

[英]Unable to Enable JNI Debugger

I have started using Java Native Interface (JNI) recently and encountered some problems that I hope you could help me to solve. 我最近开始使用Java本机接口(JNI),遇到了一些问题,希望您能帮助我解决。

I am using Android Studio 2.1.1, SDK Tools 25.1.7, NDK 12, API 21. 我正在使用Android Studio 2.1.1,SDK工具25.1.7,NDK 12,API 21。

1.My main problem is that i cannot debug the C code, only the java. 1.我的主要问题是我无法调试C代码,只能调试Java。 i will try to explain my attempts at debugging on a much simpler code which i will include. 我将尝试解释我将在包含的更简单代码上进行调试的尝试。

1.1 I compiled the C code to .so with the command ndk-build NDK_DEBUG=1. 1.1我使用命令ndk-build NDK_DEBUG = 1将C代码编译为.so。

1.2 I have added the SDK\\NDK path to the Android Studio Project Structure. 1.2我已经将SDK \\ NDK路径添加到Android Studio项目结构中。

1.3 I have added to the build.gradle "jnidebuggable=true". 1.3我已添加到build.gradle“ jnidebuggable = true”。

1.4 I have created in Run->Edit Config a new debug session with "Hybrid" settings and loaded the .so libs to it. 1.4我在“运行”->“编辑配置”中创建了一个具有“混合”设置的新调试会话,并将.so库加载到其中。

1.5 Attaching my Android.mk, Application.mk, build.gradle, C code and files. 1.5附加我的Android.mk,Application.mk,build.gradle,C代码和文件。

1.6 The code is running and working, it doesn't hit the breakpoints inside the C code. 1.6代码正在运行并且正在工作,它没有达到C代码内部的断点。

2.how can i monitor the heap and stack usage of my code and especially the of the JNI? 2.如何监视我的代码尤其是JNI的堆和堆栈使用情况? also is it changeable? 也是可变的吗?

3.on the same matter as 2. how can i decrease the dependency in the heap? 3.关于与2.相同的问题,如何减少堆中的依赖关系? will defining my variables as static do the trick? 将变量定义为静态会成功吗?

Android.mk Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sub
LOCAL_SRC_FILES := subst.c
include $(BUILD_SHARED_LIBRARY)

Application.mk Application.mk

APP_ABI := all
APP_BUILD_SCRIPT := C:\Users\Nir\AndroidStudioProjects\FirstApp\jni\Android.mk

C code C代码

jdouble Java_nir_firstapp_MainActivity_subst(JNIEnv* env, jobject obj, jdouble A, jdouble B)
{
int x;
x=A-B;
return(x);
}

build.gradle build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "nir.firstapp"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        jniDebuggable true
        debuggable true
    }
    }
}

MainActivity relevant code MainActivity相关代码

public native double subst(double A, double B);
static{
    System.loadLibrary("sub");
}
double calc = subst(Double.valueOf(num1str),Double.valueOf(num2str));

My sincere thank you, Nir 真诚的谢谢你,尼尔

To enable native debugging, compile your C++ code under Android Studio. 要启用本机调试,请在Android Studio下编译您的C ++代码。

With version 2.2, you can use externalNativeBuild . 在2.2版中,您可以使用externalNativeBuild For 2.1, you only have the experimental Gradle plugin. 对于2.1,您只有实验性 Gradle插件。 Unfortunately, it is not completely integrated into AS, eg File/Project Structure (aka Ctrl-; ) does not understand these build.gradle files. 不幸的是,它没有完全集成到AS中,例如文件/项目结构 (又名Ctrl-; )不理解这些build.gradle文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM