Recent

Author Topic: Some basic questions about LAMW  (Read 2369 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Some basic questions about LAMW
« on: November 12, 2019, 10:29:33 am »
Hello, after a few days of working with LAMW I would have questions about behavior that I don't understand.

1. If I connect my phone to the PC with the USB cable and "Build android APK and run" it does not always install / update the application on my phone. Sometimes yes (a few times) and sometimes not (many times). I don't understand how to do it.

2. Can I debug my programs from the ID by installing the application on my phone (obviously point 1 must work first)?

I forgot, I use ubuntu as an OS.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Some basic questions about LAMW
« Reply #1 on: November 13, 2019, 12:06:09 am »
1. If I connect my phone to the PC with the USB cable and "Build android APK and run" it does not always install / update the application on my phone. Sometimes yes (a few times) and sometimes not (many times). I don't understand how to do it.

The Messages window is your friend there. (IDE > Menu > View > Messages). Ensure that messages are not filtered, and then see what happens when you try to build the APK and run it. Is it a syntax error that stops the build? Or is it an error while building the APK? Or does it freeze while launching the APK on the device?

Also, I configure the device to stay awake and with the screen on all the time while connected to the USB, that speeds things up and avoids a few problems.

2. Can I debug my programs from the ID by installing the application on my phone (obviously point 1 must work first)?

If you mean to do things like putting breakpoints in the code and running it on the phone and following the execution on the IDE -- no, that cannot be done.

The main tool for debugging is logcat. If you're not familiar with it, that should be the next thing for you to learn.

Personally, I found it useful to make two versions of my apps, one for Android and one for Windows, which share the business logic units. (Obviously the UI units are different and separate). This takes a little more work at first, but brings 2 benefits: One, forcing myself to separate UI from business logic makes for better code, easier to maintain, easier to port to other OSs, etc. And Two, I can debug the business logic of the app very easily in the Windows version, with breakpoints and all that, which would be impossible otherwise. This saves a huge amount of time. I can fix bugs in minutes with breakpoints, which otherwise would take ages with trial and error and lots of extra coding if I can only run the code on a phone.

Hope this helps...
manlio mazzon gmail

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Some basic questions about LAMW
« Reply #2 on: November 13, 2019, 09:01:14 am »
Thank you for replying. Regarding point 1, the messages simply do not report any errors to me, fill in everything but in the end it does not update the app on my mobile. For point 2 I thank you too I keep the separate logic and the text on the PC, but I wanted to understand how to debug the graphic iteration with the app. Having said that I will follow your advice.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Some basic questions about LAMW
« Reply #3 on: November 13, 2019, 09:51:27 am »
Regarding the first point, the last message of a successful APK deployment should be (like in the attached image, in Windows):
...Starting APK(gradle|ant)...: Success!

Do you see that message?

You see that message and the app doesn't launch?

Or do you see a different message?
manlio mazzon gmail

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Some basic questions about LAMW
« Reply #4 on: November 13, 2019, 10:58:28 am »
Look. Only one difference. I use Ant
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Some basic questions about LAMW
« Reply #5 on: November 13, 2019, 03:26:37 pm »
I'm also fairly new with LAMW, but looking at your messages it looks very much like the app has been successfully built, installed on the device, and launched. I'm not 100% sure, but the last green message means that the device has acknowledged the starting of the app.

And by the way, are you using a real device? Emulators are not reliable.

So, some possible scenarios:

1. The app starts, and ends immediately. You can find out by checking the logs with catlog.

2. Some settings in the phone prevent the app from working properly.

These are the Settings > Developer options, that work for me:

Stay awake = ON

USB debugging = ON

Wait for debugger = OFF

Verify apps over USB = OFF

Dont keep activities = OFF

Show ANR = (I keep it OFF, but in this case you may try to put it ON -- ANR = Application Not Responsive)
manlio mazzon gmail

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Some basic questions about LAMW
« Reply #6 on: November 13, 2019, 03:33:25 pm »
One last tip if you don't do it already:

Step 1, before launching the app:

IDE > Tools > LAMW ... > ADB Logcat > Logcat -c [clear]

(This will remove old messages, so later you don't have to search among 100,000 lines)

Step 2, immediately after something goes wrong (e.g. app doesn't start)

IDE > Tools > LAMW ... > ADB Logcat > Logcat -d [dump]

Then, go through the logs in the Messages window, look for the signature of your app (search for your package name, e.g. "appscrollingimages" as in your screenshot) and look for error messages, especially the the stand-alone letter F which means Fatal error, i.e. the app crashed and was terminated.
manlio mazzon gmail

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Some basic questions about LAMW
« Reply #7 on: November 14, 2019, 09:13:09 am »
Manlio I also tried your advice. But this happens.
I install the first version of my program on the phone.
I try it and the application (ver. 1) runs correctly on the phone.
Modify the content of a jTextView (ver. 2), Build Android Apk and Run, the phone opens the ver. 1
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Some basic questions about LAMW
« Reply #8 on: November 14, 2019, 09:07:24 pm »
A. If a build doesn't seem to include all the changes you made, go Lazarus IDE > Run > Clean up and Build ...  and after that, do another Build APK and run.

B. To be sure the phone is running the latest build, I do this:

1. Have the phone screen always on when connected to USB.

2. I leave the previous version of the app running on the phone. I can see it on the phone's display.

3. I go Ctrl-F1 on Lazarus (that's Build APK and run on Windows).

4. I keep my eyes on the phone. When Lazarus finishes building the APK, and prepares to install the new version on the phone, the app on the phone will disappear for a second. (It is terminated by Lazarus via adb). And then it will appear again, when the latest version has been installed and started.

Therefore, if I see the app disappearing and reappearing, I'm sure that I have the latest version running. And if some changes I made is not appearing, I try Clean up and build, I double check my code, to see if I forgot something, etc.

In your specific case, if the app on the phone disappears and reappears, and it doesn't show the changes you made, the problem must be in your code or in some files being cached too much (so Clean up and build)
manlio mazzon gmail

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Some basic questions about LAMW
« Reply #9 on: November 15, 2019, 09:16:24 am »
I tried to do as you say. It closes me and the same version reopens me even though I just did the "clean up and build". If it works for you it's probably my phone's fault. I renounce it. I'll try again when I change phone. For now I uninstall and reinstall the application all the time.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018