Experience sharing of using "openfl" to package Android native "apk"

Just yesterday, I repackaged my game project into a native Android apk, but I actually encountered some situations.

First of all, let me explain that my game can run normally on the “html5 neko windows exe air” target.

I initially used “Java25” to package, and “APK” could package normally, but when running on my phone, it crashed and exited directly.

“OpenJDK25U-jdk_x64_windows_hotspot_25.0.4.1_1.msi“

Then I wondered if the version of ‘Java JDK 25’ was too high? So I used “Java JDK 21” to package “APK”, but the result was still the same, running it on my phone and crashing out directly

“OpenJDK21U-jdk_x64_windows_hotspot_21.0.12.1_1.msi“

And then? I used ‘Java JDK 17’ to package the ‘APK’, but unfortunately the situation is still the same. In fact, it automatically exits when running

“OpenJDK17U-jdk_x64_windows_hotspot_17.0.20.1_1.msi“

I began to realize that it might not be a problem with the “Java JDK”. I created the “SimpleBox2D” project built into “OpenFL” and successfully packaged the “APK” using “Java JDK 17”, which can run normally on my phone ..

Then I used “Java JDK 17 21 25” to package the “apk” separately, and the “SimpleBox2D” project could run normally on my phone. It seems that there is an issue with my game project ..

Then I created a new project to investigate the third-party library “Starling Nape”, and the new project using “Starling Nape” can run normally on the phone

I copied a copy of my game project, deleted some “. hx” files that I thought were problematic, and only kept the basic architecture, but it still automatically exits on my phone ..

Finally, the problem was identified as an issue with my “view. hx” adaptation class. My adaptation class only adapted to “html5 air windows exe” and did not adapt to native Android. This is the main reason, and another reason is that I did not enable landscape screen in the project configuration file ..

The solution is to add conditional compilation of native Android in the adaptation class and enable landscape screen in the project configuration file ..

Later on, I also used “Java JDK 17 21 25” to package “APK” separately, and they can all run normally on my phone

What is the warning displayed when I package with “Java JDK 25 21”?

Java compiler version 21 has deprecated support for compiling with source/target version 8.

Compiling group: hxcpp_regexp
clang++ -IC:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src --target=aarch64-linux-android21 -DHXCPP_ARM64 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS(haxe) -DHX_SMART_STRINGS(haxe) -DHXCPP_API_LEVEL=430(haxe) -IC:/HaxeToolkit/haxe/lib/hxcpp/git/include -Iinclude -DANDROID=ANDROID -DHXCPP_CLANG -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=21 -fvisibility=hidden -ffunction-sections -fstack-protector -fexceptions -c -fpic -O2 -Wno-invalid-offsetof -Wno-return-type-c-linkage -Wno-parentheses … tags=[haxe,static]

  • C:/HaxeToolkit/haxe/lib/hxcpp/git/src/hx/libs/regexp/RegExp.cpp

Compiling group: pcre2-8
clang++ -DPCRE2_CODE_UNIT_WIDTH=8 -DSUPPORT_PCRE2_8 -DHAVE_CONFIG_H -DPCRE2_STATIC -DSUPPORT_UNICODE -IC:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src -std=c99 --target=aarch64-linux-android21 -DHXCPP_ARM64 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS(haxe) -DHX_SMART_STRINGS(haxe) -DHXCPP_API_LEVEL=430(haxe) -IC:/HaxeToolkit/haxe/lib/hxcpp/git/include -Iinclude -DANDROID=ANDROID -DHXCPP_CLANG -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=21 -fvisibility=hidden -ffunction-sections -fstack-protector -fexceptions -c -fpic -O2 -Wno-invalid-offsetof -Wno-return-type-c-linkage -Wno-parentheses … tags=[]

  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_match_data.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_context.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_extuni.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_jit_compile.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_script_run.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_study.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_substitute.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_find_bracket.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_newline.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_chartables.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_maketables.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_pattern_info.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_substring.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_convert.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_dfa_match.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_serialize.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_config.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_tables.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_auto_possess.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_compile.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_error.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_ucd.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_valid_utf.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_match.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_ord2utf.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_xclass.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_string_utils.c

Compiling group: pcre2-16
clang++ -DPCRE2_CODE_UNIT_WIDTH=16 -DSUPPORT_PCRE2_16 -DHAVE_CONFIG_H -DPCRE2_STATIC -DSUPPORT_UNICODE -IC:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src -std=c99 --target=aarch64-linux-android21 -DHXCPP_ARM64 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS(haxe) -DHX_SMART_STRINGS(haxe) -DHXCPP_API_LEVEL=430(haxe) -IC:/HaxeToolkit/haxe/lib/hxcpp/git/include -Iinclude -DANDROID=ANDROID -DHXCPP_CLANG -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=21 -fvisibility=hidden -ffunction-sections -fstack-protector -fexceptions -c -fpic -O2 -Wno-invalid-offsetof -Wno-return-type-c-linkage -Wno-parentheses … tags=[]

  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_context.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_match_data.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_substitute.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_jit_compile.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_script_run.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_study.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_extuni.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_find_bracket.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_newline.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_chartables.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_maketables.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_pattern_info.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_substring.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_convert.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_dfa_match.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_config.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_serialize.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_tables.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_auto_possess.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_compile.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_error.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_ucd.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_valid_utf.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_match.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_ord2utf.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_xclass.c
  • C:/HaxeToolkit/haxe/lib/hxcpp/git/project/thirdparty/pcre2-10.42/src/pcre2_string_utils.c

Compiling group: hxcpp_std
clang++ --target=aarch64-linux-android21 -DHXCPP_ARM64 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS(haxe) -DHX_SMART_STRINGS(haxe) -DHXCPP_API_LEVEL=430(haxe) -IC:/HaxeToolkit/haxe/lib/hxcpp/git/include -Iinclude -DANDROID=ANDROID -DHXCPP_CLANG -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=21 -fvisibility=hidden -ffunction-sections -fstack-protector -fexceptions -c -fpic -O2 -Wno-invalid-offsetof -Wno-return-type-c-linkage -Wno-parentheses … tags=[haxe,static]

  • File.cpp
  • Socket.cpp
  • Random.cpp
  • Sys.cpp
  • Process.cpp
    Link: libApplicationMain-64.so
    Starting a Gradle Daemon (subsequent builds will be faster)

Task :deps:extension-api:compileDebugJavaWithJavac
Java compiler version 21 has deprecated support for compiling with source/target version 8.
Try one of the following options:
1. [Recommended] Use Java toolchain with a lower language version
2. Set a higher source/target version
3. Use a lower version of the JDK running the build (if you’re not using Java toolchain)
For more details on how to configure these settings, see https://developer.android.com/build/jdks.
To suppress this warning, set android.javaCompile.suppressSourceTargetDeprecationWarning=true in gradle.properties.
璀﹀憡: [options] 婧愬€?8 宸茶繃鏃讹紝灏嗗湪鏈潵鍙戣鐗堜腑鍒犻櫎
璀﹀憡: [options] 鐩爣鍊?8 宸茶繃鏃讹紝灏嗗湪鏈潵鍙戣鐗堜腑鍒犻櫎
璀﹀憡: [options] 瑕侀殣钘忔湁鍏冲凡杩囨椂閫夐」鐨勮鍛? 璇蜂娇鐢?-Xlint:-options銆?
3 涓鍛?

Task :app:compileDebugJavaWithJavac
Java compiler version 21 has deprecated support for compiling with source/target version 8.
Try one of the following options:
1. [Recommended] Use Java toolchain with a lower language version
2. Set a higher source/target version
3. Use a lower version of the JDK running the build (if you’re not using Java toolchain)
For more details on how to configure these settings, see https://developer.android.com/build/jdks.
To suppress this warning, set android.javaCompile.suppressSourceTargetDeprecationWarning=true in gradle.properties.
璀﹀憡: [options] 婧愬€?8 宸茶繃鏃讹紝灏嗗湪鏈潵鍙戣鐗堜腑鍒犻櫎
璀﹀憡: [options] 鐩爣鍊?8 宸茶繃鏃讹紝灏嗗湪鏈潵鍙戣鐗堜腑鍒犻櫎
璀﹀憡: [options] 瑕侀殣钘忔湁鍏冲凡杩囨椂閫夐」鐨勮鍛? 璇蜂娇鐢?-Xlint:-options銆?
娉? 鏌愪簺杈撳叆鏂囦欢浣跨敤鎴栬 鐩栦簡宸茶繃鏃剁殑 API銆?
娉? 鏈夊叧璇︾粏淇℃伅, 璇蜂娇鐢?-Xlint:deprecation 閲嶆柊缂栭噸鏂扮紪璇戙€?
3 涓鍛?
<=
BUILD SUCCESSFUL in 27s
60 actionable tasks: 60 executed

D:\OpenFL\game>

By the way, what version of “Java JDK” is everyone using?