codeplay-common 4.11.3 → 4.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +14 -0
- package/RELEASE_NOTES.md +13 -0
- package/files/buildCodeplay/codeplayBeforeBuild.js +9 -22
- package/files/buildCodeplay/ensure-current-build.cjs +42 -0
- package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -0
- package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -0
- package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -0
- package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -0
- package/files/buildCodeplay/manifestModification.js +3 -0
- package/files/buildCodeplay/project-scripts.cjs +4 -0
- package/files/finalrelease +4 -6
- package/package.json +1 -1
- package/scripts/ensure-current-build.test.cjs +76 -0
- package/scripts/sync-files.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- Detect version-suffixed files in the app's `buildCodeplay` folder at build startup, then run `npm uninstall codeplay-common` and `npm install codeplay-common` sequentially before resuming with the refreshed before-build script.
|
|
6
|
+
- Stop on reinstall failure or incomplete legacy cleanup rather than continuing with stale build templates.
|
|
7
|
+
|
|
8
|
+
## 4.11.4 — 2026-10-27
|
|
9
|
+
|
|
10
|
+
Version name: 4.11.4. Version code/build number: not applicable to this npm package.
|
|
11
|
+
|
|
12
|
+
Files changed: `package.json`, `scripts/sync-files.js`, `files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs`, `files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs`, `files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs`, `files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle`, `files/buildCodeplay/codeplayBeforeBuild.js`, `files/buildCodeplay/manifestModification.js`, `files/buildCodeplay/project-scripts.cjs`, `files/finalrelease`, `README.md`, `CHANGELOG.md`, `RELEASE_NOTES.md`.
|
|
13
|
+
|
|
14
|
+
- Preserve Capacitor permission annotations in every consuming Android app, without an app ID or permission-use restriction.
|
|
15
|
+
- Restore the scoped ProGuard rules during installation, Android sync and every Gradle build through a regenerated apply-from hook; keep existing custom rules and avoid duplicates.
|
|
16
|
+
- Ship the helper inside `buildCodeplay` so shared templates do not depend on an app-specific `Scripts` file.
|
|
17
|
+
- Provide `npm run android:r8-rules` and migrate the known previous helper command while preserving custom commands.
|
|
18
|
+
- Keep permission declarations, prompts, minification settings and iOS configuration unchanged; already-distributed binaries require rebuilding.
|
|
19
|
+
- Preserve explicit release minification settings when distributing shared templates, and retain the tested FFmpeg JNI rules when that plugin is installed.
|
|
20
|
+
|
|
3
21
|
## 4.10.5 — 2026-10-23
|
|
4
22
|
|
|
5
23
|
Version name: 4.10.5. Version code/build number: not applicable to this npm package.
|
package/README.md
CHANGED
|
@@ -9,6 +9,16 @@ Based on store install various IAP plugins
|
|
|
9
9
|
Make it to ionic project
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
## Capacitor Android permission metadata (4.11.4)
|
|
13
|
+
|
|
14
|
+
The package preserves the runtime `CapacitorPlugin` and `Permission` annotation members required by optimized Android builds. This applies to every Android consumer, even if the app does not currently use permission-dependent plugins. It does not declare or grant permissions, show prompts, or enable minification.
|
|
15
|
+
|
|
16
|
+
Installation applies the rules to an existing Android project and installs one `apply from` line in `android/app/build.gradle`. The included Gradle script reruns the repair during every Gradle configuration, including direct Android Studio/Gradle and Capacitor `run --no-sync` builds. All repair logic stays in the shared fix folder. Android sync, build preparation and release preparation restore missing rules after platform regeneration. The generated Gradle hook is restored after platform regeneration. Existing custom ProGuard rules are preserved and repeated runs do not add duplicates. Apps without an Android platform are skipped until that platform exists.
|
|
17
|
+
|
|
18
|
+
All fix implementations ship under `buildCodeplay/fix-optimize-builld/`, including the restore command and its Gradle integration; no app-specific `Scripts` file is required. Run `npm run android:r8-rules` to restore the rules manually. Existing custom npm commands are preserved; the known older `restore-android-r8-rules.cjs` command is migrated automatically.
|
|
19
|
+
|
|
20
|
+
After installing this package update, rebuild and test each app's optimized release. Updating build tooling cannot change APKs or app-store releases already distributed to users.
|
|
21
|
+
|
|
12
22
|
## App helper folder
|
|
13
23
|
|
|
14
24
|
Application helper scripts are kept in `scripts-common/`. Installation migrates the old `scripts/` folder and package command paths automatically, preserving every existing file. A conflicting destination file stops migration before any files are moved. The plugin’s internal npm lifecycle folder remains `scripts/`.
|
|
@@ -21,6 +31,8 @@ App package scripts run local files: node buildCodeplay/codeplayBeforeBuild.js,
|
|
|
21
31
|
|
|
22
32
|
Installation migrates both legacy versioned filenames and the temporary node_modules runner commands to these local paths. It removes only superseded versioned build scripts, preserves app-owned release configuration and splash XML overrides, and keeps screenshot data and custom helpers. The root finalrelease script is also copied as a local implementation.
|
|
23
33
|
|
|
34
|
+
After this update is installed, `npm run build` checks the app's `buildCodeplay/` folder for version-suffixed files before preparing the build. If any exist, it runs `npm uninstall codeplay-common` followed by `npm install codeplay-common`, then runs the refreshed before-build script before continuing. A failed command or remaining versioned files stops the build. Unrecognized legacy files must be migrated manually; they are not deleted automatically.
|
|
35
|
+
|
|
24
36
|
Before-build includes the automatic IAP startup and Home Pro-button migrations. IAP and AdMob ZIPs are downloaded directly from https://htmlcodeplay.com/code-play-plugin/ using the existing update flow. No plugin ZIPs are bundled in this npm package. App-specific configuration and designs remain in the app.
|
|
25
37
|
|
|
26
38
|
## AdMob folder packages
|
|
@@ -213,3 +225,5 @@ Version : 4.0.0 (Previous version 3.2.19)
|
|
|
213
225
|
1) In here we are completly remove the admob-emi and use "capacitor-admob-nextgen"
|
|
214
226
|
2) Removed "modify-plugin-xml.js"
|
|
215
227
|
3)
|
|
228
|
+
|
|
229
|
+
The fix preserves the metadata behind the release permission-check failure verified in testing. It does not guarantee every native dialog or plugin: required manifest declarations, Android permission policy, device settings and plugin-specific keep rules still apply.
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Release notes
|
|
2
2
|
|
|
3
|
+
## 4.11.4 — 2026-10-27
|
|
4
|
+
|
|
5
|
+
Version name: 4.11.4. Version code/build number: not applicable to this npm package.
|
|
6
|
+
|
|
7
|
+
Files changed: `package.json`, `scripts/sync-files.js`, `files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs`, `files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs`, `files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs`, `files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle`, `files/buildCodeplay/codeplayBeforeBuild.js`, `files/buildCodeplay/manifestModification.js`, `files/buildCodeplay/project-scripts.cjs`, `files/finalrelease`, `README.md`, `CHANGELOG.md`, `RELEASE_NOTES.md`.
|
|
8
|
+
|
|
9
|
+
- Fix missing permission-check results caused by release optimization removing Capacitor metadata.
|
|
10
|
+
- Apply protection to all Android apps using this package, including apps with no permission-dependent features.
|
|
11
|
+
- Restore protection after native platform regeneration and package updates, and check it on every Gradle build without overwriting custom ProGuard rules.
|
|
12
|
+
- Keep the fix self-contained in the shared package and provide a manual restore command.
|
|
13
|
+
- No new permissions or prompts are added. Update the package and rebuild each app to include the correction.
|
|
14
|
+
- Preserve existing release minification choices and protect FFmpeg native entry points in apps using that plugin.
|
|
15
|
+
|
|
3
16
|
## 4.10.5 — 2026-10-23
|
|
4
17
|
|
|
5
18
|
Version name: 4.10.5. Version code/build number: not applicable to this npm package.
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
// Version 6.7: deferred IAP startup, ownership-safe ads, and unified store preparation.
|
|
3
3
|
// Version 6.7: migrate AdMob files to ZIP-distributed folder packages.
|
|
4
4
|
// Version 6.7: recreate failed WebViews, defer background recovery, and suppress foreground recovery toasts.
|
|
5
|
+
// Reinstall legacy build templates before loading dependencies or changing the app.
|
|
6
|
+
try {
|
|
7
|
+
if (require('./ensure-current-build.cjs').ensureCurrentBuild()) process.exit(0);
|
|
8
|
+
} catch (error) {
|
|
9
|
+
console.error(`Build preparation failed: ${error.message}`);
|
|
10
|
+
process.exit(typeof error.status === 'number' && error.status > 0 ? error.status : 1);
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
const fs = require('fs');
|
|
6
14
|
const path = require('path');
|
|
7
15
|
const plist = require('plist');
|
|
@@ -4522,30 +4530,9 @@ function findAndroidBuildBlock(content, name) {
|
|
|
4522
4530
|
return null;
|
|
4523
4531
|
}
|
|
4524
4532
|
|
|
4525
|
-
function syncAndroidCapacitorPermissionRules() {
|
|
4526
|
-
if (buildPlatform !== 'android' || !fs.existsSync(androidAppBuildGradlePath)) return;
|
|
4527
|
-
const capacitorConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
4528
|
-
if (capacitorConfig.appId !== 'codeplay.love.calculator') return;
|
|
4529
|
-
|
|
4530
|
-
const rulesPath = path.join(androidPlatformPath, 'app', 'proguard-rules.pro');
|
|
4531
|
-
const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
|
|
4532
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
4533
|
-
const rules = [
|
|
4534
|
-
'-keepattributes RuntimeVisibleAnnotations,AnnotationDefault',
|
|
4535
|
-
'-keep @interface com.getcapacitor.annotation.CapacitorPlugin { *; }',
|
|
4536
|
-
'-keep @interface com.getcapacitor.annotation.Permission { *; }'
|
|
4537
|
-
];
|
|
4538
|
-
const existingRules = original.split(/\r?\n/).map(line => line.trim());
|
|
4539
|
-
const missingRules = rules.filter(rule => !existingRules.includes(rule));
|
|
4540
|
-
if (!missingRules.length) return;
|
|
4541
|
-
|
|
4542
|
-
const next = `${original.trimEnd()}${newline}${newline}# Preserve Capacitor permission metadata used at runtime.${newline}${missingRules.join(newline)}${newline}`;
|
|
4543
|
-
fs.writeFileSync(rulesPath, next, 'utf8');
|
|
4544
|
-
}
|
|
4545
|
-
|
|
4546
4533
|
function syncAndroidBuildOptimization() {
|
|
4547
4534
|
if (buildPlatform !== 'android' || !fs.existsSync(androidAppBuildGradlePath)) return;
|
|
4548
|
-
|
|
4535
|
+
require('./fix-optimize-builld/restore-android-r8-rules.cjs').syncAndroidR8Rules(process.cwd(), { installGradleHook: true });
|
|
4549
4536
|
|
|
4550
4537
|
const original = fs.readFileSync(androidAppBuildGradlePath, 'utf8');
|
|
4551
4538
|
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { execSync, execFileSync } = require('child_process');
|
|
4
|
+
|
|
5
|
+
function findVersionedBuildFiles(projectRoot) {
|
|
6
|
+
const directory = path.join(projectRoot, 'buildCodeplay');
|
|
7
|
+
if (!fs.existsSync(directory)) return [];
|
|
8
|
+
return fs.readdirSync(directory, { withFileTypes: true })
|
|
9
|
+
.filter(entry => entry.isFile() && /-\d+(?:\.\d+)*(?:-beta-\d+)?\.[^.]+$/i.test(entry.name))
|
|
10
|
+
.map(entry => entry.name);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function ensureCurrentBuild(options = {}) {
|
|
14
|
+
const projectRoot = path.resolve(options.projectRoot || process.cwd());
|
|
15
|
+
const legacyFiles = findVersionedBuildFiles(projectRoot);
|
|
16
|
+
if (!legacyFiles.length) return false;
|
|
17
|
+
|
|
18
|
+
console.log(`Legacy buildCodeplay files found: ${legacyFiles.join(', ')}. Reinstalling codeplay-common before continuing.`);
|
|
19
|
+
const runNpm = options.runNpm || (command => execSync(command, { cwd: projectRoot, stdio: 'inherit' }));
|
|
20
|
+
runNpm('npm uninstall codeplay-common');
|
|
21
|
+
runNpm('npm install codeplay-common');
|
|
22
|
+
|
|
23
|
+
// Postinstall replaces the scripts and removes recognized legacy files.
|
|
24
|
+
// Do not run stale code or retry indefinitely if migration did not finish.
|
|
25
|
+
const remaining = findVersionedBuildFiles(projectRoot);
|
|
26
|
+
if (remaining.length) {
|
|
27
|
+
throw new Error(`Legacy buildCodeplay files remain after reinstall: ${remaining.join(', ')}. Build stopped; migrate these files before retrying.`);
|
|
28
|
+
}
|
|
29
|
+
const entrypoint = path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js');
|
|
30
|
+
if (!fs.existsSync(entrypoint)) throw new Error('codeplayBeforeBuild.js is missing after reinstall. Build stopped.');
|
|
31
|
+
|
|
32
|
+
// The current process loaded the old templates. Finish preparation in a fresh
|
|
33
|
+
// process before the caller's remaining build commands are allowed to run.
|
|
34
|
+
const runBeforeBuild = options.runBeforeBuild || (script => execFileSync(process.execPath, [script, ...process.argv.slice(2)], {
|
|
35
|
+
cwd: projectRoot,
|
|
36
|
+
stdio: 'inherit',
|
|
37
|
+
}));
|
|
38
|
+
runBeforeBuild(entrypoint);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { ensureCurrentBuild, findVersionedBuildFiles };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function syncCapacitorPermissionRules(projectRoot = path.resolve(__dirname, '../..')) {
|
|
5
|
+
const appPath = path.join(projectRoot, 'android', 'app');
|
|
6
|
+
if (!fs.existsSync(path.join(appPath, 'build.gradle'))) return false;
|
|
7
|
+
|
|
8
|
+
const rulesPath = path.join(appPath, 'proguard-rules.pro');
|
|
9
|
+
const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
|
|
10
|
+
const rules = [
|
|
11
|
+
'-keepattributes RuntimeVisibleAnnotations,AnnotationDefault',
|
|
12
|
+
'-keep @interface com.getcapacitor.annotation.CapacitorPlugin { *; }',
|
|
13
|
+
'-keep @interface com.getcapacitor.annotation.Permission { *; }',
|
|
14
|
+
];
|
|
15
|
+
const existing = new Set(original.split(/\r?\n/).map(line => line.trim()));
|
|
16
|
+
const missing = rules.filter(rule => !existing.has(rule));
|
|
17
|
+
if (!missing.length) return false;
|
|
18
|
+
|
|
19
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
20
|
+
fs.writeFileSync(rulesPath, `${original.trimEnd()}${newline}${newline}`
|
|
21
|
+
+ `# Preserve Capacitor permission metadata used at runtime.${newline}`
|
|
22
|
+
+ `${missing.join(newline)}${newline}`, 'utf8');
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (require.main === module) {
|
|
27
|
+
const changed = syncCapacitorPermissionRules();
|
|
28
|
+
console.log(changed ? 'Capacitor R8 permission rules restored.' : 'Capacitor R8 permission rules unchanged.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { syncCapacitorPermissionRules };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
// FFmpegKit's JNI library looks up these Java members by name at runtime.
|
|
5
|
+
const FFMPEG_JNI_RULES = [
|
|
6
|
+
'-keep class com.antonkarpenko.ffmpegkit.** { *; }',
|
|
7
|
+
'-keep interface com.antonkarpenko.ffmpegkit.** { *; }',
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
function syncFfmpegJniRules(projectRoot) {
|
|
11
|
+
const pluginPath = path.join(projectRoot, 'node_modules', 'codeplay-fmpg', 'plugin.xml');
|
|
12
|
+
const appPath = path.join(projectRoot, 'android', 'app');
|
|
13
|
+
if (!fs.existsSync(pluginPath) || !fs.existsSync(appPath)) return false;
|
|
14
|
+
|
|
15
|
+
const rulesPath = path.join(appPath, 'proguard-rules.pro');
|
|
16
|
+
const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
|
|
17
|
+
const existing = new Set(original.split(/\r?\n/).map(line => line.trim()));
|
|
18
|
+
const missing = FFMPEG_JNI_RULES.filter(rule => !existing.has(rule));
|
|
19
|
+
if (!missing.length) return false;
|
|
20
|
+
|
|
21
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
22
|
+
fs.writeFileSync(rulesPath, `${original.trimEnd()}${newline}${newline}`
|
|
23
|
+
+ `# Preserve FFmpegKit JNI entry points and callbacks.${newline}`
|
|
24
|
+
+ `${missing.join(newline)}${newline}`, 'utf8');
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { syncFfmpegJniRules };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Restore native metadata before Gradle configures an optimized Android build.
|
|
2
|
+
def codeplayAppRoot = rootProject.projectDir.parentFile
|
|
3
|
+
def codeplayRepairScript = new File(codeplayAppRoot, 'buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs')
|
|
4
|
+
def codeplayNodeBinary = project.findProperty('codeplayNodeBinary') ?: 'node'
|
|
5
|
+
|
|
6
|
+
providers.exec {
|
|
7
|
+
workingDir codeplayAppRoot
|
|
8
|
+
commandLine codeplayNodeBinary, codeplayRepairScript.absolutePath
|
|
9
|
+
}.result.get().assertNormalExitValue()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { syncFfmpegJniRules } = require('./ffmpeg-jni-rules.cjs');
|
|
4
|
+
const { syncCapacitorPermissionRules } = require('./android-r8-rules.cjs');
|
|
5
|
+
|
|
6
|
+
function syncAndroidR8Rules(projectRoot = path.resolve(__dirname, '../..'), { installGradleHook = false } = {}) {
|
|
7
|
+
const buildPath = path.join(projectRoot, 'android', 'app', 'build.gradle');
|
|
8
|
+
if (!fs.existsSync(buildPath)) return false;
|
|
9
|
+
const capacitorChanged = syncCapacitorPermissionRules(projectRoot);
|
|
10
|
+
const ffmpegChanged = syncFfmpegJniRules(projectRoot);
|
|
11
|
+
let hookChanged = false;
|
|
12
|
+
if (installGradleHook) {
|
|
13
|
+
const original = fs.readFileSync(buildPath, 'utf8');
|
|
14
|
+
const hook = "apply from: '../../buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle'";
|
|
15
|
+
const existingHook = /^[ \t]*apply\s+from:\s*(['"])\.\.\/\.\.\/buildCodeplay\/fix-optimize-builld\/fix-optimize-build\.gradle\1[ \t]*;?[ \t]*$/m;
|
|
16
|
+
if (!existingHook.test(original)) {
|
|
17
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
18
|
+
fs.writeFileSync(buildPath, `${original.trimEnd()}${newline}${newline}${hook}${newline}`, 'utf8');
|
|
19
|
+
hookChanged = true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return capacitorChanged || ffmpegChanged || hookChanged;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (require.main === module) {
|
|
26
|
+
const changed = syncAndroidR8Rules(undefined, { installGradleHook: process.argv.includes('--install-gradle-hook') });
|
|
27
|
+
console.log(changed ? 'Android R8 keep rules restored.' : 'Android R8 keep rules unchanged; no Android app or rules already present.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { syncAndroidR8Rules };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const plist = require('plist');
|
|
4
|
+
const { syncAndroidR8Rules } = require('./fix-optimize-builld/restore-android-r8-rules.cjs');
|
|
5
|
+
|
|
6
|
+
syncAndroidR8Rules(process.cwd(), { installGradleHook: true });
|
|
4
7
|
|
|
5
8
|
const { readFileSync } = require("fs");
|
|
6
9
|
|
|
@@ -38,6 +38,10 @@ function updateBuildScripts(scripts) {
|
|
|
38
38
|
next['ionic:build'] = next['ionic:build'] || 'npm run build';
|
|
39
39
|
next['ionic:serve'] = next['ionic:serve'] || 'cross-env NODE_ENV=development vite';
|
|
40
40
|
next['baseline-profile:setup'] = next['baseline-profile:setup'] || 'node scripts-common/setup-baseline-profile.js';
|
|
41
|
+
const r8Command = next['android:r8-rules'];
|
|
42
|
+
if (!r8Command || r8Command === 'node buildCodeplay/android-r8-rules.cjs' || /^node\s+(?:\.\/)?(?:Scripts|scripts|scripts-common)\/restore-android-r8-rules\.cjs$/.test(r8Command)) {
|
|
43
|
+
next['android:r8-rules'] = 'node buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs';
|
|
44
|
+
}
|
|
41
45
|
if (!next['baseline-profile:generate'] || next['baseline-profile:generate'] === 'cd android && gradlew.bat :app:generateBaselineProfile --console=plain') {
|
|
42
46
|
next['baseline-profile:generate'] = 'node scripts-common/generate-baseline-profile.js';
|
|
43
47
|
}
|
package/files/finalrelease
CHANGED
|
@@ -12,6 +12,7 @@ import { createInterface } from 'readline';
|
|
|
12
12
|
|
|
13
13
|
import { fileURLToPath } from 'url';
|
|
14
14
|
import { dirname } from 'path';
|
|
15
|
+
import { syncAndroidR8Rules } from './buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs';
|
|
15
16
|
|
|
16
17
|
/* const path = require('path');
|
|
17
18
|
const fs = require('fs'); */
|
|
@@ -744,6 +745,7 @@ function findGradleBlock(content, headerPattern) {
|
|
|
744
745
|
}
|
|
745
746
|
|
|
746
747
|
function ensureReleaseCodeOptimization() {
|
|
748
|
+
syncAndroidR8Rules(process.cwd(), { installGradleHook: true });
|
|
747
749
|
const currentContent = readFileSync(gradleFilePath, 'utf8');
|
|
748
750
|
const releaseBlock = findGradleBlock(currentContent, /buildTypes\s*\{[\s\S]*?\brelease\s*/);
|
|
749
751
|
if (!releaseBlock) throw new Error('Release build configuration was not found.');
|
|
@@ -957,11 +959,7 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
|
|
|
957
959
|
throw new Error('Release build configuration was not found.');
|
|
958
960
|
}
|
|
959
961
|
let minificationContent = updatedGradleContent.slice(minificationBlock.start, minificationBlock.end);
|
|
960
|
-
if (
|
|
961
|
-
// Replace existing value with desired
|
|
962
|
-
minificationContent = minificationContent.replace(/\bminifyEnabled\s*(?:=\s*)?(true|false)\b/, `minifyEnabled ${desiredMinify}`);
|
|
963
|
-
console.log(`Replaced minifyEnabled with ${desiredMinify}.`);
|
|
964
|
-
} else {
|
|
962
|
+
if (!/\bminifyEnabled\b/.test(minificationContent)) {
|
|
965
963
|
// Insert minifyEnabled if not present
|
|
966
964
|
minificationContent = `\n minifyEnabled ${desiredMinify}${minificationContent}`;
|
|
967
965
|
console.log(`✅ Inserted minifyEnabled ${desiredMinify} into release block.`);
|
|
@@ -993,7 +991,7 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
|
|
|
993
991
|
|
|
994
992
|
// Write the updated gradle content back to build.gradle
|
|
995
993
|
writeFileSync(gradleFilePath, updatedGradleContent, 'utf8');
|
|
996
|
-
console.log(`✅ Updated build.gradle with versionCode: ${finalVersionCode}, versionName: ${finalVersionName}, resConfigs "en"
|
|
994
|
+
console.log(`✅ Updated build.gradle with versionCode: ${finalVersionCode}, versionName: ${finalVersionName}, resConfigs "en"; existing minification settings preserved.`);
|
|
997
995
|
|
|
998
996
|
let baselineProfileChecked = false;
|
|
999
997
|
for (const id of storeIds) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
|
+
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
|
+
|
|
9
|
+
function fixture(t, names = []) {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-legacy-build-'));
|
|
11
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
+
fs.mkdirSync(path.join(root, 'buildCodeplay'));
|
|
13
|
+
for (const name of ['codeplayBeforeBuild.js', ...names]) fs.writeFileSync(path.join(root, 'buildCodeplay', name), '');
|
|
14
|
+
return root;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('current structure continues without npm commands', t => {
|
|
18
|
+
const projectRoot = fixture(t, ['versions.json', 'custom-helper.js']);
|
|
19
|
+
assert.equal(ensureCurrentBuild({ projectRoot, runNpm: () => assert.fail('unexpected npm command') }), false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('legacy files force ordered reinstall and fresh preparation before continuing', t => {
|
|
23
|
+
const projectRoot = fixture(t, ['codeplayBeforeBuild-6.7.js', 'setSplashAnimation-1.2.mjs']);
|
|
24
|
+
const calls = [];
|
|
25
|
+
assert.equal(ensureCurrentBuild({
|
|
26
|
+
projectRoot,
|
|
27
|
+
runNpm(command) {
|
|
28
|
+
calls.push(command);
|
|
29
|
+
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
30
|
+
},
|
|
31
|
+
runBeforeBuild(script) {
|
|
32
|
+
assert.equal(script, path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js'));
|
|
33
|
+
calls.push('fresh preparation');
|
|
34
|
+
},
|
|
35
|
+
}), true);
|
|
36
|
+
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common', 'fresh preparation']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
for (const failedCommand of ['npm uninstall codeplay-common', 'npm install codeplay-common']) {
|
|
40
|
+
test(`failure of ${failedCommand} stops preparation`, t => {
|
|
41
|
+
const projectRoot = fixture(t, ['add-splash-screen-1.0.js']);
|
|
42
|
+
const calls = [];
|
|
43
|
+
assert.throws(() => ensureCurrentBuild({
|
|
44
|
+
projectRoot,
|
|
45
|
+
runNpm(command) {
|
|
46
|
+
calls.push(command);
|
|
47
|
+
if (command === failedCommand) throw new Error('npm failed');
|
|
48
|
+
},
|
|
49
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
50
|
+
}), /npm failed/);
|
|
51
|
+
assert.equal(calls.at(-1), failedCommand);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
test('unknown versioned files trigger reinstall but stop without deleting app files or looping', t => {
|
|
56
|
+
const projectRoot = fixture(t, ['custom-helper-1.0.js']);
|
|
57
|
+
const calls = [];
|
|
58
|
+
assert.throws(() => ensureCurrentBuild({
|
|
59
|
+
projectRoot,
|
|
60
|
+
runNpm: command => calls.push(command),
|
|
61
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
62
|
+
}), /Legacy buildCodeplay files remain/);
|
|
63
|
+
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common']);
|
|
64
|
+
assert.ok(fs.existsSync(path.join(projectRoot, 'buildCodeplay', 'custom-helper-1.0.js')));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('failed refreshed preparation propagates to stop the build', t => {
|
|
68
|
+
const projectRoot = fixture(t, ['packageidBaseModification-1.0.js']);
|
|
69
|
+
assert.throws(() => ensureCurrentBuild({
|
|
70
|
+
projectRoot,
|
|
71
|
+
runNpm(command) {
|
|
72
|
+
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
73
|
+
},
|
|
74
|
+
runBeforeBuild() { throw Object.assign(new Error('preparation failed'), { status: 7 }); },
|
|
75
|
+
}), { message: 'preparation failed', status: 7 });
|
|
76
|
+
});
|
package/scripts/sync-files.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { updateBuildScripts, removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
4
|
+
const { syncAndroidR8Rules } = require('../files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs');
|
|
4
5
|
|
|
5
6
|
function migrateAppScripts(projectRoot) {
|
|
6
7
|
const root = path.resolve(projectRoot);
|
|
@@ -97,6 +98,7 @@ function install(options = {}) {
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
migrateAppConfigurator(projectRoot);
|
|
101
|
+
syncAndroidR8Rules(projectRoot, { installGradleHook: true });
|
|
100
102
|
pkg.scripts = scripts;
|
|
101
103
|
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
|
|
102
104
|
// Cleanup happens only after replacement assets and package commands exist.
|