根因(极米 H1S / MStar 6A928 / GMUI2.0 / Android 5.1.1):
- MainActivity 把 API 23 才有的 android.media.AudioDeviceCallback 写成了
**字段初始化器**(private val micDeviceCallback = object : ...)。
字段初始化在 Activity 构造期执行,早于 onCreate 里的 SDK_INT 判断,
于是下面的 registerMicInputWatcher() 版本守卫形同虚设 ——
构造 MainActivity 即抛 NoClassDefFoundError,表现为一打开就闪退。
- 顺带修复 36 处同类未守卫的高版本 API 调用(lint NewApi 全量清零):
* AudioDeviceCallback / AudioDeviceInfo.isSource/getType (API 23)
→ 改为可空字段 + 仅在 SDK_INT>=23 分支按需创建(@TargetApi)
* HashMap.putIfAbsent ×5 (API 24) → MutableMap.getOrPut
* Comparator.comparing ×3 + comparingInt ×1 (API 24) → Kotlin compareBy
(同时移除 java.util.function 导入)
* ConcurrentHashMap.newKeySet ×2 (API 24) → Collections.newSetFromMap
(连带 16 处 KeySetView.add/remove/contains)
* ConcurrentHashMap.computeIfAbsent (API 24) → ConcurrentHashMap.putIfAbsent(API 1)
* URLConnection.getContentLengthLong ×5 (API 24) → 新增 Compat.contentLengthCompat()
* ByteArrayOutputStream.toString(Charset) (API 33) → String(bytes, UTF_8)
防回归:
- app/build.gradle 打开 lint 闸门: checkReleaseBuilds true + abortOnError true +
fatal += NewApi(并 disable ExpiredTargetSdkVersion,避免它挤占闸门)。
已实测: 植入一个 NewApi 违规后 assembleRelease 直接 FAILED。
- AGENTS.md 新增「低版本设备闪退(API 守卫)」条目,记录根因、替代写法与自查命令。
版本号 1.4.0(16) → 1.4.1(17);签名证书不变,可覆盖安装。
105 lines
3.6 KiB
Groovy
105 lines
3.6 KiB
Groovy
plugins {
|
|
id "com.android.application"
|
|
id "org.jetbrains.kotlin.android"
|
|
}
|
|
|
|
android {
|
|
namespace "com.local.ktv"
|
|
compileSdk 35
|
|
|
|
defaultConfig {
|
|
applicationId "com.local.ktv"
|
|
minSdk 21
|
|
targetSdk 25
|
|
versionCode 17
|
|
versionName "1.4.1"
|
|
ndk {
|
|
// 双 ABI 打包:兼容 64 位(Exynos 1580 等 arm64-v8a)与 32 位设备(极米 Play 超越版
|
|
// 的 Amlogic 950X2/S905X2 采用 32 位 Android 用户态,必须包含 armeabi-v7a,否则
|
|
// 会出现 INSTALL_FAILED_NO_MATCHING_ABIS 安装失败)。
|
|
// Package each ABI's complete IJK set; never mix individual SOs across the two sets.
|
|
abiFilters "armeabi-v7a", "arm64-v8a"
|
|
}
|
|
// 曲库已改为官方 Muse 同步(database_publish 不再发布到 Gitee),
|
|
// 不再需要 GITEE_DATABASE_* 构建参数。
|
|
}
|
|
|
|
// 签名配置:使用已有的 ktv_keystore.jks
|
|
signingConfigs {
|
|
release {
|
|
storeFile file("../../ktv_keystore.jks")
|
|
storePassword "123456"
|
|
keyAlias "ktv"
|
|
keyPassword "123456"
|
|
}
|
|
}
|
|
|
|
buildTypes {
|
|
release {
|
|
minifyEnabled true
|
|
shrinkResources true
|
|
signingConfig signingConfigs.release
|
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
}
|
|
debug {
|
|
debuggable true
|
|
applicationIdSuffix ".qa"
|
|
}
|
|
}
|
|
|
|
// 支持 .ts 视频文件(aapt 不压缩这些文件以避免 SoundPool/MediaPlayer 问题)
|
|
androidResources {
|
|
noCompress 'ts', 'mp3', 'mp4', 'aac', 'm4a', 'flac', 'wav'
|
|
}
|
|
|
|
// lint 策略:
|
|
// - 「调用了高于 minSdk 且未做版本守卫的 API」(NewApi) 必须**阻断发布构建**:
|
|
// 这类问题在 Android 5.x / 6.x 上直接 NoSuchMethodError / NoClassDefFoundError 闪退,
|
|
// 而本地打包测试用的都是较新设备, 极容易漏出去(v1.4.0 在极米 H1S / Android 5.1.1
|
|
// 一打开就闪退, 根因就是 AudioDeviceCallback(API 23) 被写进了 Activity 的字段初始化器)。
|
|
// - ExpiredTargetSdkVersion 默认也是 fatal 级, 但本地分发的 APK 不上架 Google Play,
|
|
// 显式关掉, 否则会挤占下面这道闸门。
|
|
// - abortOnError 必须为 true: 设为 false 会把 lintVital 的失败一并吞掉, 闸门会失效。
|
|
lint {
|
|
fatal += ['NewApi']
|
|
disable += ['ExpiredTargetSdkVersion']
|
|
checkReleaseBuilds true
|
|
abortOnError true
|
|
}
|
|
|
|
// 启用 BuildConfig 生成,供 AboutFragment 读取版本号/版本Code等信息
|
|
buildFeatures {
|
|
buildConfig = true
|
|
}
|
|
|
|
compileOptions {
|
|
sourceCompatibility = JavaVersion.VERSION_17
|
|
targetCompatibility = JavaVersion.VERSION_17
|
|
}
|
|
|
|
kotlinOptions {
|
|
jvmTarget = "17"
|
|
}
|
|
|
|
}
|
|
|
|
// 强制统一 Kotlin 标准库版本,避免 appcompat 与其他依赖的版本冲突
|
|
configurations.all {
|
|
resolutionStrategy {
|
|
force "org.jetbrains.kotlin:kotlin-stdlib:1.8.22"
|
|
force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22"
|
|
force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22"
|
|
force "org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22"
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
implementation files('libs/original-ijk-runtime.jar')
|
|
implementation "androidx.core:core:1.12.0"
|
|
implementation "androidx.appcompat:appcompat:1.6.1"
|
|
implementation "com.google.zxing:core:3.5.3"
|
|
implementation "com.liulishuo.okdownload:okdownload:1.0.7"
|
|
testImplementation "junit:junit:4.13.2"
|
|
|
|
}
|