How to Fix Android Services Issues with RAD Studio 10.3.3 Patch
RAD Studio 10.3.3 is a powerful tool for developing cross-platform applications, including Android apps. However, some users have reported a problem with Android services when they package their apps as Android App Bundles (AAB), a new format that Google Play requires for new apps and updates. In this article, we will explain what the problem was, how Embarcadero solved it with a patch, and how you can apply the patch to your RAD Studio 10.3.3 installation.
An Android service is a component that runs in the background without a user interface, and performs tasks that are not directly related to the app's main functionality. For example, you can use an Android service to download files, play music, or sync data with a server.
To create an Android service with RAD Studio 10.3.3, you need to use the TAndroidService class, which inherits from the TService class. You also need to add a native library to your project, which contains the code that implements the service logic. The native library is generated by RAD Studio when you compile your project.
The problem was that when you packaged your app as an AAB, the native library of the Android service could not be loaded correctly by the system. This was because the base APK generated from an AAB had the extractNativeLibs manifest attribute set to false. This attribute determines whether the native libraries of an app are extracted to the file system or not when the app is installed. When it is set to false, the native libraries are not extracted and are loaded directly from the APK.
However, the Android service tried to load its native library using an absolute path that assumed that the library was extracted to the file system. This caused an error and prevented the service from running.
How does the patch fix it?
The patch modifies the way the Android service loads its native library. Instead of using an absolute path, it uses a relative path that works regardless of the extractNativeLibs attribute value. This way, the Android service can load its native library correctly whether your app is packaged as an AAB or an APK.
How to apply the patch?
The patch is available at https://cc.embarcadero.com/item/30905. It contains a readme file with detailed installation instructions. Basically, you need to do the following steps:
Download and unzip the patch file.
Close RAD Studio 10.3.3 if it is running.
Backup the original files that will be replaced by the patch.
Copy the patch files to the corresponding folders in your RAD Studio installation directory.
Rebuild your Android service project and deploy it to your device or emulator.
The patch only affects Android services, not regular Android apps. You don't need to apply the patch if you are not using Android services in your project.
Why do you need the patch?
If you are developing Android apps with RAD Studio 10.3.3, you may wonder why you need the patch and what are the benefits of using Android App Bundles. Here are some reasons why you should apply the patch and use AABs for your Android apps:
AABs are a new format that Google Play requires for new apps and updates. If you don't use AABs, you may not be able to publish or update your apps on Google Play.
AABs are more efficient than APKs. They allow Google Play to generate optimized APKs for different device configurations, such as screen size, resolution, language, and CPU architecture. This reduces the download size and installation size of your apps, and improves the performance and battery life of your users' devices.
AABs are more secure than APKs. They use a new signing scheme that protects your apps from tampering and ensures that only you can update them. You don't need to manage your own signing keys, as Google Play handles them for you.
As you can see, using AABs for your Android apps has many advantages, but it also requires some changes in the way you package and deploy your apps. The patch for RAD Studio 10.3.3 makes sure that your Android services work correctly when packaged as AABs, and that you can take advantage of the new format without any hassle.
What are the benefits of using RAD Studio 10.3.3 for Android development?
Besides fixing the Android services issue, RAD Studio 10.3.3 offers many benefits for Android development. Here are some of them:
RAD Studio 10.3.3 supports Android 64-bit development, which is mandatory for new apps and updates on Google Play since August 2019. You can create both 32-bit and 64-bit Android apps with the same code base and the same IDE.
RAD Studio 10.3.3 supports Android API level 29 (Android 10), which is required for new apps and updates on Google Play since November 2019. You can target the latest version of Android and use its new features and capabilities.
RAD Studio 10.3.3 supports Android App Bundles, which is a new format that Google Play recommends for publishing apps. You can create smaller, more efficient, and more secure apps with AABs.
RAD Studio 10.3.3 supports Firebase Cloud Messaging (FCM), which is a cross-platform messaging solution that lets you send notifications and data messages to your users. You can integrate FCM with your Android apps using the Firebase components included in RAD Studio.
RAD Studio 10.3.3 supports Android Jetpack, which is a collection of libraries and tools that help you build better Android apps. You can use Android Jetpack components such as WorkManager, Navigation, Room, and LiveData with RAD Studio.
As you can see, RAD Studio 10.3.3 is a great tool for developing Android applications, but it had a bug that prevented Android services from running when packaged as AABs. Fortunately, Embarcadero has released a patch that solves this issue and allows you to create and deploy Android services with RAD Studio 10.3.3 without any hassle.
How to create and deploy Android services with RAD Studio 10.3.3?
If you want to create and deploy Android services with RAD Studio 10.3.3, you need to follow some steps and use some components that are provided by the IDE. Here are the main steps:
Create a new Android service project using the File > New > Other > Delphi Projects > Android Service Application or C++Builder Projects > Android Service Application menu option.
Add the code that implements the logic of your service in the OnStartCommand event handler of the TAndroidService class.
Add the TLocalServiceConnection component to your main form, and set its ServiceName property to the name of your service.
Add the code that communicates with your service in the OnConnected and OnDisconnected event handlers of the TLocalServiceConnection component.
Build and deploy your Android service project to your device or emulator.
Create a new Android app project using the File > New > Multi-Device Application menu option.
Add the code that starts and stops your service using the StartService and StopService methods of the TAndroidHelper class.
Build and deploy your Android app project to your device or emulator.
You can find more information and examples about creating and deploying Android services with RAD Studio 10.3.3 in the documentation and in this blog post.
How to test and debug Android services with RAD Studio 10.3.3?
Once you have created and deployed your Android service with RAD Studio 10.3.3, you may want to test and debug it to ensure that it works as expected. Here are some tips and tools that you can use for testing and debugging Android services with RAD Studio:
To test your Android service, you can use the TAndroidServiceConnection component, which allows you to communicate with your service from your main app. You can send and receive data, start and stop the service, and bind and unbind the service using this component.
To debug your Android service, you can use the integrated debugger of RAD Studio, which supports both 32-bit and 64-bit Android apps. You can set breakpoints, watch variables, evaluate expressions, and step through your code using the debugger.
To monitor your Android service, you can use the Logcat tool, which is a command-line tool that shows the messages logged by your app and the system. You can use the Logcat tool to view the output of the Log.d method, which you can use to print debug messages in your code.
To analyze your Android service, you can use the Android Profiler tool, which is a graphical tool that shows the performance of your app in terms of CPU, memory, network, and battery usage. You can use the Android Profiler tool to identify and optimize any performance issues in your app.
You can find more information and examples about testing and debugging Android services with RAD Studio 10.3.3 in the documentation and in this blog post.
What are the best practices for using Android services with RAD Studio 10.3.3?
Android services are useful components that can perform tasks in the background without a user interface. However, they also have some limitations and challenges that you need to be aware of when using them with RAD Studio 10.3.3. Here are some best practices that can help you use Android services effectively and efficiently:
Use Android services only for tasks that are not directly related to the app's main functionality, such as downloading files, playing music, or syncing data with a server. Avoid using Android services for tasks that require user interaction, such as showing notifications, updating the UI, or requesting permissions.
Use Android services sparingly and avoid creating too many of them. Android services consume system resources and can affect the performance and battery life of your device. If you have multiple tasks that can be performed by a single service, use a single service instead of creating multiple ones.
Use the appropriate type of Android service for your task. There are two types of Android services: started services and bound services. Started services are started by an app and run until they are stopped by themselves or by the system. Bound services are bound to one or more apps and run only as long as there is at least one app bound to them. Use started services for tasks that are independent of the app's lifecycle, such as downloading files or playing music. Use bound services for tasks that depend on the app's lifecycle, such as communicating with the app or providing data to the app.
Handle the Android service lifecycle correctly. Android services have their own lifecycle methods that are called by the system when the service is created, started, bound, unbound, stopped, or destroyed. You need to implement these methods in your TAndroidService class and perform the appropriate actions in each method. For example, you need to create and initialize your service in the OnCreate method, start your task in the OnStartCommand method, stop your task and release your resources in the OnDestroy method, and so on.
Handle the app's lifecycle correctly. When your app starts or stops an Android service, or binds or unbinds to an Android service, you need to handle these actions in your app's lifecycle methods. For example, you need to start your service in the OnCreate method of your main form, stop your service in the OnDestroy method of your main form, bind to your service in the OnResume method of your main form, unbind from your service in the OnPause method of your main form, and so on.
You can find more information and examples about using Android services with RAD Studio 10.3.3 in the documentation and in this blog post.
RAD Studio 10.3.3 is a great tool for developing Android applications, but it had a bug that prevented Android services from running when packaged as AABs. Fortunately, Embarcadero has released a patch that solves this issue and allows you to create and deploy Android services with RAD Studio 10.3.3 without any hassle. If you are using Android services in your project, we recommend that you download and apply the patch as soon as possible.
In this article, we have explained what the problem was, how the patch fixes it, and how to apply the patch to your RAD Studio 10.3.3 installation. We have also given you some tips and tools for testing and debugging Android services with RAD Studio 10.3.3, and some best practices for using Android services effectively and efficiently. We hope that this article has been helpful and informative for you.
If you want to learn more about RAD Studio 10.3.3 and its features and capabilities, you can visit the official website, read the documentation, watch the videos, or join the community. You can also request a free trial or upgrade your existing license to enjoy the latest version of RAD Studio. b99f773239