Android NDK debugging: armeabi-v7a not working - android

Eclipse / Cygwin
NDK 8c
Building a shared library
I can't get gdbserver to start anymore after switching to armeabi-v7a. I've searched online for hours but can't find a topic that deals specifically with armeabi-v7a debugging issues.
I have no choice to switch to armeabi-v7a due to using a third party library which depends on it. Without it, I get these kind of errors:
D:\TEMP\ccnnGAqD.s:10427: Error: selected processor does not support Thumb mode `ldrex r6,[r3]'
D:\TEMP\ccnnGAqD.s:10429: Error: selected processor does not support Thumb mode `strex r4,r5,[r3]'
It was all working fine before with 'armeabi', using this setup: http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/
The only change I've made is to add this to Application.mk:
APP_ABI := armeabi-v7a
At the very bottom of the shared library Android.mk I added this:
$(info TARGET_ARCH = $(TARGET_ARCH))
$(info TARGET_ARCH_ABI = $(TARGET_ARCH_ABI))
$(info TARGET_ABI = $(TARGET_ABI))
which outputs the following:
TARGET_ARCH = arm
TARGET_ARCH_ABI = armeabi-v7a
TARGET_ABI = android-14-armeabi-v7a
I've uninstalled the app using
adb uninstall com.example.game
AndroidManifest.xml does have the android:debuggable="true" property.
Done a "clean all" in Eclipse, and manually deleted the ./libs and ./obj folders. Then, ndk-build outputs to the right folders (obj/local/armeabi-v7a and libs/armeabi-v7a), and obj/local/armeabi and libs/armeabi do not exist.
However, here's what happens when I run ndk-gdb:
user#MACHINENAME /cygdrive/e/projects/game
$ ndk-gdb-eclipse --force --verbose
Android NDK installation path: /cygdrive/e/projects/sdks/android-ndk
Using default adb command: /cygdrive/e/projects/sdks/android-sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using auto-detected project path: .
Found package name: com.example.game
ABIs targetted by application: armeabi
Device API Level: 15
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Using gdb setup init: ./libs/armeabi/gdb.setup
Using toolchain prefix: /cygdrive/e/projects/sdks/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi
Found debuggable flag: true
ERROR: Could not find gdbserver binary under ./libs/armeabi
This usually means you modified your AndroidManifest.xml to set
the android:debuggable flag to 'true' but did not rebuild the
native binaries. Please call 'ndk-build' to do so,
*then* re-install to the device!
Notice the "ABIs targetted by application" using the wrong 'armeabi'. Here's the relevant part of ndk-gdb:
get_build_var ()
{
if [ -z "$GNUMAKE" ] ; then
GNUMAKE=make
fi
$GNUMAKE --no-print-dir -f $ANDROID_NDK_ROOT/build/core/build-local.mk -C $PROJECT DUMP_$1 | tail -1
}
APP_ABIS=`get_build_var APP_ABI`
if [ "$APP_ABIS" != "${APP_ABIS%%all*}" ] ; then
# replace first "all" with all available ABIs
ALL_ABIS=`get_build_var NDK_ALL_ABIS`
APP_ABIS_FRONT="${APP_ABIS%%all*}"
APP_ABIS_BACK="${APP_ABIS#*all}"
APP_ABIS="${APP_ABIS_FRONT}${ALL_ABIS}${APP_ABIS_BACK}"
fi
log "ABIs targetted by application: $APP_ABIS"
I clearly set APP_ABI to armeabi-v7a in Application.mk, so is this a bug in the NDK? Or am I missing something?

I had the same issue. I configured eclipse following this article.
Then I change from armeabi to armeabi-v7a. Then I couldn't debug.
I fixed this issue:
1) You must fix the folders in "Debug configurations"
Main tab change ...obj/local/armeabi/app_process to ...obj/local/armeabi-v7a/app_process
Debugger tab change ...obj/local/armeabi/gdb2.setup to obj/local/armeabi-v7a/gdb2.setup
Debugger tab change .../toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb to toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb
2) May be this is workaround but it works. In "Debug configurations" ->Debugger->Shared Libraries add <project path>/obj/local/armeabi-v7a and check "Load shared library symbols automatically"

Related

Build CMake library without Android-Studio (by command-line or GUI)

It seems, Android-Studio sets specific CMake options,
And I can not build with command-line (outside of Android-Studio) no matter what I tried!!
Is there any way to build an Android project's CMake library without even opening Android-Studio?
Note: I already found solution and will share answer to this shortly.
Yes there were some options and/or variables that need to be set for CMake command-line build to work (without even opening Android-Studio).
1. Firstly, create the my-toolchain.cmake file (beside your project, maybe in config dir), with content below:
#
# Allows compiling outside of Android-Studio.
#
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_TOOLCHAIN_DIRECTORY "$ENV{ANDROID_HOME}/ndk-bundle/build/cmake")
if(NOT CMAKE_TOOLCHAIN_FILE)
if(NOT ANDROID_ABI)
# Default to 32 Bit ARMv7 CPU.
set(ANDROID_ABI "armeabi-v7a")
endif()
if(NOT ANDROID_PLATFORM)
set(ANDROID_PLATFORM "android-15")
endif()
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_DIRECTORY}/android.toolchain.cmake")
endif()
if(WIN32 AND NOT CMAKE_MAKE_PROGRAM)
set(CMAKE_MAKE_PROGRAM "$ENV{ANDROID_HOME}/ndk-bundle/prebuilt/windows/bin/make.exe" CACHE INTERNAL "" FORCE)
endif()
2. Secondly, Add the file created in last step into your project, for example:
cmake_minimum_required(VERSION 3.2)
# Detect toolchain.
include(config/my-toolchain.cmake)
project(MyProject C CXX)
# ... and so on ...
3. Finally, in console cd where your CMakeLists.txt file is, and build with commands like:
cmake -H. -B .build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DANDROID_PLATFORM=android-14 -D ANDROID_ABI=armeabi-v7a
cd .build
"%ANDROID_HOME%\ndk-bundle\prebuilt\windows\bin\make.exe" install INSTALL_ROOT="%CD%\.build"
Note that last command of Step-3 changes based on your operating-system, but above should work for Windows if you have ANDROID_HOME environment-variable set to Android-SDK root directory (which of course, needs NDK extracted in ndk-bundle sub-dir).
All done!
Just repeat Step-3 for each CPU architecture, i.e. change ANDROID_ABI to one of possible options:
armeabi-v7a, arm64-v8a, x86, x86_64, mips, mips64
Although, mips and mips64 are deprecated by now (and Android NDK r16b was last version supporting them).

ndk-gdb cannot find gdb.setup but it is there under x86

Cocos2d-x 3.7.1 + ndk r10e project on Mac trying to debug in Eclipse. Days pass and the errors keep coming...
I can build and run using cocos compile and cocos run with -p android -m debug --ndk-mode NDK_DEBUG=1 from the terminal in proj.android.
My app runs Ok (eventually) on my x86 emulator no problem.
Typing 'ndk-gdb' in the terminal from ./proj.android and I get the error
ERROR: Could not find gdb.setup under ./libs/
BUT the file gdb.setup (and gdbserver & libcocos2dcpp.so) can be seen in ./proj.android/libs/x86 !?
My AndroidManifest.xml includes android:debuggable="true"
My jni/Application.mk includes APP_ABI := x86 (only)
If anyone can tell me how I can diagnose or fix this problem then I guess I owe them a beer (in Yorkshire btw)
UPDATE: I have tried running up GDB using the --verbose flag. The output shows
Using gdb setup init: ./libs/armeabi/gdb.setup
Using app out directory: ./obj/local/armeabi
Guess I need to change to settings/init file somewhere??
I ran into the same problem. It seems something changed in recent version of Android Build tools.
The trick is:
ERROR: Could not find gdb.setup under ./libs/
It expects gdb.setup is in the directory libs but NOT libs/armeabi
so the simple workground is to copy gdb.setup and gdbserver from "libs/cpu" to "libs" and it works like a magic!
This is a bug caused by adb from android sdk.Issue 191085: ndk-gdb issue - Could not find gdb.setup under ./libs/ (even though it's there)
Currently previewl channel's adb whose version is 1.0.35 still has the same problem.
Without revert adb to 1.0.31.A simple workaround would be modify ndk-gdb a little: change the line if [ $? = 0 ]; then which is below adb_var_shell BCFILES run-as $PACKAGE_NAME /system/bin/sh -c "ls lib/*.bc" to if [ $? = 1 ]; then

How do I build Libgdx.so from source for Android with gdb tracing enabled?

I have setup a debug ROM on an Android device, and enabled the DDMS Native Heap in search for a libgdx memory leak.
I now have a trace, but no source code attached to follow the lead.
I downloaded libgdx source code.
How do I build it enabling gdb tracing so I can follow the code referenced by the trace ?
Update:
I built the debug .so libgdx from source
To do this, I modified the file:
libgdx/gdx/jni/build-android32.xml
Adding to the compile-natives target
I also added APP_OPTIM := debug to the Application.mk in the same folder
And added '-g' to the Android.mk file in the same folder:
LOCAL_CFLAGS := -g $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__
This, indeed, produces a dbg libgdx.so dynamic library place in
libgdx/gdx/libs/armeabi
Although I am getting closer, I still cannot get the name of the function that is loading memory.
I am using arm-linux-androideabi-addr2line and the Hex address of the function, but it prints
??
Download the Android Source and build it.
Point DDMS to the libs with debug symbols. On the command line:
export ANDROID_SYMBOLS=$ANDROID_SOURCE/out/target/product/flo/symbols/system/lib
Note that $ANDROID_SOURCE refers to the location where you built the Android source.
start DDMS from that shell
$ddms
Now you should see the native traces on ddms.
I also built libgdx from source and added $LIBGDX_SOURCE/libgdx/gdx/obj/local/armeabi/libgdx.so
to $ANDROID_SOURCE/out/target/product/flo/symbols/system/lib to see the method names for libgdx.so.
Preliminaries
You need to set the device to debug memory
adb root
adb shell setprop libc.debug.malloc 1
adb shell stop
adb shell start
The device must be rooted or with a dbg ROM.

Android ndk-build not generating gdb.setup file

I am currently trying to debug native code in Android via ndk-gdb but I am having some troubles.
Even if I start a very simple project (let's say for example a default cocos2d-x v3 project) and run
ndk-build NDK_DEBUG=1
I end up with the following folder structure inside my android project
...
libs/
armeabi/
libcocos2dcpp.so
...
instead of the expected:
...
libs/
armeabi/
gdb.setup
gdbserver
libcocos2dcpp.so
...
In order to use ndk-gdb I need those two gdb files.
I am using cocos version 3.2 and Android NDK version r9d.
Isn't NDK_DEBUG=1enough for the gdb files to be generated? I have also tried withandroid:debuggable="true" inside my manifest file but it didn't work.
Edit
After running the command suggested by Digit I found a very suspicious line
Android NDK: Application 'local' forced *not* debuggable through NDK_DEBUG
when running the command ndk-build NDK_LOG=1 NDK_DEBUG=1
BUT
if I change to ndk-build NDK_LOG=1 NDK_DEBUG=true I get
Android NDK: Application 'local' forced debuggable through NDK_DEBUG
So it is ok now, really weird though how =1 is not considered true.
Can you paste the output of 'ndk-build NDK_LOG=1 NDK_DEBUG=1', this should contain more information about what ndk-build is doing, and is likely to provide an explanation.

Android Application ABI and Native Debugging

I was getting 'Unable to detect application ABI's' when trying to natively debug in Eclipse. I didn't get anywhere so I tried ndk-gdb (ndk-gdb.py as I am on Windows).
But using ndk-gdb gives me :
ERROR: The device does not support the application's targetted CPU ABIs!
Device supports: armeabi-v7a armeabi
Package supports: .
This happens because the ndk-gdb.py function :
def get_build_var(var):
global GNUMAKE_CMD, GNUMAKE_FLAGS, NDK, PROJECT
text = subprocess.check_output([GNUMAKE_CMD,
'--no-print-dir',
'-f',
NDK+'/build/core/build-local.mk',
'-C',
PROJECT,
'DUMP_'+var] + GNUMAKE_FLAGS
)
# replace('\r', '') due to Windows crlf (\r\n)
# ...universal_newlines=True causes bytes to be returned
# rather than a str
return text.decode('ascii').replace('\r', '').splitlines()[0]
returns a '.' when asked for APP_ABI. I have dummped the subprocess make call parameters and when I execute the make call from the command line I get the correct response of 'armeabi-v7a armeabi'
I don't think this is to do with python as the error is so similar to my Eclipse only problem.
Try to run ndk-build DUMP_APP_ABI and make sure the output is clean. Check you Application.mk for weird encoding and/or CRLFs.
All use of $(info …) or $(__ndk_info), etc. should be disabled for this target.

Categories

Resources