Compare commits
3
Commits
v1.2.2
...
ac59cf842c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac59cf842c | ||
|
|
df9eb548cb | ||
|
|
253f3c72b1 |
No files matched your search
@@ -1,76 +0,0 @@
|
|||||||
name: Release OpenLoc APKs
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build & Publish Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout Code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up JDK 21
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
distribution: 'temurin'
|
|
||||||
java-version: '21'
|
|
||||||
cache: 'gradle'
|
|
||||||
|
|
||||||
- name: Grant Execute Permission for Gradlew
|
|
||||||
run: chmod +x gradlew
|
|
||||||
|
|
||||||
- name: Restore Keystore from Secrets (If Configured)
|
|
||||||
env:
|
|
||||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
|
||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
|
||||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
|
||||||
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
if [ -n "$KEYSTORE_BASE64" ]; then
|
|
||||||
echo "Restoring official keystore..."
|
|
||||||
echo "$KEYSTORE_BASE64" | base64 -d > app/openloc.jks
|
|
||||||
cat <<EOF > keystore.properties
|
|
||||||
storeFile=openloc.jks
|
|
||||||
storePassword=${KEYSTORE_PASSWORD}
|
|
||||||
keyAlias=${KEY_ALIAS}
|
|
||||||
keyPassword=${KEY_PASSWORD}
|
|
||||||
EOF
|
|
||||||
else
|
|
||||||
echo "No custom keystore secret provided, fallback signing will be used."
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Run Tests & Build Release APKs
|
|
||||||
run: ./gradlew testDebugUnitTest assembleRelease --stacktrace
|
|
||||||
|
|
||||||
- name: Prepare Architecture Assets
|
|
||||||
run: |
|
|
||||||
TAG_NAME="${GITHUB_REF_NAME:-latest}"
|
|
||||||
cd app/build/outputs/apk/release/
|
|
||||||
cp app-universal-release.apk "OpenLoc-${TAG_NAME}-universal.apk"
|
|
||||||
cp app-arm64-v8a-release.apk "OpenLoc-${TAG_NAME}-arm64-v8a.apk"
|
|
||||||
cp app-armeabi-v7a-release.apk "OpenLoc-${TAG_NAME}-armeabi-v7a.apk"
|
|
||||||
cp app-x86_64-release.apk "OpenLoc-${TAG_NAME}-x86_64.apk"
|
|
||||||
cp app-x86-release.apk "OpenLoc-${TAG_NAME}-x86.apk"
|
|
||||||
ls -la OpenLoc-*.apk
|
|
||||||
|
|
||||||
- name: Publish GitHub Release & Upload Assets
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-universal.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-arm64-v8a.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-armeabi-v7a.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-x86_64.apk
|
|
||||||
app/build/outputs/apk/release/OpenLoc-*-x86.apk
|
|
||||||
generate_release_notes: true
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@@ -18,8 +18,8 @@ android {
|
|||||||
applicationId = "com.lzxnone.openloc"
|
applicationId = "com.lzxnone.openloc"
|
||||||
minSdk = 28
|
minSdk = 28
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 5
|
versionCode = 7
|
||||||
versionName = "1.2.2"
|
versionName = "1.2.4"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,8 @@ android {
|
|||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
isMinifyEnabled = false
|
isMinifyEnabled = true
|
||||||
|
isShrinkResources = true
|
||||||
signingConfig = signingConfigs.getByName("release")
|
signingConfig = signingConfigs.getByName("release")
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
|
|||||||
Vendored
+22
-18
@@ -1,21 +1,25 @@
|
|||||||
# Add project specific ProGuard rules here.
|
# 仅代码裁剪(Tree Shaking),完全禁用重命名混淆
|
||||||
# You can control the set of applied configuration files using the
|
-dontobfuscate
|
||||||
# proguardFiles setting in build.gradle.
|
-dontoptimize
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
# 保留调试堆栈信息与注解签名
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
-keepattributes SourceFile,LineNumberTable,InnerClasses,EnclosingMethod,Exceptions,Signature
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
# 保持 Android 基础组件(Activity, Provider 等)
|
||||||
# debugging stack traces.
|
-keep public class * extends android.app.Activity
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
-keep public class * extends android.app.Application
|
||||||
|
-keep public class * extends android.app.Service
|
||||||
|
-keep public class * extends android.content.BroadcastReceiver
|
||||||
|
-keep public class * extends android.content.ContentProvider
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
# 保持 Xposed / LSPosed 钩子入口及所有 Hook 类(在目标进程反射加载)
|
||||||
# hide the original source file name.
|
-keep class com.lzxnone.openloc.hook.** { *; }
|
||||||
#-renamesourcefileattribute SourceFile
|
|
||||||
|
# 保持数据模型与配置实体
|
||||||
|
-keep class com.lzxnone.openloc.data.model.** { *; }
|
||||||
|
-keep class com.lzxnone.openloc.hook.model.** { *; }
|
||||||
|
-keep class com.lzxnone.openloc.core.provider.** { *; }
|
||||||
|
|
||||||
|
# 保持 osmdroid 地图库必须的反射类与组件
|
||||||
|
-keep class org.osmdroid.** { *; }
|
||||||
|
-dontwarn org.osmdroid.**
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
package com.lzxnone.openloc.core.util
|
package com.lzxnone.openloc.core.util
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import com.lzxnone.openloc.BuildConfig
|
import com.lzxnone.openloc.BuildConfig
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 版本更新信息
|
* 版本更新信息
|
||||||
@@ -20,14 +23,14 @@ data class UpdateInfo(
|
|||||||
val apkSize: String = ""
|
val apkSize: String = ""
|
||||||
) {
|
) {
|
||||||
val hasUpdate: Boolean
|
val hasUpdate: Boolean
|
||||||
get() = versionCode > BuildConfig.VERSION_CODE
|
get() = UpdateChecker.isNewerVersion(versionName, BuildConfig.VERSION_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VPS 节点自建版本更新检查器
|
* Gitea Releases 版本更新检查器
|
||||||
*/
|
*/
|
||||||
object UpdateChecker {
|
object UpdateChecker {
|
||||||
private const val UPDATE_URL = "https://update.lzxnone.cloud/openloc/version.json"
|
private const val UPDATE_URL = "https://gitea.lzxnone.cloud/api/v1/repos/lzxnone/OpenLoc/releases/latest"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查是否有新版本
|
* 检查是否有新版本
|
||||||
@@ -49,22 +52,7 @@ object UpdateChecker {
|
|||||||
val response = reader.use { it.readText() }
|
val response = reader.use { it.readText() }
|
||||||
connection.disconnect()
|
connection.disconnect()
|
||||||
|
|
||||||
val json = JSONObject(response)
|
Result.success(parseReleaseJson(response))
|
||||||
val versionCode = json.optLong("versionCode", 0L)
|
|
||||||
val versionName = json.optString("versionName", "")
|
|
||||||
val changelog = json.optString("changelog", "")
|
|
||||||
val downloadUrl = json.optString("downloadUrl", "")
|
|
||||||
val apkSize = json.optString("apkSize", "")
|
|
||||||
|
|
||||||
Result.success(
|
|
||||||
UpdateInfo(
|
|
||||||
versionCode = versionCode,
|
|
||||||
versionName = versionName,
|
|
||||||
changelog = changelog,
|
|
||||||
downloadUrl = downloadUrl,
|
|
||||||
apkSize = apkSize
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
connection.disconnect()
|
connection.disconnect()
|
||||||
Result.failure(Exception("HTTP error $responseCode"))
|
Result.failure(Exception("HTTP error $responseCode"))
|
||||||
@@ -73,4 +61,102 @@ object UpdateChecker {
|
|||||||
Result.failure(e)
|
Result.failure(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun parseReleaseJson(
|
||||||
|
response: String,
|
||||||
|
supportedAbis: Array<String> = Build.SUPPORTED_ABIS ?: emptyArray()
|
||||||
|
): UpdateInfo {
|
||||||
|
val json = JSONObject(response)
|
||||||
|
val rawTag = json.optString("tag_name", "").trim()
|
||||||
|
val versionName = rawTag.removePrefix("v").removePrefix("V")
|
||||||
|
val versionCode = parseVersionCode(versionName)
|
||||||
|
val changelog = json.optString("body", "").ifBlank {
|
||||||
|
json.optString("name", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
val (downloadUrl, apkSize) = selectApkAsset(
|
||||||
|
assets = json.optJSONArray("assets"),
|
||||||
|
supportedAbis = supportedAbis,
|
||||||
|
fallbackUrl = json.optString("html_url", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
return UpdateInfo(
|
||||||
|
versionCode = versionCode,
|
||||||
|
versionName = versionName,
|
||||||
|
changelog = changelog,
|
||||||
|
downloadUrl = downloadUrl,
|
||||||
|
apkSize = apkSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selectApkAsset(
|
||||||
|
assets: JSONArray?,
|
||||||
|
supportedAbis: Array<String>,
|
||||||
|
fallbackUrl: String
|
||||||
|
): Pair<String, String> {
|
||||||
|
if (assets == null || assets.length() == 0) {
|
||||||
|
return fallbackUrl to ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val apkAssets = buildList {
|
||||||
|
for (i in 0 until assets.length()) {
|
||||||
|
val asset = assets.optJSONObject(i) ?: continue
|
||||||
|
val name = asset.optString("name", "")
|
||||||
|
val downloadUrl = asset.optString("browser_download_url", "")
|
||||||
|
val size = asset.optLong("size", 0L)
|
||||||
|
if (name.endsWith(".apk", ignoreCase = true) && downloadUrl.isNotBlank()) {
|
||||||
|
add(Triple(name, downloadUrl, size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apkAssets.isEmpty()) {
|
||||||
|
return fallbackUrl to ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val matched = supportedAbis.firstNotNullOfOrNull { abi ->
|
||||||
|
apkAssets.firstOrNull { (name, _, _) ->
|
||||||
|
name.contains(abi, ignoreCase = true)
|
||||||
|
}
|
||||||
|
} ?: apkAssets.firstOrNull { (name, _, _) ->
|
||||||
|
name.contains("universal", ignoreCase = true)
|
||||||
|
} ?: apkAssets.first()
|
||||||
|
|
||||||
|
val sizeText = if (matched.third > 0L) {
|
||||||
|
String.format(Locale.US, "%.2f MB", matched.third / (1024.0 * 1024.0))
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
return matched.second to sizeText
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun isNewerVersion(remoteVersion: String, currentVersion: String): Boolean {
|
||||||
|
val remoteParts = parseVersionParts(remoteVersion)
|
||||||
|
val currentParts = parseVersionParts(currentVersion)
|
||||||
|
if (remoteParts.isEmpty()) return false
|
||||||
|
|
||||||
|
val maxLen = maxOf(remoteParts.size, currentParts.size)
|
||||||
|
for (i in 0 until maxLen) {
|
||||||
|
val r = remoteParts.getOrElse(i) { 0 }
|
||||||
|
val c = currentParts.getOrElse(i) { 0 }
|
||||||
|
if (r != c) return r > c
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun parseVersionCode(versionName: String): Long {
|
||||||
|
val parts = parseVersionParts(versionName)
|
||||||
|
if (parts.isEmpty()) return 0L
|
||||||
|
val major = parts.getOrElse(0) { 0 }
|
||||||
|
val minor = parts.getOrElse(1) { 0 }
|
||||||
|
val patch = parts.getOrElse(2) { 0 }
|
||||||
|
return major * 10000L + minor * 100L + patch
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseVersionParts(version: String): List<Int> {
|
||||||
|
val cleaned = version.trim().removePrefix("v").removePrefix("V")
|
||||||
|
if (cleaned.isBlank()) return emptyList()
|
||||||
|
return cleaned.split(".")
|
||||||
|
.map { segment -> segment.takeWhile { it.isDigit() }.toIntOrNull() ?: 0 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user