I have started using Java Native Interface (JNI) recently and encountered some problems that I hope you could help me to solve.
I am using Android Studio 2.1.1, SDK Tools 25.1.7, NDK 12, API 21.
1.My main problem is that i cannot debug the C code, only the 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.2 I have added the SDK\\NDK path to the Android Studio Project Structure.
1.3 I have added to the 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.5 Attaching my Android.mk, Application.mk, build.gradle, C code and files.
1.6 The code is running and working, it doesn't hit the breakpoints inside the C code.
2.how can i monitor the heap and stack usage of my code and especially the of the JNI? also is it changeable?
3.on the same matter as 2. how can i decrease the dependency in the heap? will defining my variables as static do the trick?
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sub
LOCAL_SRC_FILES := subst.c
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := all
APP_BUILD_SCRIPT := C:\Users\Nir\AndroidStudioProjects\FirstApp\jni\Android.mk
C code
jdouble Java_nir_firstapp_MainActivity_subst(JNIEnv* env, jobject obj, jdouble A, jdouble B)
{
int x;
x=A-B;
return(x);
}
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
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.
With version 2.2, you can use externalNativeBuild . For 2.1, you only have the experimental Gradle plugin. Unfortunately, it is not completely integrated into AS, eg File/Project Structure (aka Ctrl-; ) does not understand these build.gradle
files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.