Files
pangolin/client/android/app/build.gradle
T
wangjia b23377acde build(scripts): 各端 libbox 构建脚本修正 + 自动部署产物
排查 Android 打包"libbox.aar not found / Unresolved reference nekohasekai"踩坑:
- scripts/build-libbox.sh:
  · 构建后自动部署产物到工程引用位置(android→app/kernel/dist/android/libbox.aar;
    apple→client/{macos,ios}/Frameworks/Libbox.xcframework),不再留 /tmp 让人手动拷
  · android 自动挑 NDK ≥28(未设 ANDROID_NDK_HOME 时):官方 build_libbox 拉 cronet-go,
    其 libcronet.a 在 NDK 27 lld 链接报 unknown relocation(315)失败
  · 头注释补全前置(NDK≥28 / JDK17 / gomobile 入 PATH)与产物路径
- app/kernel/build-android.sh:补 -javapkg io.nekohasekai —— 缺它产出默认包名 `libbox`,
  与 Kotlin 的 io.nekohasekai.libbox 对不上、APK Kotlin 编译失败
- build.gradle:注释指明两条构建途径 + 包名必须 io.nekohasekai.libbox

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 07:53:35 +08:00

80 lines
2.6 KiB
Groovy
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.pangolin.pangolin_vpn"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.pangolin.pangolin_vpn"
// libbox requires minSdk 21 (gomobile -androidapi 21)
minSdkVersion Math.max(flutter.minSdkVersion as Integer, 21)
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
// ── sing-box libboxgomobile AAR)──────────────────────────────
// 产物(gitignore,清掉/换 worktree 都要重建)二选一,均产 io.nekohasekai.libbox 包:
// bash scripts/build-libbox.sh android # 官方 build_libbox,需 NDK ≥ 28(自动部署到此路径)
// cd app/kernel && ./build-android.sh # 裸 gomobile bind,精简 tag、NDK 27 可
// ⚠️ 包名必须是 io.nekohasekai.libbox(Kotlin import 依赖);若编出默认 `libbox` 包,
// 多半是 build-android.sh 漏了 -javapkg io.nekohasekai。
// 路径:client/android/app → ../../.. → repo root → app/kernel/dist/android/
// Kotlin stdlib 由 kotlin-android 插件自动引入,无需显式声明。
def libboxAar = file("${projectDir}/../../../app/kernel/dist/android/libbox.aar")
if (libboxAar.exists()) {
implementation files(libboxAar)
} else {
logger.warn("⚠ libbox.aar not found at ${libboxAar.absolutePath}")
logger.warn(" Run: cd app/kernel && ./build-android.sh")
}
}