Debugging native extension on Android

I want to debug a project on android that includes a native extension. I did everything as described in the description (https://www.defold.com/manuals/extensions-debugging-android/). When I set the source path of the native extension on the path mapping and apply it, the source does not appear in the Project window on the left. So I can’t set a breakpoint.

Someone may have an idea why the source doesn’t appear? Thanks!

image

Hmm @Mathias_Westerdahl?

I wonder if this is where the Android Studio differs between macOS and WIndows?
I think I’ve seen this before, but we were unable to figure it out then.

If anyone has any tips, please give them here :slight_smile:

https://developer.android.com/studio/debug/apk-debugger

There is a warning at the bottom of the linked page:

Known issue: When attaching debug symbols to an APK, both the APK and debuggable .so files must be built using the same workstation or build server.

Couldn’t that be the reason? The “.so” file is built on the server, and the apk is locally?

2 Likes

Huh, that seems to indeed be related.
But I’m pretty sure I tested this with a server built apk together with my local source.
I guess it’s actually a path problem, i.e ”\” vs ”/”.
A classic issue, and there really is no reason Android studio couldn’t fix it.

Perhaps you can use a Linux virtual machine to debug it?

2 Likes

Thanks! I have linux on another partition, later I try there how it works, then I write the result.

2 Likes

Well, you’re right @Mathias_Westerdahl. On Linux, the source appears as it should. Thank you, you are king! :slight_smile:

3 Likes

Good to hear that it works on Linux. We need to figure out why it doesn’t work on Windows.

1 Like

Debugging also works well under linux!

What is still a problem for me is that during debugging I can’t see, for example, the contents of the lua structures being expanded on the variables tab.

Or can I find out which lua version (Lua: download area) you are built in the engine? I was thinking of downloading the source of the lua and setting it on the path mappings. If this works, which path should I set?

1 Like

We use LuaJIT 2.1.0-beta3 on all platforms except HTML5. You can pprint(jit) to see the version used. On HTML5 we use plain Lua 5.1.5 with the BitOp module from LuaJIT added.

3 Likes

Thanks! I don’t really find out which path should be mapping the source of the luajit. :frowning:

For path mappings you should choose such a path that the underlying relative paths would work in your local folder.

E.g. if the compiler says the path is “/some/dir/packagename/src/a/b/c.cpp” you should choose the package name local on your computer “/my/drive/packagename/src”

What folder does the path mapper display, and what path did you try?

1 Like

Unfortunately my English is very bad and I may not write what I really want. I’m sorry for it. I’ll try to describe what I want again.

So I would like to set the source of luajit for path maps just like my native extension.

This is shown in the picture above:
/home/coderm4ster/AdMobTest/ags_native/src -> /tmp/job3916…3044/upload/ags_native/src

I downloaded the luajit 2.1.0-beta3 source code. The question is which path to the src folder will belong to.
So /home/coderm4ster/LuaJIT-2.1.0-beta3/src -> ?

I don’t recall off the top of my head (I’m not at my computer) but the path should mention luajit.
Such libraries we build locally and I believe Sven or Johan built this library last.
So perhaps check under ”/Users/svenandersson”? I saw that in the first picture you posted.

1 Like

I checked all folders under “/Users/svenandersson” but I didn’t find any luajit folders. There are a few folders named lua, where I tried to set the luajit source, but did not appear on the left side of the Project window as the source of my native extension.

perhaps you can take a screenshot of what it looks like?

The folder tree is very long. I copied it in text, but the tree structure is not visible. In any case, I copy it into a folding box.

Folder names
svenandersson
libunwind_android
include
src
android-ndk-r10e
include
include
builder
android-ndk-r10e
include
sources
android
cpufeatures
native_app_glue
4.8
include
bits
include
build
engine
src
ddf
ddf
ddf
src
axtls
crypto
ssl
dlib
dlib
lz4
stb_image
webp
zlib
engine
default
src
src
src
gameobject
gameobject
gameobject
gamesys
proto
gamesys
glfw
GL
lib
graphics
graphics
src
src
src
src
src
input
proto
src
src
particle
particle
src
src
Box2D
Collision
Common
Dynamics
physics
src
src
record
render
render
render
resource
proto
src
rig
rig
src
script
script
src
src
tracking
default
tracking
lua
src
src
dynamo_home
include
include
axtls
crypto
ssl
crash
ddf
dlib
extension
gameobject
gamesys
graphics
gui
hid
input
liveupdate
lua
particle
physics
profiler
record
render
resource
rig
script
sound
tracking
dmsdk
dlib
extension
graphics
lua
script
cpp
android-ndk-r10e
include
include
s
ndk
include
include
toolchain
gcc-4.8
libgcc
include
include
gcc-4.8
include
libgcc
libiberty
libsupc++
tmp
job6552162596948655912
build
src file:///Users/coderm4ster/Projects/Defold/AdMobTest/ags_native/src
static-armeabi-v7a-4.8
include
libsupc++
dmsdk
dlib
extension
graphics
lua
script

Yeah, that’s really difficult to read and understand :slight_smile:

2 Likes

I look deeper into the “.so” file. You probably build the luajit independently (maybe in release mode) from the engine. Then the built luajit is statically linked to the engine. Because it is not built directly from the source into the engine, the built engine does not contain any reference to the luajit source.

If so, it explains why I can’t see the luajit at path mappings.

1 Like

Ah yes, that might indeed explain it yes.

1 Like