Skip to content

Commit

Permalink
moar debug
Browse files Browse the repository at this point in the history
  • Loading branch information
shocknet-justin committed Sep 14, 2024
1 parent 139e50e commit 0462f42
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,21 @@ jobs:
exit 1
fi
- name: Check AndroidManifest.xml after prebuild
run: |
echo "AndroidManifest.xml contents after prebuild:"
cat android/app/src/main/AndroidManifest.xml
- name: Verify package name and version after prebuild
run: |
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/app/shockwallet/my/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: |
Expand Down
65 changes: 46 additions & 19 deletions preBuild/preBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,22 @@ console.log('VITE_APP_URL:', process.env.VITE_APP_URL);
console.log('VERSION:', process.env.VERSION);
console.log('VERSION_CODE:', process.env.VERSION_CODE);

// Update AndroidManifest.xml
const androidManifestPath = path.join(__dirname, '..', 'android', 'app', 'src', 'main', 'AndroidManifest.xml');
let androidManifest = fs.readFileSync(androidManifestPath, 'utf8');

console.log('Before AndroidManifest.xml update:');
console.log(androidManifest);

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

// Replace the package name
androidManifest = androidManifest.replace(
/package="[^"]+"/,
`package="${process.env.VITE_ANDROID_APPLICATION_ID}"`
);

// Replace any remaining ${applicationId} placeholders
androidManifest = androidManifest.replace(
/\${applicationId}/g,
process.env.VITE_ANDROID_APPLICATION_ID || ''
/android:name="\.MainActivity"/,
`android:name="${process.env.VITE_ANDROID_APPLICATION_ID}.MainActivity"`
);
androidManifest = androidManifest.replace(
/<data android:scheme="https" android:host="[^"]+"/,
`<data android:scheme="https" android:host="${process.env.VITE_APP_URL}"`
);

console.log('After AndroidManifest.xml update:');
console.log(androidManifest);

fs.writeFileSync(androidManifestPath, androidManifest);
console.log('AndroidManifest.xml updated successfully');
Expand All @@ -51,12 +41,14 @@ buildGradle = buildGradle.replace(
/applicationId .+/,
`applicationId "${process.env.VITE_ANDROID_APPLICATION_ID}"`
);

buildGradle = buildGradle.replace(
/namespace .+/,
`namespace "${process.env.VITE_ANDROID_APPLICATION_ID}"`
);
buildGradle = buildGradle.replace(
/versionCode .+/,
`versionCode ${process.env.VERSION_CODE}`
);

buildGradle = buildGradle.replace(
/versionName .+/,
`versionName "${process.env.VERSION}"`
Expand All @@ -65,4 +57,39 @@ buildGradle = buildGradle.replace(
fs.writeFileSync(buildGradlePath, buildGradle);
console.log('build.gradle updated successfully');

// Update MainActivity.java
const mainActivityPath = path.join(__dirname, '..', 'android', 'app', 'src', 'main', 'java', 'app', 'shockwallet', 'my', 'MainActivity.java');
let mainActivity = fs.readFileSync(mainActivityPath, 'utf8');
mainActivity = mainActivity.replace(
/package .+;/,
`package ${process.env.VITE_ANDROID_APPLICATION_ID};`
);

fs.writeFileSync(mainActivityPath, mainActivity);
console.log('MainActivity.java updated successfully');

// Update strings.xml
const stringsXmlPath = path.join(__dirname, '..', 'android', 'app', 'src', 'main', 'res', 'values', 'strings.xml');
let stringsXml = fs.readFileSync(stringsXmlPath, 'utf8');

stringsXml = stringsXml.replace(
/<string name="app_name">[^<]+<\/string>/,
`<string name="app_name">${process.env.VITE_APP_NAME}</string>`
);

fs.writeFileSync(stringsXmlPath, stringsXml);
console.log('strings.xml updated successfully');

// Update capacitor.config.json or capacitor.config.ts
const capacitorConfigPath = path.join(__dirname, '..', 'capacitor.config.json');
if (fs.existsSync(capacitorConfigPath)) {
let capacitorConfig = JSON.parse(fs.readFileSync(capacitorConfigPath, 'utf8'));
capacitorConfig.android = capacitorConfig.android || {};
capacitorConfig.android.packageName = process.env.VITE_ANDROID_APPLICATION_ID;
fs.writeFileSync(capacitorConfigPath, JSON.stringify(capacitorConfig, null, 2));
console.log('capacitor.config.json updated successfully');
} else {
console.log('capacitor.config.json not found. Make sure to update it manually if needed.');
}

console.log('Prebuild script completed');

0 comments on commit 0462f42

Please sign in to comment.