Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working android ci #281

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true
APP_NAME: "shockwallet"

jobs:
build:
Expand All @@ -35,11 +34,19 @@ jobs:

- name: Set up environment for test
if: github.ref == 'refs/heads/test'
run: cp .env.development.example .env
run: |
cp .env.development.example .env
source .env
echo "VITE_APP_NAME=$VITE_APP_NAME" >> $GITHUB_ENV
echo "VITE_ANDROID_APPLICATION_ID=$VITE_ANDROID_APPLICATION_ID" >> $GITHUB_ENV

- name: Set up environment for main
if: github.ref == 'refs/heads/main'
run: cp .env.production.example .env
run: |
cp .env.production.example .env
source .env
echo "VITE_APP_NAME=$VITE_APP_NAME" >> $GITHUB_ENV
echo "VITE_ANDROID_APPLICATION_ID=$VITE_ANDROID_APPLICATION_ID" >> $GITHUB_ENV

- name: Set VERSION and VERSION_CODE
run: |
Expand Down Expand Up @@ -84,7 +91,7 @@ jobs:
- name: Build with Gradle
run: |
cd android
./gradlew assembleRelease
./gradlew assembleRelease -PversionCode=${{ env.VERSION_CODE }} -PversionName=${{ env.VERSION }} -PappName="${{ env.VITE_APP_NAME }}" -PapplicationId="${{ env.VITE_ANDROID_APPLICATION_ID }}"

- name: Set up Android SDK
uses: android-actions/setup-android@v3
Expand Down Expand Up @@ -133,12 +140,12 @@ jobs:

- name: Sign APK
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner sign --ks my-release-key.keystore --ks-pass pass:${{ secrets.ANDROID_KEYSTORE_PASSWORD }} --key-pass pass:${{ secrets.ANDROID_KEY_PASSWORD }} --out android/app/build/outputs/apk/release/${{ env.APP_NAME }}-${{ env.VERSION }}.apk android/app/build/outputs/apk/release/app-release-unsigned.apk
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner sign --ks my-release-key.keystore --ks-pass pass:${{ secrets.ANDROID_KEYSTORE_PASSWORD }} --key-pass pass:${{ secrets.ANDROID_KEY_PASSWORD }} --out android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk android/app/build/outputs/apk/release/app-release-unsigned.apk
shell: bash

- name: Verify APK
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner verify android/app/build/outputs/apk/release/${{ env.APP_NAME }}-${{ env.VERSION }}.apk
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner verify android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
shell: bash

- name: Upload APK to GitHub Release
Expand All @@ -148,13 +155,13 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: android/app/build/outputs/apk/release/${{ env.APP_NAME }}-${{ env.VERSION }}.apk
asset_name: ${{ env.APP_NAME }}-${{ env.VERSION }}.apk
asset_path: android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
asset_name: ${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
asset_content_type: application/vnd.android.package-archive

- name: Upload APK as artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v3
with:
name: app-release
path: android/app/build/outputs/apk/release/${{ env.APP_NAME }}-${{ env.VERSION }}.apk
path: android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
12 changes: 5 additions & 7 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
apply plugin: 'com.android.application'

android {
namespace "app.shockwallet.test"
namespace "${applicationId}"
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "app.shockwallet.test"
applicationId "${applicationId}"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 1
versionName project.hasProperty('versionName') ? project.property('versionName') : "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
resValue "string", "app_name", "gradle default" // This will be replaced by the preBuild script
resValue "string", "app_name", project.hasProperty('appName') ? project.property('appName') : "Default App Name"
}
buildTypes {
release {
Expand Down
67 changes: 0 additions & 67 deletions preBuild/AndroidManifest.copy.xml

This file was deleted.

31 changes: 17 additions & 14 deletions preBuild/preBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,16 @@ function updateBuildGradle(version, versionCode, applicationId, appName) {
`applicationId "${applicationId}"`
);

buildGradle = buildGradle.replace(
/versionCode \d+/,
`versionCode ${versionCode}`
);

buildGradle = buildGradle.replace(
/versionName "[^"]+"/,
`versionName "${version}"`
);

buildGradle = buildGradle.replace(
/namespace "[^"]+"/,
`namespace "${applicationId}"`
);

buildGradle = buildGradle.replace(
/resValue "string", "app_name", "[^"]+"/,
`resValue "string", "app_name", "${appName}"`
);
// Remove this replacement as we'll use project properties instead
// buildGradle = buildGradle.replace(
// /resValue "string", "app_name", "[^"]+"/,
// `resValue "string", "app_name", "${appName}"`
// );

fs.writeFileSync(buildGradlePath, buildGradle);
}
Expand All @@ -67,6 +58,18 @@ const version = process.env.VERSION || '0.0.0';
const versionCode = process.env.VERSION_CODE || '1';
const applicationId = process.env.VITE_ANDROID_APPLICATION_ID || 'app.shockwallet.test';
const appName = process.env.VITE_APP_NAME || 'missing env';

console.log('Pre-build variables:');
console.log(`Version: ${version}`);
console.log(`Version Code: ${versionCode}`);
console.log(`Application ID: ${applicationId}`);
console.log(`App Name: ${appName}`);

updateBuildGradle(version, versionCode, applicationId, appName);

// Pass version information and app name to Gradle
process.env.ORG_GRADLE_PROJECT_versionCode = versionCode;
process.env.ORG_GRADLE_PROJECT_versionName = version;
process.env.ORG_GRADLE_PROJECT_appName = appName;

console.log('Pre-build script completed');
Loading