@@ -5082,7 +5082,7 @@ def CreatePandaVersionFiles():
50825082# DIRECTORY: panda/src/testbed/
50835083#
50845084
5085- if (not RTDIST and not RUNTIME and PkgSkip ("PVIEW" )== 0 and GetTarget () != 'android' ):
5085+ if (not RTDIST and not RUNTIME and PkgSkip ("PVIEW" )== 0 ):
50865086 OPTS = ['DIR:panda/src/testbed' ]
50875087 TargetAdd ('pview_pview.obj' , opts = OPTS , input = 'pview.cxx' )
50885088 TargetAdd ('pview.exe' , input = 'pview_pview.obj' )
@@ -5101,6 +5101,7 @@ def CreatePandaVersionFiles():
51015101 TargetAdd ('org/panda3d/android/NativeIStream.class' , opts = OPTS , input = 'NativeIStream.java' )
51025102 TargetAdd ('org/panda3d/android/NativeOStream.class' , opts = OPTS , input = 'NativeOStream.java' )
51035103 TargetAdd ('org/panda3d/android/PandaActivity.class' , opts = OPTS , input = 'PandaActivity.java' )
5104+ TargetAdd ('org/panda3d/android/PythonActivity.class' , opts = OPTS , input = 'PythonActivity.java' )
51045105
51055106 TargetAdd ('p3android_composite1.obj' , opts = OPTS , input = 'p3android_composite1.cxx' )
51065107 TargetAdd ('libp3android.dll' , input = 'p3android_composite1.obj' )
@@ -5111,17 +5112,28 @@ def CreatePandaVersionFiles():
51115112 TargetAdd ('android_main.obj' , opts = OPTS , input = 'android_main.cxx' )
51125113
51135114 if (not RTDIST and PkgSkip ("PVIEW" )== 0 ):
5114- TargetAdd ('pview_pview .obj' , opts = OPTS , input = 'pview.cxx' )
5115+ TargetAdd ('libpview_pview .obj' , opts = OPTS , input = 'pview.cxx' )
51155116 TargetAdd ('libpview.dll' , input = 'android_native_app_glue.obj' )
51165117 TargetAdd ('libpview.dll' , input = 'android_main.obj' )
5117- TargetAdd ('libpview.dll' , input = 'pview_pview .obj' )
5118+ TargetAdd ('libpview.dll' , input = 'libpview_pview .obj' )
51185119 TargetAdd ('libpview.dll' , input = 'libp3framework.dll' )
51195120 if not PkgSkip ("EGG" ):
51205121 TargetAdd ('libpview.dll' , input = 'libpandaegg.dll' )
51215122 TargetAdd ('libpview.dll' , input = 'libp3android.dll' )
51225123 TargetAdd ('libpview.dll' , input = COMMON_PANDA_LIBS )
51235124 TargetAdd ('libpview.dll' , opts = ['MODULE' , 'ANDROID' ])
51245125
5126+ if (not RTDIST and PkgSkip ("PYTHON" )== 0 ):
5127+ OPTS += ['PYTHON' ]
5128+ TargetAdd ('ppython_ppython.obj' , opts = OPTS , input = 'python_main.cxx' )
5129+ TargetAdd ('libppython.dll' , input = 'android_native_app_glue.obj' )
5130+ TargetAdd ('libppython.dll' , input = 'android_main.obj' )
5131+ TargetAdd ('libppython.dll' , input = 'ppython_ppython.obj' )
5132+ TargetAdd ('libppython.dll' , input = 'libp3framework.dll' )
5133+ TargetAdd ('libppython.dll' , input = 'libp3android.dll' )
5134+ TargetAdd ('libppython.dll' , input = COMMON_PANDA_LIBS )
5135+ TargetAdd ('libppython.dll' , opts = ['MODULE' , 'ANDROID' , 'PYTHON' ])
5136+
51255137#
51265138# DIRECTORY: panda/src/androiddisplay/
51275139#
@@ -7505,7 +7517,7 @@ def copy_library(source, base):
75057517 continue
75067518 if '.so.' in line :
75077519 dep = line .rpartition ('.so.' )[0 ] + '.so'
7508- oscmd ("patchelf --replace-needed %s %s %s" % (line , dep , target ))
7520+ oscmd ("patchelf --replace-needed %s %s %s" % (line , dep , target ), True )
75097521 else :
75107522 dep = line
75117523
@@ -7516,6 +7528,7 @@ def copy_library(source, base):
75167528 copy_library (os .path .realpath (fulldep ), dep )
75177529 break
75187530
7531+ # Now copy every lib in the lib dir, and its dependencies.
75197532 for base in os .listdir (source_dir ):
75207533 if not base .startswith ('lib' ):
75217534 continue
@@ -7527,6 +7540,59 @@ def copy_library(source, base):
75277540 continue
75287541 copy_library (source , base )
75297542
7543+ # Same for Python extension modules. However, Android is strict about
7544+ # library naming, so we have a special naming scheme for these, in
7545+ # conjunction with a custom import hook to find these modules.
7546+ if not PkgSkip ("PYTHON" ):
7547+ suffix = GetExtensionSuffix ()
7548+ source_dir = os .path .join (GetOutputDir (), "panda3d" )
7549+ for base in os .listdir (source_dir ):
7550+ if not base .endswith (suffix ):
7551+ continue
7552+ modname = base [:- len (suffix )]
7553+ source = os .path .join (source_dir , base )
7554+ copy_library (source , "libpy.panda3d.{}.so" .format (modname ))
7555+
7556+ # Same for standard Python modules.
7557+ import _ctypes
7558+ source_dir = os .path .dirname (_ctypes .__file__ )
7559+ for base in os .listdir (source_dir ):
7560+ if not base .endswith ('.so' ):
7561+ continue
7562+ modname = base .partition ('.' )[0 ]
7563+ source = os .path .join (source_dir , base )
7564+ copy_library (source , "libpy.{}.so" .format (modname ))
7565+
7566+ def copy_python_tree (source_root , target_root ):
7567+ for source_dir , dirs , files in os .walk (source_root ):
7568+ if 'site-packages' in dirs :
7569+ dirs .remove ('site-packages' )
7570+
7571+ if not any (base .endswith ('.py' ) for base in files ):
7572+ continue
7573+
7574+ target_dir = os .path .join (target_root , os .path .relpath (source_dir , source_root ))
7575+ target_dir = os .path .normpath (target_dir )
7576+ os .makedirs (target_dir , 0o755 )
7577+
7578+ for base in files :
7579+ if base .endswith ('.py' ):
7580+ target = os .path .join (target_dir , base )
7581+ shutil .copy (os .path .join (source_dir , base ), target )
7582+
7583+ # Copy the Python standard library to the .apk as well.
7584+ from distutils .sysconfig import get_python_lib
7585+ stdlib_source = get_python_lib (False , True )
7586+ stdlib_target = os .path .join ("apkroot" , "lib" , "python{0}.{1}" .format (* sys .version_info ))
7587+ copy_python_tree (stdlib_source , stdlib_target )
7588+
7589+ # But also copy over our custom site.py.
7590+ shutil .copy ("panda/src/android/site.py" , os .path .join (stdlib_target , "site.py" ))
7591+
7592+ # And now make a site-packages directory containing our direct/panda3d/pandac modules.
7593+ for tree in "panda3d" , "direct" , "pandac" :
7594+ copy_python_tree (os .path .join (GetOutputDir (), tree ), os .path .join (stdlib_target , "site-packages" , tree ))
7595+
75307596 # Copy the models and config files to the virtual assets filesystem.
75317597 oscmd ("mkdir apkroot/assets" )
75327598 oscmd ("cp -R %s apkroot/assets/models" % (os .path .join (GetOutputDir (), "models" )))
@@ -7545,7 +7611,11 @@ def copy_library(source, base):
75457611 oscmd (aapt_cmd )
75467612
75477613 # And add all the libraries to it.
7548- oscmd ("cd apkroot && aapt add ../%s classes.dex lib/%s/lib*.so" % (apk_unaligned , SDK ["ANDROID_ABI" ]))
7614+ oscmd ("cd apkroot && aapt add ../%s classes.dex" % (apk_unaligned ))
7615+ for path , dirs , files in os .walk ('apkroot/lib' ):
7616+ if files :
7617+ rel = os .path .relpath (path , 'apkroot' )
7618+ oscmd ("cd apkroot && aapt add ../%s %s/*" % (apk_unaligned , rel ))
75497619
75507620 # Now align the .apk, which is necessary for Android to load it.
75517621 oscmd ("zipalign -v -p 4 %s %s" % (apk_unaligned , apk_unsigned ))
0 commit comments