Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to reach a break point in C++ using Android Studio and ndkBuild

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?

like image 598
Joan P.S Avatar asked Jul 26 '16 06:07

Joan P.S


People also ask

Why are breakpoints not working?

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.

Can you set breakpoints in Android Studio?

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.

How do you add a breakpoint in Android?

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).

How do you debug a break point?

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.


2 Answers

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

enter image description here

like image 157
Joan P.S Avatar answered Oct 04 '22 00:10

Joan P.S


app.imp file contains "<"facet type="native_android_gradle">", , option=SELECTED_BUILD_VARIANT..

check if value="debug"

like image 36
Franc Zupan Avatar answered Oct 03 '22 23:10

Franc Zupan