Android: signed, smaller release APKs

Release builds now come out one APK per ABI, signed from a gitignored
keystore.properties. Oboe is built from source with libopus and a static
libc++ into the one native library, which exports only its JNI entry
points; dex and native code are compressed in the APK and library
translations dropped. The arm64 APK went from 11.6 MB to 5.5 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 12:23:09 +00:00
co-authored by Claude Opus 5.5
parent 44ecc15bd8
commit 55e8b7bccb
5 changed files with 58 additions and 15 deletions
+4
View File
@@ -44,3 +44,7 @@ android/.gradle/
android/.kotlin/ android/.kotlin/
android/**/.cxx/ android/**/.cxx/
android/local.properties android/local.properties
# Release signing (keystore.properties points at the key)
android/keystore.properties
*.jks
+39 -2
View File
@@ -1,3 +1,5 @@
import java.util.Properties
plugins { plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.compose)
@@ -66,6 +68,14 @@ androidComponents {
} }
} }
/**
* Release signing from keystore.properties (storeFile, storePassword, keyAlias, keyPassword),
* kept out of the repository; without it the release APK is left unsigned.
*/
val releaseKeystore = rootDir.resolve("keystore.properties").takeIf { it.isFile }?.let { file ->
Properties().apply { file.inputStream().use(::load) }
}
android { android {
namespace = "com.ts3client.android" namespace = "com.ts3client.android"
compileSdk = 37 compileSdk = 37
@@ -77,19 +87,43 @@ android {
targetSdk = 36 targetSdk = 36
versionCode = 1 versionCode = 1
versionName = "0.1.0" versionName = "0.1.0"
ndk { }
abiFilters += listOf("arm64-v8a", "x86_64")
signingConfigs {
if (releaseKeystore != null) {
create("release") {
storeFile = file(releaseKeystore.getProperty("storeFile"))
storePassword = releaseKeystore.getProperty("storePassword")
keyAlias = releaseKeystore.getProperty("keyAlias")
keyPassword = releaseKeystore.getProperty("keyPassword")
}
}
}
// One APK per ABI for releases; debug builds stay a single APK for both.
splits {
abi {
isEnable = gradle.startParameter.taskNames.any { it.contains("Release") }
reset()
include("arm64-v8a", "x86_64")
isUniversalApk = false
} }
} }
buildTypes { buildTypes {
release { release {
signingConfig = signingConfigs.findByName("release")
isMinifyEnabled = true isMinifyEnabled = true
isShrinkResources = true isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
} }
} }
androidResources {
// The app is English only; drops the libraries' translations.
localeFilters += "en"
}
buildFeatures { buildFeatures {
compose = true compose = true
} }
@@ -100,6 +134,9 @@ android {
} }
packaging { packaging {
// Compressed in the APK, which then is smaller to send; extracted on install.
dex.useLegacyPackaging = true
jniLibs.useLegacyPackaging = true
resources { resources {
// BouncyCastle ships Java 9+ module metadata Android has no use for. // BouncyCastle ships Java 9+ module metadata Android has no use for.
excludes += "META-INF/versions/9/OSGI-INF/MANIFEST.MF" excludes += "META-INF/versions/9/OSGI-INF/MANIFEST.MF"
+1 -6
View File
@@ -14,15 +14,11 @@ android {
} }
externalNativeBuild { externalNativeBuild {
cmake { cmake {
arguments += "-DANDROID_STL=c++_shared" arguments += "-DANDROID_STL=c++_static"
} }
} }
} }
buildFeatures {
prefab = true
}
externalNativeBuild { externalNativeBuild {
cmake { cmake {
path = file("src/main/cpp/CMakeLists.txt") path = file("src/main/cpp/CMakeLists.txt")
@@ -38,5 +34,4 @@ android {
dependencies { dependencies {
api(project(":core")) api(project(":core"))
implementation(libs.oboe)
} }
+14 -5
View File
@@ -3,10 +3,12 @@ project(ts3audio LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
find_package(oboe REQUIRED CONFIG) # Oboe and libopus from source, built static into our one library together with a static
# libc++, so the app ships a single small .so per ABI.
# libopus from its release tarball, built static into our one library.
include(FetchContent) include(FetchContent)
FetchContent_Declare(oboe
URL https://github.com/google/oboe/archive/refs/tags/1.11.0.tar.gz
URL_HASH SHA256=0ccf2110640a2b4489f1c93a404f2978656b434d8c5dc9cb6258f9cc95c79b15)
FetchContent_Declare(opus FetchContent_Declare(opus
URL https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz URL https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz
URL_HASH SHA256=65c1d2f78b9f2fb20082c38cbe47c951ad5839345876e46941612ee87f9a7ce1) URL_HASH SHA256=65c1d2f78b9f2fb20082c38cbe47c951ad5839345876e46941612ee87f9a7ce1)
@@ -15,8 +17,15 @@ set(OPUS_BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(OPUS_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE) set(OPUS_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE)
set(OPUS_INSTALL_PKG_CONFIG_MODULE OFF CACHE BOOL "" FORCE) set(OPUS_INSTALL_PKG_CONFIG_MODULE OFF CACHE BOOL "" FORCE)
set(OPUS_INSTALL_CMAKE_CONFIG_MODULE OFF CACHE BOOL "" FORCE) set(OPUS_INSTALL_CMAKE_CONFIG_MODULE OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(opus) FetchContent_MakeAvailable(oboe opus)
add_library(ts3audio SHARED audio_line.cpp opus_jni.cpp) add_library(ts3audio SHARED audio_line.cpp opus_jni.cpp)
target_link_libraries(ts3audio PRIVATE oboe::oboe opus log) target_link_libraries(ts3audio PRIVATE oboe opus log)
target_compile_options(ts3audio PRIVATE -Wall -Wextra) target_compile_options(ts3audio PRIVATE -Wall -Wextra)
# Only the JNI entry points are exported; everything else may be dropped.
set_target_properties(ts3audio PROPERTIES CXX_VISIBILITY_PRESET hidden C_VISIBILITY_PRESET hidden)
foreach(lib oboe opus)
target_compile_options(${lib} PRIVATE -ffunction-sections -fdata-sections)
endforeach()
target_link_options(ts3audio PRIVATE -Wl,--gc-sections -Wl,--exclude-libs,ALL)
-2
View File
@@ -6,7 +6,6 @@ activityCompose = "1.13.0"
lifecycle = "2.11.0" lifecycle = "2.11.0"
bouncycastle = "1.86" bouncycastle = "1.86"
ini4j = "0.5.1" ini4j = "0.5.1"
oboe = "1.11.0"
androidsvg = "1.4" androidsvg = "1.4"
[libraries] [libraries]
@@ -20,7 +19,6 @@ androidx-lifecycle-service = { module = "androidx.lifecycle:lifecycle-service",
androidsvg = { module = "com.caverock:androidsvg-aar", version.ref = "androidsvg" } androidsvg = { module = "com.caverock:androidsvg-aar", version.ref = "androidsvg" }
bouncycastle = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncycastle" } bouncycastle = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncycastle" }
ini4j = { module = "org.ini4j:ini4j", version.ref = "ini4j" } ini4j = { module = "org.ini4j:ini4j", version.ref = "ini4j" }
oboe = { module = "com.google.oboe:oboe", version.ref = "oboe" }
[plugins] [plugins]
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }