Skip to content

Commit a533e1e

Browse files
committed
添加CI配置
1 parent 48e96a3 commit a533e1e

File tree

5 files changed

+96
-33
lines changed

5 files changed

+96
-33
lines changed

.github/workflows/android.yml

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,43 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v3
16-
- name: set up JDK 11
17-
uses: actions/setup-java@v3
18-
with:
19-
java-version: '11'
20-
distribution: 'temurin'
21-
cache: gradle
15+
- uses: actions/checkout@v3
16+
- name: set up JDK 11
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '11'
20+
distribution: 'temurin'
21+
cache: gradle
2222

23-
- name: Grant execute permission for gradlew
24-
run: chmod +x gradlew
25-
- name: Build with Gradle
26-
run: ./gradlew build
23+
- name: Grant execute permission for gradlew
24+
run: chmod +x gradlew
25+
- name: Build with Gradle
26+
run: ./gradlew build
27+
- name: Packing Release
28+
run: ./gradlew assembleRelease
29+
30+
# 创建realease
31+
- name: Create Release
32+
id: create_release
33+
uses: actions/create-release@v1
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
with:
37+
tag_name: ${{ github.ref }}
38+
release_name: Release ${{ github.ref }}
39+
draft: false
40+
prerelease: false
41+
42+
# 上传apk到release
43+
- name: Upload Release Asset
44+
id: upload-release-asset
45+
uses: actions/upload-release-asset@v1
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
with:
49+
# This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`.
50+
# See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
51+
upload_url: ${{ steps.create_release.outputs.upload_url }}
52+
asset_path: app/build/outputs/apk/release/app-release.apk
53+
asset_name: App.apk
54+
asset_content_type: application/vnd.android.package-archiv

app/build.gradle

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ plugins {
33
id 'org.jetbrains.kotlin.android'
44
}
55

6+
/*加载Key*/
7+
def keystorePropertiesFile = rootProject.file("keystore.properties")
8+
def keystoreProperties = new Properties()
9+
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
10+
11+
612
android {
713
namespace 'com.phcbest.designpatterns'
814
compileSdk 33
@@ -11,14 +17,54 @@ android {
1117
applicationId "com.phcbest.designpatterns"
1218
minSdk 26
1319
targetSdk 33
14-
versionCode 1
15-
versionName "1.0"
20+
versionCode VERSION_CODE as int
21+
versionName VERSION_NAME as String
1622

1723
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1824
}
1925

26+
signingConfigs {
27+
config {
28+
keyAlias keystoreProperties['keyAlias']
29+
keyPassword keystoreProperties['keyPassword']
30+
storeFile file(keystoreProperties['storeFile'])
31+
storePassword keystoreProperties['storePassword']
32+
}
33+
}
34+
35+
// 配置输出路径和文件名
36+
//修改输出的APK路径
37+
applicationVariants.all { variant ->
38+
// 打包完成后复制到的目录
39+
def outputFileDir = "${project.projectDir.absolutePath}/${variant.buildType.name}/${variant.versionName}"
40+
//确定输出文件名
41+
def today = new Date()
42+
def path = ((project.name != "app") ? project.name : rootProject.name.replace(" ", "")) + "_" +
43+
variant.flavorName + "_" +
44+
variant.buildType.name + "_" +
45+
variant.versionName + "_" +
46+
today.format('yyyyMMddhhmm') +
47+
".apk"
48+
variant.outputs.forEach {
49+
it.outputFileName = path
50+
}
51+
// 打包完成后做的一些事,复制apk到指定文件夹
52+
variant.assemble.doLast {
53+
File out = new File(outputFileDir)
54+
copy {
55+
variant.outputs.forEach { file ->
56+
copy {
57+
from file.outputFile
58+
into out
59+
}
60+
}
61+
}
62+
}
63+
}
64+
2065
buildTypes {
2166
release {
67+
signingConfig signingConfigs.config //配置签名文件
2268
minifyEnabled false
2369
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2470
}

gradle.properties

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
# Project-wide Gradle settings.
2-
# IDE (e.g. Android Studio) users:
3-
# Gradle settings configured through the IDE *will override*
4-
# any settings specified in this file.
5-
# For more details on how to configure your build environment visit
6-
# http://www.gradle.org/docs/current/userguide/build_environment.html
7-
# Specifies the JVM arguments used for the daemon process.
8-
# The setting is particularly useful for tweaking memory settings.
1+
###################################################################################################
92
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10-
# When configured, Gradle will run in incubating parallel mode.
11-
# This option should only be used with decoupled projects. More details, visit
12-
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13-
# org.gradle.parallel=true
14-
# AndroidX package structure to make it clearer which packages are bundled with the
15-
# Android operating system, and which are packaged with your app's APK
16-
# https://developer.android.com/topic/libraries/support-library/androidx-rn
173
android.useAndroidX=true
18-
# Kotlin code style for this project: "official" or "obsolete":
194
kotlin.code.style=official
20-
# Enables namespacing of each library's R class so that its R class includes only the
21-
# resources declared in the library itself and none from the library's dependencies,
22-
# thereby reducing the size of the R class for that library
23-
android.nonTransitiveRClass=true
5+
android.nonTransitiveRClass=true
6+
###################################################################################################
7+
VERSION_CODE = 1
8+
VERSION_NAME = 1.0.0

keystore.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
storePassword=123456
2+
keyPassword=123456
3+
keyAlias=app
4+
storeFile=../keystore/app.jks

keystore/app.jks

2.42 KB
Binary file not shown.

0 commit comments

Comments
 (0)