Skip to main content

Fix "Jar libraries added to Android 64-bit platform target are not compiled"

Due to a bug (as at March 28th, 2023) in Delphi 11.3, libraries that are added to the Android 64-bit platform target in a project are not compiled. This can result in errors when the application runs, e.g:

Project testapp.apk raised exception class EJNIFatal with message 
'Java type com/delphiworlds/kastri/DWAdListenerDelegate could not be found'.

Previously, libraries that were added to Android 32-bit platform target were also compiled when targeting Android 64-bit.

The following steps fix the issue for all projects (see below for an alternate solution, which works on a project-by-project basis):

  1. Make a backup of the CodeGear.Common.Targets file in the bin folder of your Delphi install
  2. Make another copy of the same file in a folder where it can be edited
  3. At line 958 in the file, there is this section:
  <!-- Return all the customized .jar files included on the project -->
  <Target Name="GetProjectJars">
    <ItemGroup>
        <_JarsLocations Include="%(JavaReference.FullPath)" Condition="('%(JavaReference.Disabled)'!='True') And ('%(JavaReference.IsSystem)'!='True') And
            (('$(Platform)'=='$(cAndroidArm64Platform)' And '%(JavaReference.ContainerId)'=='ClassesdexFile64') Or 
             ('$(Platform)'=='$(cAndroidArm32Platform)' And '%(JavaReference.ContainerId)'=='ClassesdexFile')
            )">
            <PredexedJar>$(OutputClassesDexDir)%(JavaReference.Filename)$(PredexedJarSuffix)%(JavaReference.Extension)</PredexedJar>
        </_JarsLocations>
    </ItemGroup>
  </Target>

Modify the section to look like this:

  <!-- Return all the customized .jar files included on the project -->
  <Target Name="GetProjectJars">
    <ItemGroup>
        <_JarsLocations Include="%(JavaReference.FullPath)" Condition="('%(JavaReference.Disabled)'!='True') And ('%(JavaReference.IsSystem)'!='True')">
            <PredexedJar>$(OutputClassesDexDir)%(JavaReference.Filename)$(PredexedJarSuffix)%(JavaReference.Extension)</PredexedJar>
        </_JarsLocations>
    </ItemGroup>
  </Target>
  1. Copy the modified CodeGear.Common.Targets file to the bin folder in your Delphi install

The following steps is the "official" workaround, however this works only on a project-by-project basis (which means you will need to update your existing projects if you compile for Android 64-bit):

  1. Make a copy of the jar files that you have added to the project, and copy them to a separate folder.
  2. Add the copies of the jar files to the Libraries node of the Android 64-bit target platform in Project Manager