Error while trying to compile to Android

I can build for the web and linux but not for android. I keep getting the error:

Vik@Vik: pts/2: 5 files 28Kb ❯ openfl build android
Creating /home/viktor/projects/HelloWorldProject/Export/android/obj/obj/android64-v7/__pch/haxe/hxcpp.h.gch…
/usr/share/haxe/lib/hxcpp/4,3,2/include/hxcpp.h:27:13: fatal error: ‘typeinfo’ file not found
#include
^~~~~~~~~~
1 error generated.
Error: Could not create PCH

I have “android-sdk” + “android-ndk” already installed. I can easily compile flutter and kotlin apps for android but I’m unable to build it from haxe.

I have set the debug variable so you can have more details.
Vik@Vik: pts/0: 5 files 28Kb ❯ openfl build android
__
/\ \
\ \ ___ __ _ ___ _____ _____
\ \ _ \ /\ \/'\ /'___\/\ '__/\ '`\
\ \ \ \ \/> <//\ _/\ \ \L\ \ \ \L\
\ _\ _/_/_\ _
\ \ ,/\ \ ,/
/////////_/ \ \ / \ \ /
\ _\ \ _\
/
/ /
/

hxcpp (Haxe C++ Runtime Support) (4.3.2)

Using makefile: Build.xml
Reading HXCPP config: /home/viktor/.hxcpp_config.xml
No specified toolchain

  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/toolchain/setup.xml
  • Parsing include: /home/viktor/.hxcpp_config.xml (section “vars”)
  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/toolchain/finish-setup.xml
  • Parsing makefile: /home/viktor/projects/HelloWorldProject/Export/android/obj/Build.xml
  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/build-tool/BuildCommon.xml
  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/toolchain/haxe-target.xml
  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/src/hx/libs/regexp/Build.xml
  • Parsing FileGroup: /usr/share/haxe/lib/hxcpp/4,3,2/src/hx/libs/regexp/pcre2_sources.xml
  • Parsing FileGroup: /usr/share/haxe/lib/hxcpp/4,3,2/src/hx/libs/regexp/pcre2_sources.xml
  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/src/hx/libs/std/Build.xml
  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/toolchain/android-toolchain.xml

Using Android NDK root: /opt/android-ndk/
Try to get version from source.properties
Deduced NDK version 26.001 from “/opt/android-ndk/”/source.properties
Detected Android NDK 26.001
x86 Platform: 16
arm Platform: 16
x86_64 Platform: 21
arm_64 Platform: 21
Frameworks should set the minSdkVersion for each APK to these values.

  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/toolchain/android-toolchain-clang.xml
  • Adding path: /opt/android-ndk//toolchains/llvm/prebuilt/linux-x86/bin
  • Parsing include: /usr/share/haxe/lib/hxcpp/4,3,2/toolchain/gcc-toolchain.xml
  • Parsing compiler: /usr/share/haxe/lib/hxcpp/4,3,2/toolchain/common-defines.xml
  • Parsing include: /home/viktor/.hxcpp_config.xml (section “exes”)

Using compile threads: 4

Ignoring compiler cache because HXCPP_COMPILE_CACHE is not valid.
Creating PCH directory “/home/viktor/projects/HelloWorldProject/Export/android/obj/obj/android64-v7/__pch/haxe”

  • Precompile /home/viktor/projects/HelloWorldProject/Export/android/obj/obj/android64-v7/__pch/haxe/hxcpp.h.gch
  • Running command: clang++ -Iinclude --target=arm-linux-androideabi16 -DHXCPP_ARMV7 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHX_SMART_STRINGS -DHXCPP_API_LEVEL=400 -I/usr/share/haxe/lib/hxcpp/4,3,2/include -Iinclude -DANDROID=ANDROID -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=16 -fvisibility=hidden -ffunction-sections -fstack-protector -fexceptions -c -fpic -O2 -Wno-invalid-offsetof -Wno-return-type-c-linkage -Wno-parentheses -x c+±header -o /home/viktor/projects/HelloWorldProject/Export/android/obj/obj/android64-v7/__pch/haxe/hxcpp.h.gch /usr/share/haxe/lib/hxcpp/4,3,2/include/hxcpp.h
    /usr/share/haxe/lib/hxcpp/4,3,2/include/hxcpp.h:27:13: fatal error: ‘typeinfo’ file not found
    #include
    ^~~~~~~~~~
    1 error generated.
    Error: Error while running command
    clang++ -Iinclude --target=arm-linux-androideabi16 -DHXCPP_ARMV7 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHX_SMART_STRINGS -DHXCPP_API_LEVEL=400 -I/usr/share/haxe/lib/hxcpp/4,3,2/include -Iinclude -DANDROID=ANDROID -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=16 -fvisibility=hidden -ffunction-sections -fstack-protector -fexceptions -c -fpic -O2 -Wno-invalid-offsetof -Wno-return-type-c-linkage -Wno-parentheses -x c+±header -o /home/viktor/projects/HelloWorldProject/Export/android/obj/obj/android64-v7/__pch/haxe/hxcpp.h.gch /usr/share/haxe/lib/hxcpp/4,3,2/include/hxcpp.h

Vik@Vik: pts/0: 5 files 28Kb ❯ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-Ubuntu-121.04)
OpenJDK 64-Bit Server VM (build 17.0.1+12-Ubuntu-121.04, mixed mode, sharing)

Vik@Vik: pts/0: 5 files 28Kb ❯ android --version


The “android” command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager


Invalid or unsupported command “–version”

Supported commands are:
android list target
android list avd
android list device
android create avd
android move avd
android delete avd
android list sdk
android update sdk

Vik@Vik: pts/2: 49 files 17Gb ❯ android list target


The “android” command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager


Running /opt/android-sdk/tools/bin/avdmanager list target

Exception in thread “main” java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
… 5 more

Vik@Vik: pts/2: 5 files 28Kb ❯ sdkmanager --version
9.0

Vik@Vik: pts/1: 5 files 28Kb ❯ java -XshowSettings:properties -version 2>&1 > /dev/null | grep ‘java.home’
java.home = /usr/lib/jvm/java-17-openjdk-amd64

Vik@Vik: pts/3: 49 files 17Gb ❯ ndk-build --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Here is part of my ~/.bashrc

export NDK_HOME=/opt/android-ndk
export ANDROID_NDK_DIR=/opt/android-ndk
export SDK_ROOT=/opt/android-sdk
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

hxcpp supports NDK up to 21 for now
try android-ndk-r15c or android-ndk-r21e

1 Like

Thanks for the quick responde. I’ll try it.

Screenshot from 2023-11-05 19-37-16

Does it matter which one I install?

The most recent one is 21.4.7075529.
But it might turn out like this: Haxe 4.3.0 and HXCPP 4.3.2 prodce APK that crashes on Android 10 · Issue #2631 · openfl/openfl · GitHub
I currently have this configuration: SDL error on some android devices at startup - #8 by Vortelio

21.0 == r21a
21.1 == r21b
21.2 == r21c
21.3 == r21d
21.4 == r21e

FIXED:
[FIXED]
SOLVED
[SOLVED]

The issue has been fixed. Thanks everybody.

SOLUTION:

  1. I downloaded the file “android-ndk-r21d-linux-x86_64.zip” from google’s dl.
  2. I unzip it.
  3. I moved it to /opt/android-ndk/
  4. I then compiled the code and It’s not giving off that error anymore.

I would like to notice that I had downloaded the version from Android Studio but it did not solve the problem. I had to manually move it to /opt/android-ndk

I’m not sure if Android Studio is buggy or not but all the things I downloaded(around 20GB) it stills lists them as “NOT INSTALLED”. bruh.