Update tpt-libs, add support for android

This commit is contained in:
Tamás Bálint Misius
2022-04-11 21:11:03 +02:00
parent 29ed52d50e
commit f7527b46e6
53 changed files with 837 additions and 118 deletions

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.powdertoy.tpt"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto"
>
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="30"
/>
<uses-feature
android:glEsVersion="0x00020000"
/>
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false"
/>
<uses-feature
android:name="android.hardware.bluetooth"
android:required="false"
/>
<uses-feature
android:name="android.hardware.gamepad"
android:required="false"
/>
<uses-feature
android:name="android.hardware.usb.host"
android:required="false"
/>
<uses-feature
android:name="android.hardware.type.pc"
android:required="false"
/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true"
>
<activity
android:name=".PowderActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:preferMinimalPostProcessing="true"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter> -->
</activity>
</application>
</manifest>

26
android/align-apk.py Normal file
View File

@@ -0,0 +1,26 @@
import os
import os.path
import subprocess
import sys
(
script,
zipalign,
build_dir,
unsigned_name,
unaligned_name,
) = sys.argv
unaligned_path = os.path.join(build_dir, unaligned_name)
unsigned_path = os.path.join(build_dir, unsigned_name)
if os.path.exists(unsigned_path):
os.remove(unsigned_path)
if subprocess.run([
zipalign,
'-f', '4',
unaligned_path,
unsigned_path,
]).returncode:
sys.exit(1)

102
android/build-apk.py Normal file
View File

@@ -0,0 +1,102 @@
import os
import os.path
import shutil
import subprocess
import sys
(
script,
d8,
aapt,
aapt2,
source_dir,
build_dir,
private_name,
unaligned_name,
sha_name,
android_jar,
sdl_jar,
powder_jar,
tpt_arch,
debug_release,
manifest_xml,
*resources,
) = sys.argv
if tpt_arch == 'i686':
android_arch = 'x86'
if tpt_arch == 'arm':
android_arch = 'armeabi-v7a'
if tpt_arch == 'arm64':
android_arch = 'arm64-v8a'
if tpt_arch == 'x86_64':
android_arch = 'x86_64'
manifest_path = os.path.join(build_dir, manifest_xml)
sha_path = os.path.join(build_dir, sha_name)
unaligned_path = os.path.join(build_dir, unaligned_name)
private_dir = os.path.join(build_dir, private_name)
arch_dir = os.path.join(private_dir, 'lib', android_arch)
sha_lib_path = os.path.join(arch_dir, sha_name)
flat_dir = os.path.join(private_dir, 'flat')
if os.path.exists(arch_dir):
shutil.rmtree(arch_dir)
os.makedirs(arch_dir)
if os.path.exists(sha_lib_path):
os.remove(sha_lib_path)
if os.path.exists(unaligned_path):
os.remove(unaligned_path)
if os.path.exists(flat_dir):
shutil.rmtree(flat_dir)
os.makedirs(flat_dir)
if subprocess.run([
aapt2,
'compile',
'-o', os.path.join(private_dir, 'flat'),
*resources,
], cwd = build_dir).returncode:
sys.exit(1)
aapt2_link_inputs = []
for root, dirs, files in os.walk(flat_dir):
for name in files:
if name.endswith(".flat"):
aapt2_link_inputs.append(os.path.join(root, name))
if subprocess.run([
aapt2,
'link',
'-o', unaligned_path,
'-I', android_jar,
'--manifest', manifest_path,
*aapt2_link_inputs,
]).returncode:
sys.exit(1)
shutil.copy(sha_path, sha_lib_path)
if subprocess.run([
aapt,
'add',
unaligned_path,
os.path.join('lib', android_arch, sha_name),
], cwd = private_dir).returncode:
sys.exit(1)
if subprocess.run([
d8,
os.path.join(build_dir, sdl_jar),
os.path.join(build_dir, powder_jar),
'--' + debug_release,
'--lib', android_jar,
'--min-api', '21',
], cwd = private_dir).returncode:
sys.exit(1)
if subprocess.run([
aapt,
'add',
unaligned_path,
'classes.dex',
], cwd = private_dir).returncode:
sys.exit(1)

View File

@@ -0,0 +1,8 @@
[constants]
android_ndk_toolchain_prefix = 'aarch64-linux-android21-'
[host_machine]
system = 'android'
cpu_family = 'aarch64'
cpu = 'armv8'
endian = 'little'

View File

@@ -0,0 +1,8 @@
[constants]
android_ndk_toolchain_prefix = 'armv7a-linux-androideabi19-'
[host_machine]
system = 'android'
cpu_family = 'arm'
cpu = 'armv7a'
endian = 'little'

8
android/cross/x86.ini Normal file
View File

@@ -0,0 +1,8 @@
[constants]
android_ndk_toolchain_prefix = 'i686-linux-android19-'
[host_machine]
system = 'android'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'

8
android/cross/x86_64.ini Normal file
View File

@@ -0,0 +1,8 @@
[constants]
android_ndk_toolchain_prefix = 'x86_64-linux-android21-'
[host_machine]
system = 'android'
cpu_family = 'x86_64'
cpu = 'amd64'
endian = 'little'

28
android/install-apk.py Normal file
View File

@@ -0,0 +1,28 @@
import os
import os.path
import subprocess
import sys
(
script,
adb,
build_dir,
phony,
apk_name,
) = sys.argv
apk_path = os.path.join(build_dir, apk_name)
phony_path = os.path.join(build_dir, phony)
if os.path.exists(phony_path):
os.remove(phony_path)
if subprocess.run([
adb,
'install',
apk_path,
]).returncode:
sys.exit(1)
with open(phony_path, 'w') as _:
pass

6
android/meson.build Normal file
View File

@@ -0,0 +1,6 @@
android_manifest_xml = files('AndroidManifest.xml')
powder_jar_sources = files(
'uk/co/powdertoy/tpt/PowderActivity.java',
)
subdir('res')

54
android/powder-jar.py Normal file
View File

@@ -0,0 +1,54 @@
import os
import os.path
import shutil
import subprocess
import sys
(
script,
javac,
jar,
source_dir,
build_dir,
private_name,
powder_jar_name,
android_jar,
java_runtime,
sdl_jar,
debug_release,
*javac_sources,
) = sys.argv
powder_jar_path = os.path.join(build_dir, powder_jar_name)
private_dir = os.path.join(build_dir, private_name)
class_dir = os.path.join(private_dir, 'class')
if os.path.exists(powder_jar_path):
os.remove(powder_jar_path)
if os.path.exists(class_dir):
shutil.rmtree(class_dir)
os.makedirs(class_dir)
if subprocess.run([
javac,
'-d', class_dir,
'-source', '1.8',
'-target', '1.8',
'-bootclasspath', java_runtime,
'-classpath', os.pathsep.join([ android_jar, sdl_jar ]),
*javac_sources,
], cwd = build_dir).returncode:
sys.exit(1)
jar_inputs = []
for root, dirs, files in os.walk(class_dir):
for name in files:
if name.endswith(".class"):
jar_inputs.append(os.path.relpath(os.path.join(root, name), start = class_dir))
if subprocess.run([
jar,
'cMf',
powder_jar_path,
*jar_inputs,
], cwd = class_dir).returncode:
sys.exit(1)

6
android/res/meson.build Normal file
View File

@@ -0,0 +1,6 @@
android_resources = files(
'mipmap-mdpi/ic_launcher.png',
'values/colors.xml',
'values/strings.xml',
'values/styles.xml',
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">The Powder Toy</string>
</resources>

View File

@@ -0,0 +1,4 @@
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
</resources>

24
android/run-apk.py Normal file
View File

@@ -0,0 +1,24 @@
import os
import os.path
import subprocess
import sys
(
script,
adb,
build_dir,
phony,
apk_name,
) = sys.argv
apk_path = os.path.join(build_dir, apk_name)
if subprocess.run([
adb,
'shell',
'am',
'start',
'--activity-clear-top',
'-n', 'uk.co.powdertoy.tpt/.PowderActivity',
]).returncode:
sys.exit(1)

35
android/sign-apk.py Normal file
View File

@@ -0,0 +1,35 @@
import os
import os.path
import subprocess
import sys
(
script,
apksigner,
build_dir,
apk_name,
unsigned_name,
android_keystore,
android_keyalias,
) = sys.argv
if 'ANDROID_KEYSTORE_PASS' not in os.environ:
print('ANDROID_KEYSTORE_PASS not set')
sys.exit(1)
unsigned_path = os.path.join(build_dir, unsigned_name)
apk_path = os.path.join(build_dir, apk_name)
if os.path.exists(apk_path):
os.remove(apk_path)
if subprocess.run([
apksigner,
'sign',
'--ks', android_keystore,
'--ks-key-alias', android_keyalias,
'--ks-pass', 'env:ANDROID_KEYSTORE_PASS',
'--out', apk_path,
unsigned_path,
]).returncode:
sys.exit(1)

View File

@@ -0,0 +1,7 @@
package uk.co.powdertoy.tpt;
import org.libsdl.app.SDLActivity;
public class PowderActivity extends SDLActivity
{
}