1. 新增 OtaManager.java:實現背景下載 APK 檔案至應用程式私有快取空間,並透過 Root 權限 (su 與 pm install -r) 進行靜默覆蓋安裝的完整邏輯。 2. 修改 MqttService.java:支援 update_app MQTT 指令,解析 payload 中的 url 參數並啟動 OtaManager 進行 OTA 更新。 3. 修改 app/build.gradle:實作雙版號動態計算機制,定義 verMajor、verMinor、verPatch,以符合實體機台的 OTA 覆蓋安裝規範。 4. 新增 .agents/rules/versioning.md:制訂專案版號與發版規範。 5. 修改 .agents/workflows/compiler-apk.md:調整編譯工作流,在編譯前自動檢查程式碼變更與遞增版號,並支援動態尋找編譯產出的最新 APK。 6. 修改 .gitignore:排除 .antigravitycli/ 工具產生的目錄。 7. 修改 .vscode/settings.json:設定自動更新 Java 的建置組態。
101 lines
3.1 KiB
Groovy
101 lines
3.1 KiB
Groovy
plugins {
|
||
alias(libs.plugins.android.application)
|
||
}
|
||
|
||
// =========================================================================
|
||
// 核心版號與自動連動定義
|
||
// 每次發佈新版本給機台時,只需遞增 verPatch (修補版號)。
|
||
// 例如:從 5 改為 6,對應的 versionName 就會自動變成 "10_08_6_R",
|
||
// versionCode 就會自動變大為 100806,以正確觸發實體機台的 OTA 自動更新。
|
||
// =========================================================================
|
||
def verMajor = 10
|
||
def verMinor = 8
|
||
def verPatch = 6
|
||
|
||
android {
|
||
namespace 'com.unibuy.smartdevice'
|
||
compileSdk 35
|
||
|
||
defaultConfig {
|
||
applicationId "com.unibuy.smartdevice"
|
||
minSdk 21
|
||
targetSdk 34
|
||
versionCode verMajor * 10000 + verMinor * 100 + verPatch
|
||
versionName "${verMajor}_0${verMinor}_${verPatch}_R"
|
||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||
}
|
||
|
||
// 設定不同場域
|
||
flavorDimensions "app_type"
|
||
|
||
productFlavors {
|
||
S_12_XY_U_Standard_ {
|
||
dimension "app_type"
|
||
versionCode verMajor * 10000 + verMinor * 100 + verPatch
|
||
versionName "${verMajor}_0${verMinor}_${verPatch}_R"
|
||
}
|
||
}
|
||
|
||
buildTypes {
|
||
release {
|
||
minifyEnabled false
|
||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||
signingConfig signingConfigs.debug
|
||
}
|
||
}
|
||
|
||
// 自定義打包檔案名稱,包含版本號
|
||
applicationVariants.all { variant ->
|
||
variant.outputs.each { output ->
|
||
def versionCode = variant.versionCode
|
||
def versionName = variant.versionName
|
||
def flavor = variant.productFlavors[0].name
|
||
def buildType = variant.buildType.name
|
||
|
||
// 設定打包檔案名稱:app-<flavor>-<versionName>-<buildType>.apk
|
||
output.outputFileName = "app-${flavor}-${versionName}-${buildType}.apk"
|
||
}
|
||
}
|
||
|
||
compileOptions {
|
||
sourceCompatibility JavaVersion.VERSION_11
|
||
targetCompatibility JavaVersion.VERSION_11
|
||
}
|
||
|
||
buildFeatures {
|
||
viewBinding true
|
||
}
|
||
|
||
packaging {
|
||
resources {
|
||
excludes += ['META-INF/INDEX.LIST', 'META-INF/io.netty.versions.properties']
|
||
}
|
||
}
|
||
}
|
||
|
||
dependencies {
|
||
implementation libs.appcompat
|
||
implementation libs.material
|
||
implementation libs.activity
|
||
implementation libs.constraintlayout
|
||
implementation libs.work.runtime
|
||
testImplementation libs.junit
|
||
androidTestImplementation libs.ext.junit
|
||
androidTestImplementation libs.espresso.core
|
||
|
||
annotationProcessor libs.compiler
|
||
implementation libs.usb.serial.for.android
|
||
implementation libs.android.serialport
|
||
implementation libs.glide
|
||
implementation libs.media3.exoplayer
|
||
implementation libs.media3.ui
|
||
implementation libs.tsnackBar
|
||
|
||
implementation 'com.blankj:utilcodex:1.31.1'
|
||
implementation 'com.hivemq:hivemq-mqtt-client:1.3.3'
|
||
implementation 'io.netty:netty-codec-http:4.1.94.Final'
|
||
implementation 'io.netty:netty-handler:4.1.94.Final'
|
||
implementation 'com.google.code.gson:gson:2.10.1'
|
||
}
|