How to build for Android on Windows?

Hello,
how can I build Panda3D for Android on Windows?
I am building with
makepanda\makepanda.py --everything --no-eigen --no-python --target=android-29

and I get many warnings about missing third party packages, like:
WARNING: Could not locate thirdparty package gles2, excluding from build
WARNING: Could not locate thirdparty package egl, excluding from build

Where can I get the source for GLES2, specifically? Shouldn’t it already be included in the Android NDK?

pandamake.py also seems to be unable to locate clang++; I get the folllowing error:
[ 0%] Building C++ object built/tmp/p3dtoolbase_composite1.o
clang++: error: unable to execute command: program not executable
Storing dependency cache.
Elapsed Time: 14 sec
The following command returned a non-zero value: clang++ -std=gnu++11 -ftemplate-depth-70 -fPIC -c -o built/tmp/p3dtoolbase_composite1.o -ID:/dev/android/sdk/android-ndk-r13b/sources/cxx-stl/llvm-libc++/include -ID:/dev/android/sdk/android-ndk-r13b/sources/android/support/include -Ibuilt/tmp -Ibuilt/include -DANDROID= -Idtool/src/dtoolbase -fvisibility=hidden -isystem D:/dev/android/sdk/android-ndk-r13b/sysroot/usr/include -isystem D:/dev/android/sdk/android-ndk-r13b/sysroot/usr/include/arm-linux-androideabi -no-canonical-prefixes -D__ANDROID_API__=29 -gcc-toolchain D:/dev/android/sdk/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows -ffunction-sections -funwind-tables -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -Wa,–noexecstack -mthumb -mfpu=neon -fno-exceptions -fno-rtti -fno-strict-aliasing -ffast-math -fno-stack-protector -fno-finite-math-only -fno-unsafe-math-optimizations -O2 -Wall -Wno-unused-function -Wno-reorder -DBUILDING_DTOOL dtool/src/dtoolbase/p3dtoolbase_composite1.cxx
Build terminated.

I have set ANDROID_NDK_ROOT to D:\dev\android\sdk\android-ndk-r13b and I set PATH to include D:\dev\android\sdk\android-ndk-r13b\toolchains\llvm\prebuilt\windows\bin where clang++.exe is located. Do I need to do anything else to get it working?

Thanks in Advance

PS: Please note that I don’t want to build on my Android device using Termux, as that is going to be too cumbersome. I would prefer to do it on Windows.

Hi, welcome to the community!

I’m assuming you’ve already installed the Android SDK, the files for the API level you have specified, as well as the NDK. (I think you can install all these things from the SDK manager.)

Note that makepanda should automatically be setting the PATH correctly; the only thing you need to pass is ANDROID_SDK_ROOT (it is guessed to be C:\Users\You\AppData\Local\Android\Sdk if not specified), and ANDROID_NDK_ROOT if the NDK is installed manually instead of via the SDK manager (it defaults to looking for an ndk-bundle folder under the Sdk folder).

The error message appears to indicate that a version of clang++ is used that is not compatible with your platform. I find this a little curious. Can you run clang++ correctly on the command-line? Perhaps it is picking up a clang++ from a different directory?

I think GLES2 should indeed be included in the NDK, but I’m guessing this might be a related issue.

I managed to get the build process started.

The problem was that the (ancient) version 13b of the NDK I used doesn’t include a sysroot for Android platform 29. I had to set ANDROID_NDK_ROOT to a more recent NDK version.

I encountered some other obstacles, though.
The build script couldn’t find ar and ld, so I had to add D:\dev\android\sdk\android-ndk-r18b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows\arm-linux-androideabi\bin to the PATH. I think this is a bug and should be done automatically in makepandacore.py.

after each *.so linking step this message is displayed:
‘chmod’ is not recognized as an internal or external command,
operable program or batch file.

This doesn’t stop the build process, though. Obviously chmod doesn’t exist on Windows.

“Build successfully finished, elapsed time: 1 hours 15 min” :slight_smile:
So how do I make the APK? It isn’t automatically created by makepanda. Do I need to manually create an Android Studio project and import all the built *.so libs and Java source files from panda\src\android?

I now have created an APK in Android studio containing the 4 Java files from {pandasrc]}panda\src\android and all the built x86 android *.so libs in {androidproject}/main/src/jniLibs.

When launching the app on the emulator it immediately crashes with the following error in logcat:
Process: org.panda3d.test1, PID: 4502
java.lang.UnsatisfiedLinkError: dlopen failed: “/data/app/org.panda3d.test1-2/lib/x86/libpandaegg.so” has unexpected e_machine: 40
at java.lang.Runtime.loadLibrary(Runtime.java:371)
at java.lang.System.loadLibrary(System.java:988)
at org.panda3d.android.PandaActivity.(PandaActivity.java:117)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
[…]

What does “unexpected e_machine: 40” mean? How to fix it? I hope someone can help.

Thanks in advance!

EDIT: It looks like I mixed up arm and x86 libs. I fixed that. But now I get another error:

EXCEPTION: main
Process: org.panda3d.test1, PID: 3122
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “__register_atfork” referenced by “libp3dtool.so”…
at java.lang.Runtime.loadLibrary(Runtime.java:371)
at java.lang.System.loadLibrary(System.java:988)
at org.panda3d.android.PandaActivity.(PandaActivity.java:117)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
[…]

EDIT2: Seems like this is an issue with NDK, not specific to Panda3D (https://github.com/android/ndk/issues/964). I’ll need to rebuild all native libs with a lower SDK level to match the minimum SDK level set in the Android Manifest.

For the record, you can produce an .apk using makepanda if you pass the --installer flag, or by using makepanda/makepackage.py.

I rebuilt Panda3D targeting API level 21. (The emulator is API level 22). Now I get another error when lauching the app:

FATAL EXCEPTION: main
Process: org.panda3d.test1, PID: 2983
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “ALooper_pollAll” referenced by “libpandagles.so”…
at java.lang.Runtime.loadLibrary(Runtime.java:371)
at java.lang.System.loadLibrary(System.java:988)
at org.panda3d.android.PandaActivity.(PandaActivity.java:118)

makepanda\makepanda.py --everything --no-eigen --no-python --no-pandatool --no-deploytools --target=android-21 --arch=x86 --threads=3 --installer

Cannot find rm on search path
Build terminated.

=======================
makepanda\makepackage.py

Building Panda3D SDK 1.10.4 installer at Panda3D-1.10.4.exe
Note: you are using zlib, which is faster, but lzma gives better compression.
Storing dependency cache.
Elapsed Time: 0 sec
Cannot find thirdparty\win-nsis\makensis on search path
Build terminated.

=======================
Those commands don’t work …
Is there a switch to let makepackage build the Android APK?

makepanda with --installer just invokes makepackage with the right flags, so if one doesn’t work, the other won’t either.

I guess the code in makepackage assumes that you’re on a non-Windows system, by using tools like rm. You may have to modify the code in MakeInstallerAndroid to use the shutil module instead of directly invoking cp, rm, mkdir.