Building Panda on Android

It was stated in the recent blog post that you can build Panda3D for android. However, there is a lack of ANY documentation or any ways to get the thirdparties required for it. Do you have any link to the thirdparties for building on android?

There are no prebuilt thirdparty packages; you would need to build them from source.

I personally build Panda3D in termux, on Android itself, which I find easier. In that case, it is just a matter of installing them using pkg install. I can give you a list of the package names I used if you’d like.

That would be helpful.

You would first need to install Termux and Termux:API from the play store.

You probably also want to run the termux-setup-storage command to give Termux access to your external storage.

Then, you can install the following packages:

pkg install python-dev clang libvorbis-dev libopus-dev opusfile-dev openal-soft-dev freetype-dev harfbuzz-dev libpng-dev ecj dx patchelf aapt apksigner libcrypt-dev

Note that not all packages are required. For example, if you don’t have libjpeg, Panda will use the Android Bitmap loader in order to load .jpg files.

My build.sh script looks like this:

export LD_LIBRARY_PATH=/system/lib64:$LD_LIBRARY_PATH
rm -f panda3d.apk
python makepanda/makepanda.py --everything --target android --installer --threads 2 $@
if [ -f panda3d.apk ]; then
  cp panda3d.apk /sdcard/panda3d.apk
  xdg-open /sdcard/panda3d.apk
done

This way, when the build is done, it will automatically ask you to install the package.

It compiles pretty well on a Tegra X1, but if your hardware is weaker then I suggest leaving out the --threads 2 part.

Thanks, I am starting the build now. However, I would like the ODE library, any advice on how I’d go about getting that?

It’s not in the termux package repository, so you’ll have to build it from source.

After running it for about 15 minutes. The build failed with an OPUS error.

> In file included from panda/src/movies/opusAudioCursor.cxx:19:
> /data/data/com.termux/files/usr/include/opus/opusfile.h:110:11: fatal error:
>       'opus_multistream.h' file not found
> # include <opus_multistream.h>
>           ^~~~~~~~~~~~~~~~~~~~
> 1 error generated.                                          The following command returned a non-zero value: aarch64-linux-android-clang++ -std=gnu++11 -ftemplate-depth-70 -fPIC -c -o built/tmp/p3movies_composite1.o -Ibuilt/tmp -Ibuilt/include -I/data/data/com.termux/files/usr/include/opus -DANDROID= -Ipanda/src/movies -fvisibility=hidden -D__ANDROID_API__=21 -ffunction-sections -funwind-tables -target aarch64-none-linux-android -Wa,--noexecstack -fno-exceptions -fno-rtti -fno-strict-aliasing -ffast-math -fno-stack-protector -fno-finite-math-only -O2 -DBUILDING_PANDA panda/src/movies/p3movies_composite1.cxx
> Storing dependency cache.
> Elapsed Time: 15 min 26 sec
> Build process aborting.

I think you also need libopus-dev, sorry.

No worries. Trying again now

I got another error.

    panda/src/android/python_main.cxx:38:21: error: use of undeclared
          identifier 'Py_DecodeLocale'
      Py_SetProgramName(Py_DecodeLocale("ppython", nullptr));
                        ^
    panda/src/android/python_main.cxx:42:20: error: use of undeclared
          identifier 'Py_DecodeLocale'
      Py_SetPythonHome(Py_DecodeLocale(apk_path.c_str(), nullptr));
                       ^
    panda/src/android/python_main.cxx:51:7: error: no matching function for
          call to 'PyImport_AppendInittab'
          PyImport_AppendInittab("zlib", (PyObject *(*)())init);
          ^~~~~~~~~~~~~~~~~~~~~~
    /data/data/com.termux/files/usr/include/python2.7/import.h:54:17: note:
          candidate function not viable: no known conversion from
          'PyObject *(*)()' (aka '_object *(*)()') to 'void (*)()' for 2nd
          argument
    PyAPI_FUNC(int) PyImport_AppendInittab(const char *name, void (*ini...
                    ^
    panda/src/android/python_main.cxx:61:19: warning: ISO C++11 does not allow
          conversion from string literal to 'char *' [-Wwritable-strings]
      PySys_SetObject("_native_library_dir", py_native_dir);
                      ^
    8 warnings and 3 errors generated.
    The following command returned a non-zero value: aarch64-linux-android-clang++ -std=gnu++11 -ftemplate-depth-70 -fPIC -c -o built/tmp/ppython_ppython.o -Ibuilt/tmp -Ibuilt/include -I/data/data/com.termux/files/usr/include/python2.7 -DANDROID= -Ipanda/src/android -fvisibility=hidden -D__ANDROID_API__=21 -ffunction-sections -funwind-tables -target aarch64-none-linux-android -Wa,--noexecstack -fno-exceptions -fno-rtti -fno-strict-aliasing -ffast-math -fno-stack-protector -fno-finite-math-only -O2 panda/src/android/python_main.cxx
    Storing dependency cache.
    Elapsed Time: 10 min 52 sec
    Build process aborting.
    Build terminated.

That’s odd. Which version of Python are you building with? Try doing python -V. I’m building with Python 3.6, which is the default Python version in termux.

I am using python 2.

The Android entry point currently only supports Python 3. I didn’t think anyone would be interested in still using Python 2. Is there any reason you can’t just use Python 3?

However, it would not be a whole lot of effort to change the code to also support Python 2, since it’s only a single file that would need to be changed, android_main.cxx.

C++ Side of things that the game uses isnt Python 3 compatible.

I did try building with python 3 however, and i get

/data/data/com.termux/files/usr/include/python3.6m/Python.h:39:10: fatal error: 'crypt.h' file not found
#include <crypt.h>
         ^~~~~~~~~
1 error generated.
The following command returned a non-zero value: aarch64-linux-android-clang++ -std=gnu++11 -ftemplate-depth-70 -fPIC -c -o built/tmp/ppython_ppython.o -Ibuilt/tmp -Ibuilt/include -I/data/data/com.termux/files/usr/include/python3.6m -DANDROID= -Ipanda/src/android -fvisibility=hidden -D__ANDROID_API__=21 -ffunction-sections -funwind-tables -target aarch64-none-linux-android -Wa,--noexecstack -fno-exceptions -fno-rtti -fno-strict-aliasing -ffast-math -fno-stack-protector -fno-finite-math-only -O2 panda/src/android/python_main.cxx
Storing dependency cache.
Elapsed Time: 23 sec
Build process aborting.
Build terminated.

I suspect that crypt.h is part of the openssl-dev package.

I installed the openssl-dev package, but that still happens.

I guess libcrypt-dev might be worth a try, then.

That seemed to work. Thanks.
How would I go about running an application though?

In the panda/src/android directory, there is a run_python.sh script that will launch the Panda3D Python runner, given a path to the Python code you want to run (which must be somewhere in /sdcard since Panda cannot access any other files from the termux filesystem). It will use a socket for piping the command-line output back to the terminal.