Skip to content

Commit

Permalink
Merge pull request #1121 from Chilledheart/android_build_aab_bundle
Browse files Browse the repository at this point in the history
android: build aab bundle to contain debug symbols
  • Loading branch information
Chilledheart authored Oct 17, 2024
2 parents f66e089 + 4eb298d commit 4a397da
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 44 deletions.
59 changes: 33 additions & 26 deletions .github/workflows/releases-android-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
with:
path: |
third_party/crashpad
key: ${{ runner.os }}-android-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}-16k-alignment
key: ${{ runner.os }}-android-${{ matrix.arch }}-crashpad-${{ hashFiles('CRASHPAD_COMMIT') }}-v${{ env.CACHE_EPOCH }}-16k-alignment-no-stripped
- name: Cache cargo build stage
id: cargo-cache
uses: actions/cache@v4
Expand Down 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 @@ -160,7 +160,7 @@ jobs:
- name: Download and Build Crashpad
if: ${{ steps.crashpad-cache.outputs.cache-hit != 'true' }}
run: |
WITH_OS=android WITH_CPU=${{ matrix.arch }} ./scripts/build-crashpad.sh
WITH_OS=android WITH_CPU=${{ matrix.arch }} SKIP_STRIP=1 ./scripts/build-crashpad.sh
- name: "Install dependency: qemu user cache"
if: ${{ steps.qemu-user-cache.outputs.cache-hit != 'true' }}
run: |
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: 1 addition & 1 deletion .github/workflows/releases-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
if: ${{ steps.crashpad-cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
WITH_CPU=${{ matrix.arch }} ./scripts/build-crashpad.sh
WITH_CPU=${{ matrix.arch }} SKIP_STRIP=1 ./scripts/build-crashpad.sh
- name: Build
run: |
set VCToolsVersion=
Expand Down
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2893,7 +2893,9 @@ if (UNIX AND (${CMAKE_BUILD_TYPE} MATCHES MinSizeRel OR ${CMAKE_BUILD_TYPE} MATC

if (NOT IOS)
file(COPY "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler.dbg" DESTINATION ${CMAKE_BINARY_DIR})
if (EXISTS "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler.dbg")
file(COPY "${_CRASHPAD_BINARY_PREFIX}/crashpad_handler.dbg" DESTINATION ${CMAKE_BINARY_DIR})
endif()
set(_CRASHPAD_BINARY "${CMAKE_BINARY_DIR}/crashpad_handler")
endif()
endif()
Expand Down
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
4 changes: 2 additions & 2 deletions scripts/build-crashpad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ OBJCOPY="$PWD/llvm-build/Release+Asserts/bin/llvm-objcopy"

# strip debug symbols (ignore msvc build which generating pdbs already)
function strip_binary {
if [ "$WITH_OS" = "win" ]; then
echo 'omit calling llvm-objcopy on msvc binary'
if [ ! -z "$SKIP_STRIP" ]; then
echo 'omit calling llvm-objcopy as required'
return
fi

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 4a397da

Please sign in to comment.