Skip to content

Commit

Permalink
Build everything ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Aug 24, 2017
1 parent 7f8ba74 commit a1e33c4
Show file tree
Hide file tree
Showing 17 changed files with 911 additions and 204 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Declare files that will always have CRLF line endings on checkout.
*.cmd text eol=crlf
*.bat text eol=crlf

# Denote all files that are truly binary and should not be modified.
chromeos/** binary
Expand Down
47 changes: 34 additions & 13 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,17 @@ def build_apk(args):
if proc.returncode != 0:
error('Zipalign Magisk Manager failed!')

proc = subprocess.run('{} sign --ks {} --out {} {}'.format(
'java -jar {}'.format(os.path.join('../ziptools/apksigner.jar')),
# Find apksigner.jar
apksigner = ''
for root, dirs, files in os.walk(os.path.join(os.environ['ANDROID_HOME'], 'build-tools', build_tool)):
if 'apksigner.jar' in files:
apksigner = os.path.join(root, 'apksigner.jar')
break
if not apksigner:
error('Cannot find apksigner.jar in Android SDK build tools')

proc = subprocess.run('java -jar {} sign --ks {} --out {} {}'.format(
apksigner,
os.path.join('..', 'release_signature.jks'),
release, aligned), shell=True)
if proc.returncode != 0:
Expand All @@ -140,30 +149,42 @@ def build_apk(args):
os.chdir('..')

def sign_adjust_zip(unsigned, output):
header('* Signing / Adjusting Zip')

# Unsigned->signed
proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'signapk.jar'),
os.path.join('ziptools', 'public.certificate.x509.pem'),
os.path.join('ziptools', 'private.key.pk8'), unsigned, 'tmp_signed.zip'])
if proc.returncode != 0:
error('First sign flashable zip failed!')
zipsigner = os.path.join('ziptools', 'zipsigner', 'build', 'libs', 'zipsigner.jar')

if os.name != 'nt' and not os.path.exists(os.path.join('ziptools', 'zipadjust')):
header('* Building zipadjust')
# Compile zipadjust
proc = subprocess.run('gcc -o ziptools/zipadjust ziptools/src/*.c -lz', shell=True)
proc = subprocess.run('gcc -o ziptools/zipadjust ziptools/zipadjust_src/*.c -lz', shell=True)
if proc.returncode != 0:
error('Build zipadjust failed!')
if not os.path.exists(zipsigner):
header('* Building zipsigner.jar')
os.chdir(os.path.join('ziptools', 'zipsigner'))
proc = subprocess.run('{} shadowJar'.format(os.path.join('.', 'gradlew')), shell=True)
if proc.returncode != 0:
error('Build zipsigner.jar failed!')
os.chdir(os.path.join('..', '..'))

header('* Signing / Adjusting Zip')

publicKey = os.path.join('ziptools', 'public.certificate.x509.pem')
privateKey = os.path.join('ziptools', 'private.key.pk8')

# Unsigned->signed
proc = subprocess.run(['java', '-jar', zipsigner,
publicKey, privateKey, unsigned, 'tmp_signed.zip'])
if proc.returncode != 0:
error('First sign flashable zip failed!')

# Adjust zip
proc = subprocess.run([os.path.join('ziptools', 'zipadjust'), 'tmp_signed.zip', 'tmp_adjusted.zip'])
if proc.returncode != 0:
error('Adjust flashable zip failed!')

# Adjusted -> output
proc = subprocess.run(['java', '-jar', os.path.join('ziptools', 'minsignapk.jar'),
os.path.join('ziptools', 'public.certificate.x509.pem'),
os.path.join('ziptools', 'private.key.pk8'), 'tmp_adjusted.zip', output])
proc = subprocess.run(['java', '-jar', zipsigner,
"-m", publicKey, privateKey, 'tmp_adjusted.zip', output])
if proc.returncode != 0:
error('Second sign flashable zip failed!')

Expand Down
Binary file removed ziptools/apksigner.jar
Binary file not shown.
Binary file removed ziptools/minsignapk.jar
Binary file not shown.
Binary file removed ziptools/signapk.jar
Binary file not shown.
191 changes: 0 additions & 191 deletions ziptools/src/MinSignAPK.java

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions ziptools/zipsigner/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.iml
.gradle
/local.properties
.idea/
/build
*.hprof
app/.externalNativeBuild/
36 changes: 36 additions & 0 deletions ziptools/zipsigner/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
group 'com.topjohnwu'
version '1.0.0'

apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'

sourceCompatibility = 1.8

jar {
manifest {
attributes 'Main-Class': 'com.topjohnwu.ZipSigner'
}
}

shadowJar {
classifier = null
version = null
}

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}

repositories {
mavenCentral()
}

dependencies {
compile 'org.bouncycastle:bcprov-jdk15on:1.57'
compile 'org.bouncycastle:bcpkix-jdk15on:1.57'
}
Binary file not shown.
6 changes: 6 additions & 0 deletions ziptools/zipsigner/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Aug 24 10:35:40 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-bin.zip
Loading

0 comments on commit a1e33c4

Please sign in to comment.