Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:01:23+00:00 2026-06-01T11:01:23+00:00

I am trying to debug a C++ native code on Android device using NDK.

  • 0

I am trying to debug a C++ native code on Android device using NDK.

The Android.mk already has the debug flags:

APP_OPTIM:= debug
LOCAL_CFLAGS    := -DRAPIDXML_NO_EXCEPTIONS
LOCAL_CFLAGS    += -g
LOCAL_CFLAGS    += -ggdb
LOCAL_CFLAGS    += -O1

I also tried with the flag -O0 instead of -O1.

And the AndroidManifest.xml has also the debug mode:

     android:debuggable="true"

So, here we go… I put some breakpoints in the code to watch it step by step. Went to the terminal and typed:

$ adb shell ps |grep packtpub
app_57    24084 117   467368 49136 ffffffff 00000000 S com.packtpub.app3D

Then run the debug:

$ ndk-gdb --verbose --force
...
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: /home/android-sdks/platform-tools/adb forward tcp:5039 localfilesystem:/data/data/com.packtpub.app3D/debug-socket
## COMMAND: /home/android-sdks/platform-tools/adb shell run-as com.packtpub.app3D lib/gdbserver +debug-socket --attach 1822
## COMMAND: /home/android-sdks/platform-tools/adb pull /system/bin/app_process ./obj/local/armeabi/app_process
Attached; pid = 1822
Listening on sockaddr socket debug-socket
Pulled app_process from device/emulator.
## COMMAND: /home/android-sdks/platform-tools/adb pull /system/lib/libc.so ./obj/local/armeabi/libc.so
Pulled libc.so from device/emulator.

The application starts and run. But no break points show up. Neither the (gdb) prompt appears to allow me to set commands.

I tried both ways: from Eclipse IDE, and from console using the command line. And the same happens.

Any suggestion how to spot what is missing to put the debug on and have the breakpoints working?

All comments and suggestions are highly appreciated.


So… I keep fighting to solve why the ndk-debug is not running. Maybe I came across something that can shed a little light on it:

I have also added to Android.mk:

APP_MODULES := callbacks
APP_PLATFORM := android-14

On command line in the terminal:

$ android update project -p . --target android-14

It gives the message:

Error: Target id 'android-14' is not valid. Use 'android list targets' to get the target ids.

Then we obtain the output when running the list targets:

$ android list targets
id: 1 or "android-15"
Name: Android 4.0.3
Type: Platform
API level: 15
...
id: 2 or "Google Inc.:Google APIs:15"

On the other hand it compiles and builds on command line only if I put ‘android-15’, but it will not run in the device (a Samsung Nexus), which has the ‘android-14’. In the AndroidManifest.xml it was setup as 14, to allow the App to compile, load and run in the device from the Eclipse IDE:

<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="14">

In Eclipse IDE it compiles and runs with no complaints as Android-14. When asked to run ndk-debug on Eclipse IDE, it also doesn’t complaint as shown mentioned in my previous post, but neither the (gdb) appears.

However, when I try to run the ndk-debug on command line it complains and shows that it is not attaching the debugger:

$ ndk-gdb --verbose --force
...
Launched gdbserver successfully.
## COMMAND: /home/android-sdks/platform-tools/adb shell run-as com.packtpub.app3D lib/gdbserver +debug-socket --attach 7722
## COMMAND: /home/android-sdks/platform-tools/adb pull /system/bin/app_process ./obj/local/armeabi/app_process
Cannot attach to process 7722: Operation not permitted (1)
Pulled app_process from device/emulator.

The ndk-gdb not working has something to do with the target version?

Any suggestions or workaround that might fix it and make possible to have active breakpoint to debug NDK?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:01:25+00:00Added an answer on June 1, 2026 at 11:01 am

    Solved the problem installing the API 14 in the debugging environment,and creating a new project entirely as API 14. Now it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to debug some native code I built using the android ndk-build script
I'm trying to debug an android app that call native code to do some
I am trying to debug native C code for an Android application, where I
I'm trying to debug an access violation error in some native code, and I
I am trying to pass a preprocessor define into my native code using the
I am trying to debug some problems in a native C++ COM DLL I
I am having real problems trying debug my code to malfunctioning print statements. I
I'm trying to debug a deadlock in a multi-threaded Python application after it has
I'm trying to debug a native shared library that my App uses through JNI.
I'm trying to debug and step through an Android application that segfaults. I've tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.