I'm trying to reach a break point in a simple C++ code:
Here the .cpp
#include <jni.h>
#include <string>
extern "C"
{
jstring Java_com_comscore_android_app_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++ lalalaaaaaa";
return env->NewStringUTF(hello.c_str());
}
}
here the gradle file:
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.comscore"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=src/main/jni/Application.mk"
}
}
}
externalNativeBuild{
ndkBuild{
path "src/main/jni/Android.mk"
}
}
...
}
The Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_MODULE := native-lib
LOCAL_LDLIBS := -llog
LOCAL_CPPFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
LOCAL_CFLAGS += -fsigned-char -fexceptions -frtti -g -O0 -std=c++0x -std=gnu++0x
include $(BUILD_SHARED_LIBRARY)
And the Application.mk
APP_ABI := all
APP_STL := gnustl_static
The application compiles and works but I'm not able to stop in any breakpoint in the C++ code while running the debugger. I can see how it loads the native libraries but it doesn't stop any where and Android studio is telling me that the break point has been attached.
I'm using Android Studio 2.2 Preview 6
Can anybody help me?
If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.
To set a breakpoint in Android Studio, you need to navigate to a specific line of code and then click in the gutter next to the line number. To unset a breakpoint, you need to click an existing breakpoint in the gutter to make it disappear.
To add a line breakpoint, proceed as follows: Locate the line of code where you want to pause execution, then either click the left gutter along that line of code or place the caret on the line and press Control+F8 (on Mac, Command+F8).
To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
In my case I have two modules, one with the C++ code (library) and an other one with the application that consumes the library module.
The problem was that I tried to debug the library module uaing the app module, so I just need to specify the folder where the debug symbols are:
Run->Edit configurations... -> Debuggerand in the symbol directories tab add the right path. For instance:
/path_to_my_project/lib_module/build/intermediates/ndkBuild/flavor/debug/obj/local/x86
app.imp file contains "<"facet type="native_android_gradle">", , option=SELECTED_BUILD_VARIANT..
check if value="debug"
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