Skip to content

Commit

Permalink
Merge pull request #280 from shocknet/test
Browse files Browse the repository at this point in the history
Test builds
  • Loading branch information
shocknet-justin authored Sep 13, 2024
2 parents 8548691 + 1b00c5c commit ab48766
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,22 @@ jobs:
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=test" >> $GITHUB_ENV
echo "VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "VERSION_CODE=$(git rev-list --count HEAD)" >> $GITHUB_ENV
fi
echo "VERSION_CODE=$(git rev-list --count HEAD)" >> $GITHUB_ENV
- name: Run pre-build script
run: VERSION=${{ env.VERSION }} VERSION_CODE=${{ env.VERSION_CODE }} npm run prebuild
run: |
source .env
VERSION=${{ env.VERSION }} VERSION_CODE=${{ env.VERSION_CODE }} npm run prebuild
- name: Build Android app
run: ionic cap build android --no-interactive
run: |
source .env
ionic cap sync android
ionic cap build android --no-interactive --prod
- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ android {
// 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
}
buildTypes {
release {
Expand Down
8 changes: 3 additions & 5 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:requestLegacyExternalStorage="true"
Expand All @@ -12,7 +11,6 @@
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask"
android:exported="true">
Expand All @@ -21,7 +19,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter android:autoVerify="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
Expand All @@ -30,7 +28,7 @@
<data android:scheme="bitcoin"/>
</intent-filter>

<intent-filter android:autoVerify="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
Expand All @@ -43,7 +41,7 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="test.shockwallet.app" />
<data android:scheme="https" android:host="my.shockwallet.app" />
</intent-filter>
</activity>

Expand Down
21 changes: 16 additions & 5 deletions preBuild/preBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ const path = require('path');

// Read and modify the AndroidManifest.xml file
const androidManifestPath = 'android/app/src/main/AndroidManifest.xml';
let androidManifest = fs.readFileSync('preBuild/AndroidManifest.copy.xml', 'utf8');
androidManifest = androidManifest.replace('${appUrl}', process.env.VITE_APP_URL);
androidManifest = androidManifest.replace('${appName}', process.env.VITE_APP_NAME);
let androidManifest = fs.readFileSync(androidManifestPath, 'utf8');

// Replace the app URL
androidManifest = androidManifest.replace(
/<data android:scheme="https" android:host="[^"]+"/,
`<data android:scheme="https" android:host="${process.env.VITE_APP_URL}"`
);

fs.writeFileSync(androidManifestPath, androidManifest);

// Read and modify the Info.plist file
Expand All @@ -26,7 +31,7 @@ entitlements = entitlements.replace('${appUrl}', process.env.VITE_APP_URL);
fs.writeFileSync(entitlementsPath, entitlements);

// Update the build.gradle file
function updateBuildGradle(version, versionCode, applicationId) {
function updateBuildGradle(version, versionCode, applicationId, appName) {
const buildGradlePath = path.join(__dirname, '..', 'android', 'app', 'build.gradle');
let buildGradle = fs.readFileSync(buildGradlePath, 'utf8');

Expand All @@ -50,12 +55,18 @@ function updateBuildGradle(version, versionCode, applicationId) {
`namespace "${applicationId}"`
);

buildGradle = buildGradle.replace(
/resValue "string", "app_name", "[^"]+"/,
`resValue "string", "app_name", "${appName}"`
);

fs.writeFileSync(buildGradlePath, buildGradle);
}

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';
updateBuildGradle(version, versionCode, applicationId);
const appName = process.env.VITE_APP_NAME || 'missing env';
updateBuildGradle(version, versionCode, applicationId, appName);

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

0 comments on commit ab48766

Please sign in to comment.