From 05ea82a903f899e367a830412e438ba9f2b7f6b1 Mon Sep 17 00:00:00 2001 From: Veirt Date: Wed, 11 Dec 2024 23:24:25 +0800 Subject: [PATCH] build: setup apk build --- .github/workflows/build.yaml | 74 +++++++++++++++++++ app/build.gradle.kts | 44 +++++++---- .../main/res/layout/activity_detail_tutor.xml | 9 ++- gradlew | 0 4 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/build.yaml mode change 100644 => 100755 gradlew diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..3e2a2f5 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,74 @@ +name: Build and Release + +on: + push: + branches: + - master + workflow_dispatch: + +permissions: + contents: write + packages: write + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: "zulu" + java-version: "17" + + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: ${{ runner.os }}-gradle- + + - name: Decode and Set Up Keystore + run: | + echo "${{ secrets.KEYSTORE_BASE64_ENCODED }}" | base64 -d > keystore.jks + + - name: Setup keystore.properties + run: | + echo "store.file=keystore.jks" >> keystore.properties + echo "store.password=${{ secrets.KEYSTORE_PASSWORD }}" >> keystore.properties + echo "key.alias=tutortoise" >> keystore.properties + echo "key.password=${{ secrets.KEY_PASSWORD }}" >> keystore.properties + + - name: Setup local.properties + run: | + echo "base.url=${{ secrets.BASE_URL }}" >> local.properties + echo "google.oauth.client.id=${{ secrets.GOOGLE_OAUTH_CLIENT_ID }}" >> local.properties + + - name: Build Release APK + run: ./gradlew assembleRelease + env: + CI: true + + - name: List APK Directory Contents + run: ls -alh app/build/outputs/apk/release/ + + - name: Upload APK as Artifact + uses: actions/upload-artifact@v3 + with: + name: app-release + path: app/build/outputs/apk/release/app-release.apk + + - name: Upload APK to Release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: app/build/outputs/apk/release/app-release.apk + asset_name: app-release.apk + asset_content_type: application/vnd.android.package-archive diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5bd667a..16077e8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -2,6 +2,7 @@ import java.io.FileInputStream import java.util.Properties val localProperties = Properties() + localProperties.load(FileInputStream(rootProject.file("local.properties"))) plugins { @@ -16,6 +17,13 @@ keystoreProperties.load(FileInputStream(rootProject.file("keystore.properties")) android { signingConfigs { + create("release") { + storeFile = file(keystoreProperties.getProperty("store.file")) + storePassword = keystoreProperties.getProperty("store.password") + keyAlias = keystoreProperties.getProperty("key.alias") + keyPassword = keystoreProperties.getProperty("key.password") + } + getByName("debug") { storeFile = file(keystoreProperties.getProperty("store.file")) storePassword = keystoreProperties.getProperty("store.password") @@ -35,30 +43,42 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + val baseUrl = localProperties.getProperty( + "base.url", + System.getenv("BASE_URL") ?: "https://default-url.com/" + ) + val googleOauthClientId = localProperties.getProperty( + "google.oauth.client.id", + System.getenv("GOOGLE_OAUTH_CLIENT_ID") ?: "" + ) + buildConfigField( "String", "BASE_URL", - "\"${localProperties.getProperty("base.url", "https://default-url.com/")}\"" + "\"$baseUrl\"" ) buildConfigField( "String", "GOOGLE_OAUTH_CLIENT_ID", - "\"${localProperties.getProperty("google.oauth.client.id", "")}\"" + "\"$googleOauthClientId\"" ) - signingConfig = signingConfigs.getByName("debug") + multiDexEnabled = true } buildTypes { release { - isMinifyEnabled = true - isShrinkResources = true + isMinifyEnabled = false + isShrinkResources = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) + signingConfig = signingConfigs.getByName("release") } + + debug { signingConfig = signingConfigs.getByName("debug") } } buildFeatures { @@ -71,15 +91,9 @@ android { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = "1.8" - } - buildFeatures { - viewBinding = true - } - viewBinding { - enable = true - } + kotlinOptions { jvmTarget = "1.8" } + buildFeatures { viewBinding = true } + viewBinding { enable = true } } dependencies { @@ -126,4 +140,4 @@ dependencies { implementation(libs.glide) implementation(libs.shimmer.android) implementation(libs.ucrop) -} +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_detail_tutor.xml b/app/src/main/res/layout/activity_detail_tutor.xml index 6b61bbf..eb51e8c 100644 --- a/app/src/main/res/layout/activity_detail_tutor.xml +++ b/app/src/main/res/layout/activity_detail_tutor.xml @@ -272,27 +272,28 @@ android:id="@+id/groupCategory" android:layout_width="match_parent" android:layout_height="wrap_content" - app:layout_constraintStart_toStartOf="@id/tvCategoryLabel" + app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvCategoryLabel"> + android:textSize="14sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> diff --git a/gradlew b/gradlew old mode 100644 new mode 100755