Skip to content

Commit

Permalink
Merge pull request #285 from shocknet/test
Browse files Browse the repository at this point in the history
Android builds
  • Loading branch information
shocknet-justin authored Sep 14, 2024
2 parents 348edcd + bf047f7 commit db33c94
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .env.production.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ VITE_DEFAULT_BRIDGE_URL=https://shockwallet.app
VITE_APP_URL=my.shockwallet.app
VITE_SANCTUM_URL=https://auth.shock.network
VITE_KEYLINK_APP_ID=81dcf7168a5de38247ee1a42855f499d077ef5fce79446b779f2bcb2a0e123be
VITE_ANDROID_APPLICATION_ID=app.shockwallet
VITE_ANDROID_APPLICATION_ID=app.shockwallet.my
151 changes: 96 additions & 55 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,73 @@ jobs:
npm ci
npm install -g @ionic/cli native-run cordova-res
- name: Set up environment for test
if: github.ref == 'refs/heads/test'
- name: Set up environment
run: |
cp .env.development.example .env
if [[ ${{ github.event_name }} == 'release' ]]; then
cp .env.production.example .env
else
cp .env.development.example .env
fi
source .env
echo "VITE_APP_NAME=$VITE_APP_NAME" >> $GITHUB_ENV
echo "VITE_ANDROID_APPLICATION_ID=$VITE_ANDROID_APPLICATION_ID" >> $GITHUB_ENV
echo "VITE_APP_NAME=$VITE_APP_NAME" >> $GITHUB_ENV
echo "VITE_APP_URL=$VITE_APP_URL" >> $GITHUB_ENV
- name: Set up environment for production
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
- name: Debug environment
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
echo "Environment variables:"
echo "VITE_APP_NAME: ${{ env.VITE_APP_NAME }}"
echo "VITE_ANDROID_APPLICATION_ID: ${{ env.VITE_ANDROID_APPLICATION_ID }}"
echo "VITE_APP_URL: ${{ env.VITE_APP_URL }}"
- name: Set VERSION and VERSION_CODE
run: |
if [[ ${{ github.event_name }} == 'release' ]]; then
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
echo "VERSION_CODE=$(git rev-list --count HEAD)" >> $GITHUB_ENV
else
echo "VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "VERSION_CODE=$(git rev-list --count HEAD)" >> $GITHUB_ENV
fi
- name: Set up Android project structure
run: |
mkdir -p android/app/src/main/java
mkdir -p android/app/src/main/res/values
- name: Run pre-build script
run: |
if [ -f .env ]; then
source .env
VERSION=${{ env.VERSION }} VERSION_CODE=${{ env.VERSION_CODE }} npm run prebuild
else
echo ".env file not found. Current directory contents:"
ls -la
echo "Current working directory: $(pwd)"
exit 1
fi
npm run prebuild
- name: Verify Android project structure
run: |
echo "Android project structure:"
tree android/app/src/main
echo "MainActivity.java contents:"
cat android/app/src/main/java/${VITE_ANDROID_APPLICATION_ID//./\/}/MainActivity.java
echo "AndroidManifest.xml package and URL:"
grep 'package=' android/app/src/main/AndroidManifest.xml
grep 'android:host=' android/app/src/main/AndroidManifest.xml
echo "build.gradle applicationId and version:"
grep 'applicationId' android/app/build.gradle
grep 'versionCode' android/app/build.gradle
grep 'versionName' android/app/build.gradle
echo "MainActivity.java package:"
grep 'package' android/app/src/main/java/${VITE_ANDROID_APPLICATION_ID//./\/}/MainActivity.java
echo "strings.xml app name:"
grep 'app_name' android/app/src/main/res/values/strings.xml
echo "capacitor.config.json package name:"
grep 'packageName' capacitor.config.json || echo "capacitor.config.json not found"
- name: Build Android app
run: |
source .env
ionic cap sync android
ionic cap build android --no-interactive --prod
if [[ ${{ github.event_name }} == 'release' ]]; then
ionic cap build android --no-interactive --prod
else
ionic cap build android --no-interactive
fi
- name: Set up JDK 17
uses: actions/setup-java@v3
Expand All @@ -98,7 +122,17 @@ jobs:
- name: Build with Gradle
run: |
cd android
./gradlew assembleRelease -PversionCode=${{ env.VERSION_CODE }} -PversionName=${{ env.VERSION }} -PappName="${{ env.VITE_APP_NAME }}" -PapplicationId="${{ env.VITE_ANDROID_APPLICATION_ID }}" -PappUrl="${{ env.VITE_APP_URL }}"
./gradlew assembleRelease --info \
-PversionCode=${{ env.VERSION_CODE }} \
-PversionName=${{ env.VERSION }} \
-PappName="${{ env.VITE_APP_NAME }}" \
-PapplicationId="${{ env.VITE_ANDROID_APPLICATION_ID }}" \
-PappUrl="${{ env.VITE_APP_URL }}"
- name: Check AndroidManifest.xml after Gradle build
run: |
echo "AndroidManifest.xml contents after Gradle build:"
cat android/app/src/main/AndroidManifest.xml
- name: Set up Android SDK
uses: android-actions/setup-android@v3
Expand All @@ -113,38 +147,6 @@ jobs:
keytool -list -v -keystore my-release-key.keystore -storepass ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
shell: bash

- name: Sign APK for test
if: github.ref == 'refs/heads/test'
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 }}-test-${{ env.VERSION }}.apk android/app/build/outputs/apk/release/app-release-unsigned.apk
shell: bash

- name: Sign APK for main
if: github.ref == 'refs/heads/main'
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 }}-prod-${{ env.VERSION }}.apk android/app/build/outputs/apk/release/app-release-unsigned.apk
shell: bash

- name: Verify APK for test
if: github.ref == 'refs/heads/test'
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner verify android/app/build/outputs/apk/release/${{ env.APP_NAME }}-test-${{ env.VERSION }}.apk
shell: bash

- name: Verify APK for main
if: github.ref == 'refs/heads/main'
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner verify android/app/build/outputs/apk/release/${{ env.APP_NAME }}-prod-${{ env.VERSION }}.apk
shell: bash

- name: Set VERSION for release
if: github.event_name == 'release'
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV

- name: Set VERSION for test branch
if: github.event_name == 'push'
run: echo "VERSION=test" >> $GITHUB_ENV

- 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.VITE_APP_NAME }}-${{ env.VERSION }}.apk android/app/build/outputs/apk/release/app-release-unsigned.apk
Expand All @@ -170,5 +172,44 @@ jobs:
if: github.event_name == 'push'
uses: actions/upload-artifact@v3
with:
name: app-release
name: app-release-dev
path: android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk

- name: Check AndroidManifest.xml
run: |
cat android/app/src/main/AndroidManifest.xml
- name: Debug Build Environment
run: |
echo "VITE_ANDROID_APPLICATION_ID: ${{ env.VITE_ANDROID_APPLICATION_ID }}"
echo "Gradle Properties:"
cat android/gradle.properties
echo "Build Gradle Contents:"
cat android/app/build.gradle
- name: Check APK contents
run: |
APK_DIR="android/app/build/outputs/apk/release"
APK_FILE=$(find $APK_DIR -name "*.apk" | head -n 1)
if [ -f "$APK_FILE" ]; then
echo "APK file found: $APK_FILE"
echo "APK contents:"
unzip -l "$APK_FILE"
echo "AndroidManifest.xml contents:"
if unzip -p "$APK_FILE" AndroidManifest.xml > manifest.xml; then
if [ -s manifest.xml ]; then
$ANDROID_SDK_ROOT/build-tools/33.0.0/aapt dump xmltree manifest.xml || echo "aapt command failed"
else
echo "Extracted AndroidManifest.xml is empty"
fi
else
echo "Failed to extract AndroidManifest.xml from APK"
fi
else
echo "No APK file found in $APK_DIR"
ls -R $APK_DIR
fi
- name: Check aapt version
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/aapt version || echo "aapt not found or failed to run"
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apply plugin: 'com.android.application'

android {
namespace project.hasProperty('applicationId') ? project.property('applicationId') : "${applicationId}"
namespace project.hasProperty('applicationId') ? project.property('applicationId') : System.getenv('VITE_ANDROID_APPLICATION_ID')
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId project.hasProperty('applicationId') ? project.property('applicationId') : "${applicationId}"
applicationId project.hasProperty('applicationId') ? project.property('applicationId') : System.getenv('VITE_ANDROID_APPLICATION_ID')
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 1
versionName project.hasProperty('versionName') ? project.property('versionName') : "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "app_name", project.hasProperty('appName') ? project.property('appName') : "Default App Name"
manifestPlaceholders = [appUrl: project.hasProperty('appUrl') ? project.property('appUrl') : (project.hasProperty('applicationId') ? project.property('applicationId').replace('app.', '') : "shockwallet.app")]
manifestPlaceholders = [appUrl: project.hasProperty('appUrl') ? project.property('appUrl') : (project.hasProperty('applicationId') ? project.property('applicationId').replace('app.', '') : "my.shockwallet.app")]
}
buildTypes {
release {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit db33c94

Please sign in to comment.