8

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?

Joan P.S
  • 1,553
  • 1
  • 16
  • 42
  • Look into "Create Hello-JNI with Android Studio" code lab at https://codelabs.developers.google.com/. There are differences in your code from the one on code labs, you might be using different gradle plugin - or something else. – marcinj Jul 26 '16 at 07:08
  • The example that you are pointing is not good enough, it is not using ndk-build (so no Android.mk neither Application.mk files) and each gradle versions changes a lot from release to release and it also don't provide any reference for the ndk gradle options available – Joan P.S Jul 26 '16 at 10:29
  • Did you find solution? – tower120 Feb 03 '17 at 14:22
  • Not yet... I'm using Eclipse just for debugging C++ code :( – Joan P.S Feb 04 '17 at 20:09

2 Answers2

13

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

Joan P.S
  • 1,553
  • 1
  • 16
  • 42
  • 1
    For whatever reason android studio works about 80% of the time but then gets into this scenario where it can no longer debug my c++ libraries. In this situation adding the symbol dir like this totally fixes the problem. – Medran Jan 15 '19 at 21:49
  • this answer is work for me –  Godrick Jul 31 '23 at 09:54
1

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

check if value="debug"