Using a Custom Set of Java Libraries In Your RAD Studio Android Apps

From RAD Studio
Jump to: navigation, search

Go Up to Using 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:

  1. Ensure that your Java libraries meet the RAD Studio requirements for Java libraries.
  2. Create a native bridge file that your Delphi or C++ applications can use to access the APIs of your Java libraries.
  3. 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\22.0) for reference:

  • source\rtl\android (Delphi)
  • include\android\rtl (C++)

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:

See Also