makepanda: Replace dx with d8 for building Dalvik executable (Android)

Also, do it in makepanda instead of in makepackage
This commit is contained in:
rdb 2021-12-06 22:28:18 +01:00
parent 798fa90513
commit 9230af94a3
3 changed files with 36 additions and 13 deletions

View File

@ -794,19 +794,8 @@ def MakeInstallerAndroid(version, **kwargs):
if os.path.exists(apk_unsigned):
os.unlink(apk_unsigned)
# Compile the Java classes into a Dalvik executable.
dx_cmd = "d8 --output apkroot "
if GetOptimize() <= 2:
dx_cmd += "--debug "
else:
dx_cmd += "--release "
if "ANDROID_API" in SDK:
dx_cmd += "--min-api %d " % (SDK["ANDROID_API"])
if "ANDROID_JAR" in SDK:
dx_cmd += "--lib %s " % (SDK["ANDROID_JAR"])
dx_cmd += " ".join(glob.glob(os.path.join(outputdir, "classes", "org", "panda3d", "android", "*.class")))
oscmd(dx_cmd)
# Copy the compiled Java classes.
oscmd("cp %s apkroot/classes.dex" % (os.path.join(outputdir, "classes.dex")))
# Copy the libraries one by one. In case of library dependencies, strip
# off any suffix (eg. libfile.so.1.0), as Android does not support them.

View File

@ -2111,6 +2111,31 @@ def CompileMIDL(target, src, opts):
oscmd(cmd)
##########################################################################################
#
# CompileDalvik
#
##########################################################################################
def CompileDalvik(target, inputs, opts):
cmd = "d8 --output " + os.path.dirname(target)
if GetOptimize() <= 2:
cmd += " --debug"
else:
cmd += " --release"
if "ANDROID_API" in SDK:
cmd += " --min-api %d" % (SDK["ANDROID_API"])
if "ANDROID_JAR" in SDK:
cmd += " --lib %s" % (SDK["ANDROID_JAR"])
for i in inputs:
cmd += " " + BracketNameWithQuotes(i)
oscmd(cmd)
##########################################################################################
#
# CompileAnything
@ -2222,6 +2247,9 @@ def CompileAnything(target, inputs, opts, progress = None):
elif infile.endswith(".r"):
ProgressOutput(progress, "Building resource object", target)
return CompileRsrc(target, infile, opts)
elif origsuffix == ".dex":
ProgressOutput(progress, "Building Dalvik object", target)
return CompileDalvik(target, inputs, opts)
exit("Don't know how to compile: %s from %s" % (target, inputs))
##########################################################################################
@ -4844,6 +4872,11 @@ if GetTarget() == 'android':
TargetAdd('org/panda3d/android/PandaActivity.class', opts=OPTS, input='PandaActivity.java')
TargetAdd('org/panda3d/android/PythonActivity.class', opts=OPTS, input='PythonActivity.java')
TargetAdd('classes.dex', input='org/panda3d/android/NativeIStream.class')
TargetAdd('classes.dex', input='org/panda3d/android/NativeOStream.class')
TargetAdd('classes.dex', input='org/panda3d/android/PandaActivity.class')
TargetAdd('classes.dex', input='org/panda3d/android/PythonActivity.class')
TargetAdd('p3android_composite1.obj', opts=OPTS, input='p3android_composite1.cxx')
TargetAdd('libp3android.dll', input='p3android_composite1.obj')
TargetAdd('libp3android.dll', input=COMMON_PANDA_LIBS)

View File

@ -3361,6 +3361,7 @@ def CalcLocation(fn, ipath):
if (GetOptimize() <= 2 and target == 'windows'): dllext = "_d"
if (fn == "AndroidManifest.xml"): return OUTPUTDIR+"/"+fn
if (fn == "classes.dex"): return OUTPUTDIR+"/"+fn
if (fn.endswith(".cxx")): return CxxFindSource(fn, ipath)
if (fn.endswith(".I")): return CxxFindSource(fn, ipath)
if (fn.endswith(".h")): return CxxFindSource(fn, ipath)