Friday, November 22, 2024

Delphi mobile development gripes

 This post is going to be a bit of a rant, but hopefully a useful one.     Mobile development would benefit greatly from a stable, simple, future proof multi-platform IDE and framework and tools of some kind.

It's a great shame that this sort of thing doesn't exist.   You see, there's an essential complexity element, and an accidental complexity element in mobile development, and here's the problem


1. The two big mobile platforms are endlessly mutating, each away from its own previous iterations. iOS moves faster and breaks more often, and Apple adds onerous new hoops to jump through more frequently than Google, but both, mostly driven by security and a desire to improve the overall quality of their app ecosystems, add more and more burdens, as years roll on.

2. The two platforms each require tools which change frequently.   Google's worse in this regards, as the various levels of Android SDKs and tools, and their quirks, will attest.


Delphi, and FMX (Firemonkey) are noble attempts, but they are not winning significant traction in the market with the product, and it's not hard to say why.   It's been an incredibly hard uphill battle to fight with Apple, and Google, and then build a native code compilation system (Delphi loves to be native to an instruction set for a single CPU) that will never be really at home in the Android dalvik-vm centric world.  Native compilation to ARM is a better fit for iOS but the native Cocoa APIs are not easily interfaced to Delphi apps, and forever there is a need for a series of complex wrappers to make iOS development with Delphi and FMX feasible.

I spent most of the last two days trying to figure out a quirk that only occurs on Delphi 12.1,  and does not occur on Delphi 12.2, which I can't safely fix by moving an entire product to Delphi 12.2, because of potential regressions in Delphi 12.2, and which is completely inscrutable.  The problem is not yet solved, and as I write this I'm reinstalling a delphi version on a different PC for the third time.

The latest small frustration? The delphi 12.0, 12.1 and 12.2 installers have a habit of not installing the android-tools even when the installer is told to install the SDK or the android platform.   On systems where ADB.exe was installed by the installer, the path is in CatalogRepository. Once it stops doing that installation, nothing will make the install work again, that I know of. Other developers I work with don't hit this glitch, but I hit it on four different PCs. The android platforms folder is also not installing, as if some marker exists somewhere in the registry that means "don't bother installing parts the installer needs to install for android to work".



figure: SDK Manager showing the supposed adb.exe location

Here's what the dialog should look like without any errors



The problem to me with this design is there should be a button here that says "reinstall missing items", since these items ship with Delphi.

The delphi app in question, that I need Delphi 12.1 on my pc to debug, is failing to start and the android parent launcher process is attempting to relaunch it.  The only information visible is found by using Android Studio's ADB LOGCAT support, filtered to the bundle id of the mobile app to get the following repeating errors that libc is raising at startup, with a permission read in a bundle resource.   Googling and stack overflow searches come up blank.   Installing Delphi 12.2 on my pc then 12.1 then 12.2 is crazy making, and is the reason I'm ranting a bit today. 

And this in the end is the problem with not going with Android Studio, being all alone on your own tiny little sub-platform of the Android platform, and that in the end, is why I do not believe that Delphi FMX has a long term future, on any platform.   The fragmentation, the technical risk, the quirks, the bugs, there are no solutions for tiny niche commercial systems.    The market will kill it.


Anyways here's a checklist for "Delphi just won't show me my device in the Android Targets".


1. find any adb.exe running that is not the adb shown in the dialog above and terminate it.  Android Studio will have its own version, each version of delphi on your computer will be using its own, and there's no mechanism in delphi to manage these adb.exe processes.


2. make sure using SDK manager that your project is looking for ADB.exe where there actually is an adb.exe and that the platform folders and other folders in the SDK and NDK tabs exist.


3.  Refresh.


4. Reboot.


5. Look for on-device messages to allow you to do USB debugging. Answer yes when prompted.


6. Make sure USB debugging is enabled on your device, or adb.exe won't find your machine.


There are about 50 more tips to make this really work, but it's so frustrating, and that's without all the bugs building, signing, deploying and getting apk and aab files into app stores.



If anyone has seen this error with delphi 12, the app crashes at startup, the debugger in 12.1 won't attach, and the logcat shows this

Access denied finding property "ro.vendor.pref_scale_resolution"

There are also messages from libMEOW that appear to just be noise:

2024-11-22 15:48:59.786 10985-10985 Compatibil...geReporter com.***           D  Compat change id reported: 149924527; UID 10217; state: ENABLED

2024-11-22 15:48:59.786 10985-10985 Compatibil...geReporter com.***           D  Compat change id reported: 132649864; UID 10217; state: DISABLED

2024-11-22 15:49:02.876 11358-11358 NetworkSecurityConfig   com.***           D  No Network Security Config specified, using platform default

2024-11-22 15:49:02.877 11358-11358 NetworkSecurityConfig   com.***           D  No Network Security Config specified, using platform default

2024-11-22 15:49:02.878 11358-11358 libc                    com.***           E  Access denied finding property "ro.vendor.pref_scale_resolution"

2024-11-22 15:49:02.888 11358-11388 libMEOW                 com.***           D  meow reload base cfg path: na

2024-11-22 15:49:02.888 11358-11388 libMEOW                 com.***           D  meow reload overlay cfg path: na

2024-11-22 15:49:02.889 11358-11388 libMEOW                 com.***           D  applied 1 plugins for [com.***]:

2024-11-22 15:49:02.889 11358-11388 libMEOW                 com.***           D    plugin 1: [libMEOW_gift.so]:

2024-11-22 15:49:02.923 11358-11358 Compatibil...geReporter com.***           D  Compat change id reported: 149924527; UID 10217; state: ENABLED

2024-11-22 15:49:02.924 11358-11358 Compatibil...geReporter com.***           D  Compat change id reported: 132649864; UID 10217; state: DISABLED

2024-11-22 15:49:08.017 11602-11602 NetworkSecurityConfig   com.***           D  No Network Security Config specified, using platform default

2024-11-22 15:49:08.018 11602-11602 NetworkSecurityConfig   com.***           D  No Network Security Config specified, using platform default

2024-11-22 15:49:08.019 11602-11602 libc                    com.***           E  Access denied finding property "ro.vendor.pref_scale_resolution"

2024-11-22 15:49:08.029 11602-11629 libMEOW                 com.***           D  meow reload base cfg path: na

2024-11-22 15:49:08.029 11602-11629 libMEOW                 com.***           D  meow reload overlay cfg path: na

2024-11-22 15:49:08.031 11602-11629 libMEOW                 com.***           D  applied 1 plugins for [com.***]:

2024-11-22 15:49:08.031 11602-11629 libMEOW                 com.***           D    plugin 1: [libMEOW_gift.so]:

2024-11-22 15:49:08.065 11602-11602 Compatibil...geReporter com.***           D  Compat change id reported: 149924527; UID 10217; state: ENABLED