Skip to content

Commit 5fa5ed5

Browse files
committed
[[ Debug ]] Doc and tweaks for android debugging
This path documents how to debug and profile an android debug build using Android Studio. It also makes some minor tweaks to our builds to take a couple of steps that would need to be done each build out of the process.
1 parent a5c2a51 commit 5fa5ed5

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

docs/development/build-android.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,41 @@ The Linux build environment used for compiling LiveCode for Android is based on
133133
* openjdk-7-jdk
134134
* flex
135135
* bison
136+
137+
## Debugging & Profiling with Android Studio
138+
139+
* Build a debug build of the android engine
140+
* Inside android-XXX-bin, create a symlink librevandroid.so -> Standalone-Community
141+
(or Standalone-Commercial; whichever you're using)
142+
* Build your standalone
143+
* Start Android Studio and select "Profile or Debug APK" on the main menu.
144+
* Select the APK you built
145+
* Studio will show you the contents of your APK and there will be a banner
146+
along the top about being unable to find debug symbols. Click it and navigate
147+
to the folder where you created the librevandroid.so symlink.
148+
* Set the paths to the source folders in the panel that appears if you want to
149+
do debugging rather than profiling
150+
* On the top right of the Android Studio toolbar, there are icons for running,
151+
debugging and profiling. Select the one you want.
152+
* If Android Studio complains about the SDK not being set, select the top-level
153+
project in the left-hand tree view, right-click and go to Module Settings. Hunt
154+
through those menus for SDK/API selections and make sure they're set properly
155+
(they may default to "Java 1.8" rather than an Android SDK).
156+
* If Android Studio complains about the app not having a default activity, quit
157+
Studio and restart it. Keep doing this until it stops being stupid.
158+
* If you selected "Profile", you'll see the profiler on the bottom of the
159+
window. Click the "CPU" portion of the graphs. To do a trace, select
160+
"Sample C++ methods" from the drop down and hit Record. Perform the action you
161+
want to profile then click "Stop".
162+
* If profiling says "Advanced profiling not available", you will likely need to
163+
play around with MinimumSDK settings and the like when building the app. In
164+
particular, make sure your device is at least API26 and that the minimum API
165+
level is set to API26 too.
166+
* The threads of interest are the one at the top of the list (the main Android
167+
thread) and one further down called "Thread-2" - this is the engine thread.
168+
169+
> **Note:** When you import an APK into Android Studio, the IDE creates a new
170+
> project in your home directory under ApkProjects/, and makes a local copy of
171+
> the target APK there. This means that if you rebuild or update the original
172+
> APK, you need to manually import the updated version into Android Studio
173+
> again.

engine/engine.gyp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,23 @@
349349
[
350350
{
351351
'action_name': 'copy_manifest',
352-
'message': 'Copying manifest file',
352+
'message': 'Copying and update debuggable in manifest file',
353353

354354
'inputs':
355355
[
356356
'rsrc/android-manifest.xml',
357357
],
358-
358+
359359
'outputs':
360360
[
361361
'<(PRODUCT_DIR)/Manifest.xml',
362362
],
363363

364364
'action':
365365
[
366-
'cp', '<@(_inputs)', '<@(_outputs)',
366+
'../util/set_android_debuggable.sh',
367+
'<@(_inputs)',
368+
'<@(_outputs)',
367369
],
368370
},
369371
{

tools/extract-debug-symbols.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ for input in "$@" ; do
2424
# Extract a copy of the debugging information
2525
$OBJCOPY --only-keep-debug "$input" "$output"
2626

27-
# Because we export symbols from the engine, only debug symbols
28-
# should be stripped.
29-
$STRIP -x --strip-debug "$input"
30-
27+
if [ "$os" == "android" -a "$BUILDTYPE" == "Debug" ] ; then
28+
echo Skipping strip-debug for ${input}
29+
else
30+
# Because we export symbols from the engine, only debug symbols
31+
# should be stripped.
32+
$STRIP -x --strip-debug "$input"
33+
fi
34+
3135
# Add a hint for the debugger so it can find the debug info
3236
$OBJCOPY --remove-section=.gnu_debuglink "$input"
3337
$OBJCOPY --add-gnu-debuglink="$output" "$input"

util/set_android_debuggable.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
INPUT="$1"
6+
OUTPUT="$2"
7+
8+
if [ "$BUILDTYPE" == "Debug" ] ; then
9+
sed 's/android:debuggable="false"/android:debuggable="true"/g' "${INPUT}" > "${OUTPUT}"
10+
else
11+
cp "${INPUT}" "${OUTPUT}"
12+
fi

0 commit comments

Comments
 (0)