Using a Custom Set of Java Libraries In Your RAD Studio Android Apps
RAD Studio allows you to use your own or third-party Java libraries in RAD Studio applications.
To use a custom set of libraries in your RAD Studio Android applications:
- Ensure that your Java libraries meet the RAD Studio requirements for Java libraries.
- Create a native bridge file that your Delphi or C++ applications can use to access the APIs of your Java libraries.
- Add your Java libraries to your application.
RAD Studio Requirements for Java Libraries
RAD Studio only supports the Android API level 10 (Android 2.3.3) and later. If your Java libraries use the Android API, they must be compiled using a supported Android API.
If your Java library depends on other Java libraries, you must have the JAR files of both your Java library and the libraries that your library depends on. You need the JAR files of all those Java libraries to generate a valid
classes.dex file later.
See in the table under Generating a
classes.dex File which JAR file belongs to each library.
Creating a Native Bridge File for a Java Library
Once you have your Java library, you need to create one or more native bridge files, files in Delphi or C++ that you can include in your native RAD Studio applications to access the API of your Java libraries.
You can create native bridge files for Delphi using the Java2OP command-line tool. You can then translate your Delphi native bridge file to C++ manually.
You can check the existing bridge files (prefixed with
Androidapi.JNI) in the following paths within the RAD Studio installation folder (
C:\Program Files (x86)\Embarcadero\Studio\21.0) for reference:
Adding Your Java Libraries to Your Application
There are two different approaches that you can follow to add your Java libraries to your application for Android:
- Use the Project Manager to add your Java libraries to your application. This is the simplest approach, you only need a couple of clicks. This approach should work for most people.
- Create and deploy a
classes.dexfile manually. This approach allows you not only to add libraries to your application, but also to modify the built-in RAD Studio Java libraries for Android, or remove those that you do not need.