[LAMW] Debug Apk From IDE lazarus / 43-Android ---------------------------------------------------------------------- jmpessoa · 2021-01-21 15:31 New! "Debug Apk From IDE"  by  @leopreo ref. https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/LAMW_De bugApkFromIDE.txt Thanks to @leopreo! PS. dependency/required package "LazDebuggerFpGdbmi" ---------------------------------------------------------------------- rsu333 · 2021-01-22 15:29 Thanks for your great job. ---------------------------------------------------------------------- rsu333 · 2021-01-24 05:40 Kindly explain the importance of above method over previous  method of  debugging. I have try it on laz4and. in another folder , girdle 6.>,  fetal at  build step. You have also explain key store in debugging which I can't do easily . Is there any google friendly debugging method ? Or can do any changes in debugging option ? Please ---------------------------------------------------------------------- Segator · 2021-01-24 13:34 I think that you not need the keystore in debugging option, when the app work fine then you change from debugging to release and then use keystore. ---------------------------------------------------------------------- Leopreo · 2021-01-26 13:47 26.01.2021: Add chipset ARMv7a+Soft and test it on AVD Android Emulator (Device Nexus 9 [5.1.1-API22] Google APIs ARM (armeabi-v7a)), Setup in gdbmiserverdebuggerlamw.pas SIG33 & SIG35 to "nopass nostop noprint" (blocks real time events), add for localhost command "adb forward tcp:port tcp:port" https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/LAMW_De bugApkFromIDE.txt ---------------------------------------------------------------------- Segator · 2021-02-11 15:39 i can't find the ...android-ndk-r10e\toolchains\arm-linux- androideabi-4.9\prebuilt\windows\bin\arm-linux-androideabi-gdb.exe binary in that place exits other like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i arm-linux- androideabi-g++.exearm-linux-androideabi-gcc.exearm-linux-androideabi- gcc-4.9.exearm-linux-androideabi-gcc-4.9.x.exearm-linux-androideabi- gcc-ar.exearm-linux-androideabi-gcc-nm.exearm-linux-androideabi-gcc- ranlib.exearm-linux-androideabi-gcov.exearm-linux-androideabi-gcov- tool.exearm-linux-androideabi-gprof.exe but not gdb, what can i do? ---------------------------------------------------------------------- juank1971 · 2021-02-11 16:01 yes i have in C:\LAMW\android-ndk-r10e\toolchains\arm-linux- androideabi-4.9\prebuilt\windows\bin\arm-linux-androideabi-gdb.exe donwload android-ndk-r10e again and uncompress ---------------------------------------------------------------------- juank1971 · 2021-02-11 16:04 this is ---------------------------------------------------------------------- Segator · 2021-02-12 22:26 thanks @juank1971 i will try it. ---------------------------------------------------------------------- Segator · 2021-02-17 16:57 i try other ndk version the file is not present, i try with the 64bits versions 16b and 18b, is only present in the 32 bits version or the 10e like the tutorial? ---------------------------------------------------------------------- Leopreo · 2021-02-18 15:46 32bit: android-ndk-r18b\prebuild\windows\bin\gdb.exe 64bit: android-ndk-r18b\prebuild\windows-x86_64\bin\gdb.exe ---------------------------------------------------------------------- Segator · 2021-02-19 01:12 thanks @Leopreo i will try it. ---------------------------------------------------------------------- cappe · 2021-04-10 07:27 Thanks for this implementation. I wanted to ask if it is possible to debug also by launching the apk on a physical device. I tried, with emulator it works fine, but on a physical device it gives me this error: Messaggi, suggerimenti: 2 Verbose: Selected chip architecture: armeabi-v7a Verbose: Taking libraries from folder: C:\lamw\test\canccanc\AppLAMWProject2\libs\armeabi-v7a Verbose: Found library: libcontrols.so Note: Duplicate unit "controls" in "controls", orphaned ppu "C:\lamw\test\canccanc\AppLAMWProject2\obj\controls\controls.o" Note: Duplicate unit "controls" in "LCLBase 2.0.0.4", ppu="C:\lamw\laz4android2.0.0\lcl\units\arm-android\controls.ppu", source="C:\lamw\laz4android2.0.0\lcl\controls.pp" Compila il progetto, OS: android, CPU: arm, Destinazione: C:\lamw\test\canccanc\AppLAMWProject2\libs\armeabi-v7a\libcontrols.so: Successo Building APK (Gradle)... : Successo Starting APK (Gradle)... : Successo  Get CPU Abilist: Successo  Get Build Version Sdk: Successo Scan org.lamw.applamwproject2 PID...: Successo  Pull /system/bin/app_process32 to C:/lamw/test/canccanc/AppLAMWProject2/gdb: Successo  Pull /system/bin/linker to C:/lamw/test/canccanc/AppLAMWProject2/gdb: Successo  Pull /system/lib/libc.so to C:/lamw/test/canccanc/AppLAMWProject2/gdb: Successo Adb forward tcp:2021 tcp:2021: Successo 2021 Start(run-as org.lamw.applamwproject2 lib/gdbserver --multi :2021): Codice di uscita 234, Errori: 1 run-as: Package 'org.lamw.applamwproject2' has corrupt installation Panic: lo strumento ha terminato con codice di uscita 234. Usare il menu contestuale per maggiori informazioni. Exception, Errori: 1 Fatal: [Exception] Failed: Cannot start(run-as org.lamw.applamwproject2 lib/gdbserver --multi :2021) Is it possible to debug on a physical device? ---------------------------------------------------------------------- Leopreo · 2021-04-13 06:21 Yes. It is possible. 1. Check device debug permissions 2. Android 8 (Android 8.1) has system bug - problem start gdbserver 3 Change NDK version (android-ndk-r10e tested) ---------------------------------------------------------------------- Tomi · 2021-04-16 10:45 Hello everybody! Yesterday I installed some android packages into Lazarus based on this video: https://youtu.be/1BH460c9_Aw Everything works, except that when I launch a new android project, Lazarus can't build APK, because of fpc.exe doesn't support arm- android (it is an error message). What should I do? Maybe can I install arm-android with fpcupdeluxe program? ---------------------------------------------------------------------- rsu333 · 2021-04-18 06:25 This is also good , example video ,But I suggest to upgrade it by LAMW manager. ---------------------------------------------------------------------- jluixjurado · 2022-09-27 18:37 Hi there! I'm trying to debug from IDE but with not luck so far. First of all, I'm using the ndk bundled with last version of LAMW (updated) In that version, the gdb is in C:\lamw_manager\LAMW\sdk\ndk- bundle\prebuilt\windows-x86_64\bin\gdb.exe I've followed the steps in LAMW_DebugApkFromIDE.txt to the 14th with success. The Messages Window says:      Listening on port 2021      Remote debugging from host 127.0.0.1, port 57975 <--???      Attached; pid = 20562 BUT, the app is frozen in my (real) device and, when setting breakpoints in any code line, the ? symbols appears (like not really connected) I'm using Windows 10 btw. Any idea would be greatly appreciated! ---------------------------------------------------------------------- jluixjurado · 2022-09-28 06:48 Ok, I've downloaded the android-ndk-r10e package and it's working! Superb! ---------------------------------------------------------------------- iwizard · 2024-02-12 13:52 Does anyone use the latest version of lamw and newer NDK versions such as 19c and above? Did the experiment debug function succeed in the end? I use the latest lamw version, tried 19c (32bit_win), 20b (32bit_win), 21e (32bit_win/64win_win) all failed, basically in the last step of attaching the process, you can attach the process pop-up window and you can select the current program to be debugged, but then it will be stuck, unable F9 ---------------------------------------------------------------------- iwizard · 2024-02-14 08:46 After a few days of trying, I think that the gdb program provided by ndk is incompatible with the relevant method implementation in TGDBMIDebugger in lazarus, search for alternatives on the Internet, and find the "GDB 7.4.1 for Android with NEON support" provided by the https://gnutoolchains.com/android/ website, use gdb, GDBserver replaces the program with the same name in ndk R19C (this GDB7.4.1 only supports ARM platform) and can be smoothly debugged on Android real machines! ---------------------------------------------------------------------- maxerist · 2024-03-11 13:07 Quote from: iwizard on February 14, 2024, 09:46:31 am... and find the "GDB 7.4.1 for Android with NEON support" provided by the https://gnutoolchains.com/android/ website, use gdb, GDBserver replaces the program with the same name in ndk R19C (this GDB7.4.1 only supports ARM platform) and can be smoothly debugged on Android real machines! ;) Many thanks for the info. I postponed the debug setup in my case until the moment it became essential to do. Side note: LAMW is a great tool, but when going advanced many small tasks/obstacles turns the development into a minefield :) Step-by-step debugging makes it much less painful. More details for those who finds it still scary. I didn't believe but it worked. My initial setup used NDK r19c - x86_64, I downloaded 32-bit version, copied to an alternative folder (ndk32) and changed the setting "Path to Android NDK" to this one and LAMW automatically detected NDK Prebuild setting. The gnutoolchains instructions were slightly different. There's no arm-linux-androideabi-gdb.exe in the r19c "toolchains\arm-linux-androideabi-4.9\prebuilt\windows\bin" folder so I simply copied. The target folder for gdbserver copy operation is "prebuilt\android-arm\gdbserver"Then one just more or less should follow the instructions about enabling debugging from https://github.c om/jmpessoa/lazandroidmodulewizard/blob/master/docs/LAMW_DebugApkFromI DE.txt. The path to the gdb is where the new executable is placed (arm-linux-androideabi-gdb.exe). Also no need for IDE recompilation as the note said, it probably was needed when the feature was introduced. The modern LAMW is already debug-friendly This simple steps allowed step-by-step debugging on an external tablet. This particular working example was tested on Windows 7, Lazarus 2.2.2, Fpc 3.2.2 cross-compiled with FPCUPdeluxe for hardware floating point (VFPv3), LAMW 0.8.6 and an external android tablet. Happy debugging :) ---------------------------------------------------------------------- maxerist · 2024-03-13 11:11 It looks like if one wants to debug several projects while keeping the same Android session running on the device, there  might be obstacles to this. In my case I tried to switch from a current app I'm extending to an existing demo (com.example.appdemo1). After launching the first one once, the second one refused to debug with with the error "Fatal: [Exception] Failed: Cannot kill last gdbserver PID=...".  What the following inquiry showed is LAMW debugger installs gdbserver  (implicitly probably) together with the primary apk. This process  (gdbserver) keeps running after the program finishes. Both the main program and apk are listed as running from the same "user", for example u0_a254. This info is available with [adb shell ps -A] command When a new install/run is launched, the script from "lazandroidmodulewizard-master\ide_tools\apkbuild.pas" (TApkBuilder.KillLastGdbServer) tries to kill the gdbserver if it is found in (probably ps ) output. It does this with "run-as" having the package name of the main app. This routine always works while I'm at the same project (the same package name) But if I switch to another program and try to run/debug it, obviously the script will try to kill the running gdbserver instance as another package and fails. The user in this case is different, for example u0_a252, but it is irrelevant since Android itself assigns new users to new installations, but for us it's important because gdbserver comes together with the package as one "user" So in order to debug a couple of android apps one has the following choices Restart the android device everytime it is necessary to switch the app for debuggingUse the equivalent adb commands (run-as, kill) for killing gdbserver manually before switching to another app. Please let me know whether some other options or fixes are available. Thanks