Skip to content

Commit

Permalink
android: build aab bundle to contain debug symbols
Browse files Browse the repository at this point in the history
We only build split aab file for each architecture for now.

Fixes #1060.
  • Loading branch information
Chilledheart committed Oct 17, 2024
1 parent 9d381f4 commit dffbfa6
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 38 deletions.
55 changes: 31 additions & 24 deletions .github/workflows/releases-android-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobs:
sudo tar -C /usr/local --strip-components=1 -xf cmake-3.29.8-linux-x86_64.tar.gz
cmake --version
rm -f *.tar.gz
- name: Build TGZ packages (no build, for patching)
- name: Build Binary (no build, for patching)
run: |
# FIXME required by next step, need to copy to current clang with ndk's libunwind.a
./tools/build --variant gui --arch ${{ matrix.arch }} --system android \
Expand All @@ -177,30 +177,10 @@ jobs:
sudo apt remove libc6-i386
sudo dpkg -i qemu-user_*.deb
- name: Install the Release certificate
if: ${{ github.event_name == 'release' }}
env:
SIGNING_STORE_BASE64: ${{ secrets.SIGNING_STORE_BASE64 }}
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: |
echo -n "$SIGNING_STORE_BASE64" | base64 --decode > $RUNNER_TEMP/release.jks
echo "SIGNING_STORE_PATH=$RUNNER_TEMP/release.jks" >> $GITHUB_ENV
echo "SIGNING_STORE_PASSWORD=$SIGNING_STORE_PASSWORD" >> $GITHUB_ENV
echo "SIGNING_KEY_ALIAS=$SIGNING_KEY_ALIAS" >> $GITHUB_ENV
echo "SIGNING_KEY_PASSWORD=$SIGNING_KEY_PASSWORD" >> $GITHUB_ENV
- name: Build TGZ packages
- name: Build Binary
run: |
./tools/build --variant gui --arch ${{ matrix.arch }} --system android \
-build-benchmark -build-test \
-android-sdk-dir "${ANDROID_SDK_ROOT}" -android-ndk-ver "${ANDROID_NDK_VER}"
- name: Clean up keychain and provisioning profile
if: ${{ always() }}
run: |
if [ ! -z $SIGNING_STORE_PATH ]; then
rm -f $SIGNING_STORE_PATH
fi
-build-benchmark -build-test -nc -no-packaging
- name: "Install dependency: android sysroot (test purpose)"
if: ${{ steps.sysroot-cache.outputs.cache-hit != 'true' }}
run: |
Expand All @@ -224,9 +204,36 @@ jobs:
qemu-${{ matrix.qemu_suffix }} -L $SYSROOT \
-E TMPDIR=$PWD/build-android${{ matrix.apilevel }}-${{ matrix.arch }} \
$PWD/build-android${{ matrix.apilevel }}-${{ matrix.arch }}/yass_test
- name: Install the Release certificate
if: ${{ github.event_name == 'release' }}
env:
SIGNING_STORE_BASE64: ${{ secrets.SIGNING_STORE_BASE64 }}
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: |
echo -n "$SIGNING_STORE_BASE64" | base64 --decode > $RUNNER_TEMP/release.jks
echo "SIGNING_STORE_PATH=$RUNNER_TEMP/release.jks" >> $GITHUB_ENV
echo "SIGNING_STORE_PASSWORD=$SIGNING_STORE_PASSWORD" >> $GITHUB_ENV
echo "SIGNING_KEY_ALIAS=$SIGNING_KEY_ALIAS" >> $GITHUB_ENV
echo "SIGNING_KEY_PASSWORD=$SIGNING_KEY_PASSWORD" >> $GITHUB_ENV
- name: Build AAB bundle
run: |
./tools/build --variant gui --arch ${{ matrix.arch }} --system android \
-build-benchmark -build-test -nc -android-aab
- name: Build APK package
run: |
./tools/build --variant gui --arch ${{ matrix.arch }} --system android \
-build-benchmark -build-test -nc
- name: Clean up keychain and provisioning profile
if: ${{ always() }}
run: |
if [ ! -z $SIGNING_STORE_PATH ]; then
rm -f $SIGNING_STORE_PATH
fi
- name: Upload dist tarball (including debuginfo)
if: ${{ github.event_name == 'release' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.event.release.tag_name }} yass*.tgz yass*.apk
gh release upload ${{ github.event.release.tag_name }} yass*.tgz yass*.apk yass*.aab yass*.aab.idsig
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ local.properties
*.hsp
*.har
*.app
*.aab
*.aab.idsig
8 changes: 8 additions & 0 deletions android/yass/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ android {
}
}
buildTypes {
debug {
ndk {
debugSymbolLevel 'FULL' // 'SYMBOL_TABLE' for smaller size
}
}
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
debugSymbolLevel 'FULL' // 'SYMBOL_TABLE' for smaller size
}
}
}
// https://developer.android.com/build/configure-apk-splits
Expand Down
60 changes: 46 additions & 14 deletions tools/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var mingwDir string
var mingwAllowXpFlag bool

var androidApiLevel int
var androidAab bool

var androidSdkDir string
var androidNdkVer string
Expand Down Expand Up @@ -202,6 +203,7 @@ func InitFlag() {
flag.StringVar(&mingwDir, "mingw-dir", "", "MinGW Dir Path")
flag.BoolVar(&mingwAllowXpFlag, "mingw-allow-xp", false, "Enable Windows XP Build")

flag.BoolVar(&androidAab, "android-aab", false, "Build aab format instead of apk")
flag.IntVar(&androidApiLevel, "android-api", 24, "Select Android API Level")
flag.StringVar(&androidSdkDir, "android-sdk-dir", getEnv("ANDROID_SDK_ROOT", ""), "Android SDK Home Path")
flag.StringVar(&androidNdkVer, "android-ndk-ver", getEnv("ANDROID_NDK_VER", "26.3.11579264"), "Android NDK Version")
Expand Down Expand Up @@ -1599,7 +1601,7 @@ func postStateStripBinaries() {
glog.Info("Done in xcodebuild")
return
}
if systemNameFlag == "mingw" || systemNameFlag == "android" || systemNameFlag == "harmony" || systemNameFlag == "linux" || systemNameFlag == "freebsd" {
if systemNameFlag == "mingw" || systemNameFlag == "harmony" || systemNameFlag == "linux" || systemNameFlag == "freebsd" {
objcopy := filepath.Join(clangPath, "bin", "llvm-objcopy")
if runtime.GOOS == "windows" {
objcopy = filepath.Join(clangPath, "bin", "llvm-objcopy.exe")
Expand Down Expand Up @@ -2037,14 +2039,24 @@ func archiveMainFile(output string, prefix string, paths []string, dllPaths []st
}
_, abi := getAndroidTargetAndAppAbi(archFlag)
if cmakeBuildTypeFlag == "Release" || cmakeBuildTypeFlag == "MinSizeRel" {
cmdRun([]string{"./gradlew", "yass:assembleRelease", "--parallel", "--info"}, true)
err = os.Rename(fmt.Sprintf("./yass/build/outputs/apk/release/yass-%s-release.apk", abi), output)
if androidAab {
cmdRun([]string{"./gradlew", "yass:bundleRelease", "--parallel", "--info"}, true)
err = os.Rename("./yass/build/outputs/bundle/release/yass-release.aab", output)
} else {
cmdRun([]string{"./gradlew", "yass:assembleRelease", "--parallel", "--info"}, true)
err = os.Rename(fmt.Sprintf("./yass/build/outputs/apk/release/yass-%s-release.apk", abi), output)
}
if err != nil {
glog.Fatalf("%v", err)
}
} else {
cmdRun([]string{"./gradlew", "yass:assembleDebug", "--parallel", "--info"}, true)
err = os.Rename(fmt.Sprintf("./yass/build/outputs/apk/debug/yass-%s-release-unsigned.apk", abi), output)
if androidAab {
cmdRun([]string{"./gradlew", "yass:bundleDebug", "--parallel", "--info"}, true)
err = os.Rename("./yass/build/outputs/bundle/debug/yass-debug.aab", output)
} else {
cmdRun([]string{"./gradlew", "yass:assembleDebug", "--parallel", "--info"}, true)
err = os.Rename(fmt.Sprintf("./yass/build/outputs/apk/debug/yass-%s-release-unsigned.apk", abi), output)
}
if err != nil {
glog.Fatalf("%v", err)
}
Expand Down Expand Up @@ -2257,7 +2269,11 @@ func postStateArchives() map[string][]string {
archiveSuffix := fmt.Sprintf(archiveFormat, "", "", "")
archiveSuffix = archiveSuffix[1:]
if systemNameFlag == "android" && variantFlag == "gui" {
archive = fmt.Sprintf(archiveFormat, APPNAME, "", ".apk")
if androidAab {
archive = fmt.Sprintf(archiveFormat, APPNAME, "", ".aab")
} else {
archive = fmt.Sprintf(archiveFormat, APPNAME, "", ".apk")
}
}
if systemNameFlag == "darwin" {
archive = fmt.Sprintf(archiveFormat, APPNAME, "-unsigned", ".dmg")
Expand Down Expand Up @@ -2357,11 +2373,8 @@ func postStateArchives() map[string][]string {
}
archiveFiles(debugArchive, archivePrefix, dbgPaths)
} else if systemNameFlag == "android" {
dbgPaths = append(dbgPaths, getAppName()+".dbg")
if hasCrashpadDbg {
dbgPaths = append(dbgPaths, "crashpad_handler.dbg")
}
archiveFiles(debugArchive, archivePrefix, dbgPaths)
// nop because we produces aab now
dbgPaths = []string{}
} else if systemNameFlag == "darwin" {
dbgPaths = append(dbgPaths, getAppName()+".dSYM")
if hasCrashpadDbg {
Expand All @@ -2381,7 +2394,9 @@ func postStateArchives() map[string][]string {
archiveFiles(debugArchive, archivePrefix, []string{getAppName() + ".dSYM", "YassPacketTunnel.appex.dSYM"})
dbgPaths = append(dbgPaths, getAppName()+".dSYM", "YassPacketTunnel.appex.dSYM")
}
archives[debugArchive] = dbgPaths
if len(dbgPaths) > 0 {
archives[debugArchive] = dbgPaths
}

// Create openwrt Makefile
if subSystemNameFlag == "openwrt" && variantFlag == "cli" {
Expand All @@ -2401,15 +2416,32 @@ func get7zPath() string {
func inspectArchive(file string, files []string) {
if strings.HasSuffix(file, ".dmg") {
cmdRun([]string{"hdiutil", "imageinfo", file}, false)
} else if strings.HasSuffix(file, ".zip") || strings.HasSuffix(file, ".msi") || strings.HasSuffix(file, ".exe") || strings.HasSuffix(file, ".apk") || strings.HasSuffix(file, ".ipa") || strings.HasSuffix(file, ".hap") {
} else if strings.HasSuffix(file, ".zip") || strings.HasSuffix(file, ".msi") || strings.HasSuffix(file, ".exe") || strings.HasSuffix(file, ".aab") || strings.HasSuffix(file, ".apk") || strings.HasSuffix(file, ".ipa") || strings.HasSuffix(file, ".hap") {
p7z := get7zPath()
cmdRun([]string{p7z, "l", file}, false)
if strings.HasSuffix(file, ".apk") {
if strings.HasSuffix(file, ".aab") {
// sign aab file (https://developer.android.com/tools/apksigner)
// FIXME hardcoded with build-tools 35.0.0
apksigner := filepath.Join(androidSdkDir, "build-tools", "35.0.0", "apksigner")
cmdRun([]string{apksigner, "sign", "-v", "--min-sdk-version", fmt.Sprintf("%d", androidApiLevel),
"--ks", getEnv("SIGNING_STORE_PATH", "../android/keystore/debug_keystore.jks"),
"--ks-pass", fmt.Sprintf("pass:%s", getEnv("SIGNING_STORE_PASSWORD", "abc123")),
"--ks-key-alias", getEnv("SIGNING_KEY_ALIAS", "key0"),
"--key-pass", fmt.Sprintf("pass:%s", getEnv("SIGNING_KEY_PASSWORD", "abc123")),
file}, true)
}
if strings.HasSuffix(file, ".apk") || strings.HasSuffix(file, ".aab") {
// check 16kb-alignment with zipalign
// FIXME hardcoded with build-tools 35.0.0
zipalign := filepath.Join(androidSdkDir, "build-tools", "35.0.0", "zipalign")
cmdRun([]string{zipalign, "-c", "-P", "16", "-v", "4", file}, true)
}
if strings.HasSuffix(file, ".apk") {
// verify signature
// FIXME hardcoded with build-tools 35.0.0
apksigner := filepath.Join(androidSdkDir, "build-tools", "35.0.0", "apksigner")
cmdRun([]string{apksigner, "verify", "-v", "--min-sdk-version", fmt.Sprintf("%d", androidApiLevel), file}, true)
}
} else if strings.HasSuffix(file, ".tgz") {
cmdRun([]string{"tar", "tvf", file}, false)
} else {
Expand Down

0 comments on commit dffbfa6

Please sign in to comment.