Skip to content

Commit

Permalink
[feature|optimize] Support building multiple APKs per ABI; optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Apr 6, 2024
1 parent 5a927fb commit 274da2a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 31 deletions.
62 changes: 47 additions & 15 deletions .github/workflows/pre_release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Pre-Release

# 触发器
# Trigger
on:
workflow_dispatch:
push:
Expand Down Expand Up @@ -33,46 +33,78 @@ jobs:
uses: actions/checkout@v3
with:
repository: ${{ secrets.SECRET_REPO }}
token: ${{ secrets.TOKEN }} # 连接仓库的Token
token: ${{ secrets.TOKEN }} # Repo token
path: secret
# 准备 secret 文件
# Prepare secret files
- name: Copy Secret Files
run: |
cd secret/Rays-Android
cp key.jks ../..
cp secret.gradle.kts ../..
cp -rf assets ../../app/src/main
# 清理 secret 文件
# Clean secret files
- name: Clean Temp Secret Files
run: |
rm -rf ./secret
# 构建
# Build
- name: Build with Gradle
run: |
bash ./gradlew assembleGitHubRelease
# 上传 apk
- name: Upload Pre-Release Apk
# Upload apk (arm64-v8a)
- name: Upload Pre-Release Apk (arm64-v8a)
uses: actions/upload-artifact@v3
with:
name: Pre-Release Apk
path: app/build/outputs/apk/GitHub/release/*.apk
# 上传 mapping
name: Pre-Release Apk (arm64-v8a)
path: app/build/outputs/apk/GitHub/release/*arm64-v8a*.apk
# Upload apk (armeabi-v7a)
- name: Upload Pre-Release Apk (armeabi-v7a)
uses: actions/upload-artifact@v3
with:
name: Pre-Release Apk (armeabi-v7a)
path: app/build/outputs/apk/GitHub/release/*armeabi-v7a*.apk
# Upload apk (x86_64)
- name: Upload Pre-Release Apk (x86_64)
uses: actions/upload-artifact@v3
with:
name: Pre-Release Apk (x86_64)
path: app/build/outputs/apk/GitHub/release/*x86_64*.apk
# Upload apk (x86)
- name: Upload Pre-Release Apk (x86)
uses: actions/upload-artifact@v3
with:
name: Pre-Release Apk (x86)
path: app/build/outputs/apk/GitHub/release/*x86*.apk
# Upload apk (universal)
- name: Upload Pre-Release Apk (universal)
uses: actions/upload-artifact@v3
with:
name: Pre-Release Apk (universal)
path: app/build/outputs/apk/GitHub/release/*universal*.apk
# Upload mapping
- name: Upload Pre-Release Mapping
uses: actions/upload-artifact@v3
with:
name: Pre-Release Mapping
path: app/build/outputs/mapping/GitHubRelease/mapping.txt
# 获取 apk 路径
# Get apk path
- name: Get Pre-Release Apk File Path
run: |
echo "PRE_RELEASE_APK=$(find app/build/outputs/apk/GitHub/release -name '*.apk' -type f | head -1)" >> $GITHUB_ENV
# 发送至 Telegram 频道
echo "PRE_RELEASE_APK_ARM64_V8=$(find app/build/outputs/apk/GitHub/release -name '*arm64-v8a*.apk' -type f | head -1)" >> $GITHUB_ENV
echo "PRE_RELEASE_APK_ARM_V7=$(find app/build/outputs/apk/GitHub/release -name '*armeabi-v7a*.apk' -type f | head -1)" >> $GITHUB_ENV
echo "PRE_RELEASE_APK_X86_64=$(find app/build/outputs/apk/GitHub/release -name '*x86_64*.apk' -type f | head -1)" >> $GITHUB_ENV
echo "PRE_RELEASE_APK_X86=$(find app/build/outputs/apk/GitHub/release -name '*x86*.apk' -type f | head -1)" >> $GITHUB_ENV
echo "PRE_RELEASE_APK_UNIVERSAL=$(find app/build/outputs/apk/GitHub/release -name '*universal*.apk' -type f | head -1)" >> $GITHUB_ENV
# Send to Telegram
- name: Post to Telegram Channel
if: github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[skip_post]') == false
env:
CHANNEL_ID: ${{ secrets.TELEGRAM_TO }}
BOT_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
PRE_RELEASE: ${{ env.PRE_RELEASE_APK }}
PRE_RELEASE_ARM64_V8: ${{ env.PRE_RELEASE_APK_ARM64_V8 }}
PRE_RELEASE_ARM_V7: ${{ env.PRE_RELEASE_APK_ARM_V7 }}
PRE_RELEASE_X86_64: ${{ env.PRE_RELEASE_APK_X86_64 }}
PRE_RELEASE_X86: ${{ env.PRE_RELEASE_APK_X86 }}
PRE_RELEASE_UNIVERSAL: ${{ env.PRE_RELEASE_APK_UNIVERSAL }}
COMMIT_MESSAGE: |+
GitHub New CI: Rays\
Expand All @@ -83,4 +115,4 @@ jobs:
Commit details [here](${{ github.event.head_commit.url }})
run: |
ESCAPED=`python3 -c 'import json,os,urllib.parse; print(urllib.parse.quote(json.dumps(os.environ["COMMIT_MESSAGE"])))'`
curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${CHANNEL_ID}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2Fpre_release%22%2C%22parse_mode%22%3A%22MarkdownV2%22%2C%22caption%22%3A${ESCAPED}%7D%5D" -F pre_release="@$PRE_RELEASE"
curl -v "https://api.telegram.org/bot${BOT_TOKEN}/sendMediaGroup?chat_id=${CHANNEL_ID}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2Fpre_release_arm64_v8%22%2C%22parse_mode%22%3A%22MarkdownV2%22%2C%22caption%22%3A${ESCAPED}%7D%5D" -F pre_release_arm64_v8="@$PRE_RELEASE_ARM64_V8"
30 changes: 20 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.android.build.api.variant.FilterConfiguration
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -21,7 +22,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 62
versionName = "2.2-alpha08"
versionName = "2.2-alpha09"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -52,11 +53,27 @@ android {
}
}

splits {
abi {
// Enables building multiple APKs per ABI.
isEnable = true
// By default all ABIs are included, so use reset() and include().
// Resets the list of ABIs for Gradle to create APKs for to none.
reset()
// A list of ABIs for Gradle to create APKs for.
include("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
// We want to also generate a universal APK that includes all ABIs.
isUniversalApk = true
}
}

applicationVariants.all {
outputs
.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl }
.forEach {
it.outputFileName = "Rays_${versionName}_${buildType.name}_${flavorName}.apk"
.forEach { output ->
val abi = output.getFilter(FilterConfiguration.FilterType.ABI.name) ?: "universal"
output.outputFileName =
"Rays_${versionName}_${abi}_${buildType.name}_${flavorName}.apk"
}
}

Expand All @@ -69,9 +86,6 @@ android {
"proguard-rules.pro"
)
applicationIdSuffix = ".debug"
ndk {
abiFilters += mutableSetOf("armeabi", "x86", "x86_64", "arm64-v8a")
}
}
release {
signingConfig = signingConfigs.getByName("release") // signing
Expand All @@ -81,10 +95,6 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
ndk {
//noinspection ChromeOsAbiSupport
abiFilters += "arm64-v8a"
}
}
}
compileOptions {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/skyd/rays/model/bean/UpdateBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ data class UpdateBean(
var tagName: String,
@SerialName("name")
var name: String,
@SerialName("html_url")
var htmlUrl: String,
@SerialName("published_at")
var publishedAt: String,
@SerialName("assets")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fun UpdateDialog(
},
onDownloadClick = { updateBean ->
dispatch(
UpdateIntent.Update(updateBean?.assets?.firstOrNull()?.browserDownloadUrl)
UpdateIntent.Update(updateBean?.htmlUrl)
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.skyd.rays.base.mvi.AbstractMviViewModel
import com.skyd.rays.config.GITHUB_REPO
import com.skyd.rays.ext.catchMap
import com.skyd.rays.ext.startWith
import com.skyd.rays.ext.toDateTimeString
import com.skyd.rays.model.respository.UpdateRepository
import com.skyd.rays.util.CommonUtil.getAppVersionCode
import com.skyd.rays.util.CommonUtil.openBrowser
Expand Down Expand Up @@ -80,11 +81,7 @@ class UpdateViewModel @Inject constructor(private var updateRepo: UpdateReposito
).apply {
timeZone = TimeZone.getTimeZone("UTC")
}.parse(data.publishedAt)
val publishedAt: String = if (date != null) {
SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(date)
} else {
data.publishedAt
}
val publishedAt: String = date?.toDateTimeString() ?: data.publishedAt

UpdatePartialStateChange.CheckUpdate.HasUpdate(
data.copy(publishedAt = publishedAt)
Expand Down

0 comments on commit 274da2a

Please sign in to comment.