Android SDK And NDK Troubleshooting

1. Windows: Building for Android fails, because it cannot delete .jar file from previous compilation

Sometimes, the intermediate jar file is locked by some process, and all the attempts to build for Android, or to Clean the project from CGE editor, will fail with message like this:

Cannot delete file "....\castle-engine-output\android\project\app\build\intermediates\project_dex_archive\debug\out\2d864914410e990332c5a81a0dad4c5ee5c1075c0122b7be66757876af632106_0.jar"

Workaround: Delete the castle-engine-output subdirectory using Windows file manager. Searching the Internet confirms this problem happens and is not related to CGE.

2. Compilation errors "Trying to use a unit which was compiled with a different FPU mode"

This indicates you compiled FPC standard units without -CfVFPV3. This would result in very slow execution on Android. Solutions:

  • If you compile FPC cross-compiler yourself, following Android, remember to add CROSSOPT="-CfVFPV3" .

  • If you compile FPC cross-compiler by fpcupdeluxe, go to the "Setup+" options and for Android/Arm add -CfVFPV3 option.

FpcUpDeluxe cross-compiler options

3. libz errors, "exception in thread png-cruncher" errors

In case of errors about libz.so.1 (resulting in later errors about Exception in thread "png-cruncher…​) on Linux 64-bit, see here: http://stackoverflow.com/questions/29241640/error-unable-to-run-mksdcard-sdk-tool . Install additional libraries as needed.

4. clang errors

The Android NDK for 32-bit Windows has a known error in version r12b, see https://github.com/android-ndk/ndk/issues/139 . The clang binaries are for 64-bit architecture. It will prevent compiling the NDK samples (not related to CGE…​). This should be fixed in next NDK release. An easy fix for now is to go to "ndk\toolchains\llvm\prebuilt\windows\bin" directory and:

  • rename clang.exe -> clang_64.exe (or just remove it)

  • rename clang_32.exe -> clang.exe

  • rename clang++.exe -> clang++_64.exe (or just remove it)

  • copy clang.exe -> clang++.exe (yes, just copy to a new name, this is the same executable).

5. "Could not find tools.jar" error

The error Could not find tools.jar usually means you did not set JAVA_HOME correctly (to point to JDK).

6. Errors when executing aidl on 64-bit (x86_64) Linux

If you get errors when executing /usr/local/android/android-sdk-linux/build-tools/23.0.2/aidl on 64-bit (x86_64) Linux:

That is because Google distributes them as compiled for a 32-bit (i386) Linux system. Install some additional libraries to make them work. On Debian:

apt-get install libc6-i386 lib32stdc++6 lib32z1

(In general, old build-tools are distributed only for Linux 32-bit, and new build-tools are distributed only for Linux 64-bit. Google doesn’t provide alternatives for both architectures here.) See https://stackoverflow.com/questions/24158727/android-sdk-aapt-error-libstdc-so-6-cannot-open-shared-object-file .

7. Error "No toolchains found in the NDK toolchains folder for ABI with prefix: mipsel-linux-android"

This error occurs since Android NDK 18. They removed MIPS CPU support (which we never used), but old Gradle versions still expect to find the relevant folders.

A workaround is to create the necessary folders manually (it’s OK to leave them empty), by running:

mkdir -p $ANDROID_NDK_HOME/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86_64
mkdir -p $ANDROID_NDK_HOME/toolchains/mips64el-linux-android-4.9/prebuilt/linux-x86_64

This problem should no longer be present (we upgraded Gradle in CGE). See also


To improve this documentation just edit this page and create a pull request to cge-www repository.