Signing complete

This commit is contained in:
maelstrom 2024-07-26 19:12:39 +02:00
parent b73f336f4f
commit acae658fca
5 changed files with 49 additions and 5 deletions

4
.gitignore vendored
View file

@ -1,5 +1,7 @@
build/
source-apk/*.apk
keystores/*.keystore
tools/*
!tools/smali-2.5.2.jar
!tools/apktool_2.9.3.jar
!tools/apktool_2.9.3.jar
!tools/apksigner.jar

View file

@ -120,13 +120,51 @@ class Task:
debugFlag = ('-d',) if ('d' in ''.join(sys.argv[2:])) else ()
print("Building apk...")
subprocess.run(['java', '-jar', './tools/apktool_2.9.3.jar', 'b', *debugFlag, 'build/merged', '-o', 'build/apk/tumblr-ykit.apk'])
subprocess.run(['java', '-jar', './tools/apktool_2.9.3.jar', 'b', *debugFlag, 'build/merged', '-o', 'build/apk/tumblr-ykit-unsigned.apk'])
def alignApk():
Task.buildApk()
print('Aligning apk...')
subprocess.run(['tools/zipalign', '-p', '-f', '-v', '4', 'build/apk/tumblr-ykit-unsigned.apk', 'build/apk/tumblr-ykit.apk'])
def debugKey():
if Path('keystores/debug.keystore').exists():
return
print("Debug keystore does not exist, generating...")
subprocess.run(['keytool', '-genkey', '-v', '-keystore', 'keystores/debug.keystore', '-alias', 'alias_name', '-keyalg', 'RSA', '-keysize', '2048', '-validity', '10000', '-storepass', '123456', '-keypass', '123456', '-dname', 'CN=, OU=, O=, L=, ST=, C='])
def signApk():
Task.alignApk()
Task.debugKey()
debugFlag = 'd' in ''.join(sys.argv[2:])
releaseFlag = 'r' in ''.join(sys.argv[2:])
if not (debugFlag or releaseFlag):
print("Neither debug nor release flag was specified so the apk will not be signed.")
return
if releaseFlag:
if not Path('keystores/release.keystore').exists():
print("release.keystore is missing from keystores directory")
return
keystoreOpts = ('--ks', 'keystores/release.keystore',)
else:
Task.debugKey()
keystoreOpts = ('--ks', 'keystores/debug.keystore', '--ks-pass', 'pass:123456',)
print('Signing apk...')
subprocess.run(['java', '-jar', './tools/apksigner.jar', 'sign', *keystoreOpts, 'build/apk/tumblr-ykit.apk'])
print("Successfully signed apk in 'build/apk/tumblr-ykit.apk' using " + ('release' if releaseFlag else 'debug') + ' keystore')
def deployToAndroidStudio():
projDir = Path.home() / 'ApkProjects/tumblr-ykit'
if not projDir.exists():
print("No project named 'tumblr-ykit' in ~/ApkProjects/")
shutil.copy('build/apk/tumblr-ykit.apk', projDir / 'tumblr-ykit.apk')
print("Deployed to Android Studio")
@ -137,9 +175,11 @@ def main():
Task.clean()
case 'extract':
Task.extractApk()
case 'build':
case 'assemble':
Task.buildApk()
case 'build':
Task.signApk()
if ('a' in ''.join(sys.argv[2:])):
Task.deployToAndroidStudio()

View file

@ -0,0 +1 @@
Release keystore must be named 'release.keystore'

View file

@ -0,0 +1 @@
Place tumblr apk version

BIN
tools/apksigner.jar Normal file

Binary file not shown.