Skip to content

Commit

Permalink
fix: no resources.arsc compress for API 31+
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinasokan committed Mar 11, 2023
1 parent cc83774 commit a8126ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func alignAPK() {
if err != nil {
LogF("build", string(out))
}

// verify with: zipalign -c -v 4 build/app.apk
}

// signAPK signs apk with jarsigner and default debug keys
Expand Down
30 changes: 19 additions & 11 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,16 @@ func buildBundle(useAAB bool) {

w := zip.NewWriter(outFile)

addFileToZip := func(s, d string) {
dst, err := w.Create(d)
addFileToZip := func(s, d string, compress bool) {
var dst io.Writer
if compress {
dst, err = w.Create(d)
} else {
dst, err = w.CreateHeader(&zip.FileHeader{
Name: d,
Method: zip.Store,
})
}
if err != nil {
LogF("build", err)
}
Expand All @@ -154,13 +162,13 @@ func buildBundle(useAAB bool) {
}

if useAAB {
addFileToZip(filepath.Join("build", "AndroidManifest.xml"), filepath.Join("manifest", "AndroidManifest.xml"))
addFileToZip(filepath.Join("build", "classes.dex"), filepath.Join("dex", "classes.dex"))
addFileToZip(filepath.Join("build", "resources.pb"), "resources.pb")
addFileToZip(filepath.Join("build", "AndroidManifest.xml"), filepath.Join("manifest", "AndroidManifest.xml"), true)
addFileToZip(filepath.Join("build", "classes.dex"), filepath.Join("dex", "classes.dex"), true)
addFileToZip(filepath.Join("build", "resources.pb"), "resources.pb", true)
} else {
addFileToZip(filepath.Join("build", "AndroidManifest.xml"), "AndroidManifest.xml")
addFileToZip(filepath.Join("build", "classes.dex"), "classes.dex")
addFileToZip(filepath.Join("build", "resources.arsc"), "resources.arsc")
addFileToZip(filepath.Join("build", "AndroidManifest.xml"), "AndroidManifest.xml", true)
addFileToZip(filepath.Join("build", "classes.dex"), "classes.dex", true)
addFileToZip(filepath.Join("build", "resources.arsc"), "resources.arsc", false)
}

files := getFiles(filepath.Join("build", "res"), "")
Expand All @@ -169,23 +177,23 @@ func buildBundle(useAAB bool) {
if err != nil {
LogF("build", err)
}
addFileToZip(f, r)
addFileToZip(f, r, true)
}

files = getFiles("assets", "")
if len(files) > 0 {
LogI("build", "bundling assets")
}
for _, f := range files {
addFileToZip(f, f)
addFileToZip(f, f, true)
}

files = getFiles("lib", "")
if len(files) > 0 {
LogI("build", "bundling native libs")
}
for _, f := range files {
addFileToZip(f, f)
addFileToZip(f, f, true)
}

err = w.Close()
Expand Down

0 comments on commit a8126ed

Please sign in to comment.