|
|
@@ -487,9 +487,28 @@ function buildAndroidApk() {
|
|
|
}
|
|
|
}
|
|
|
copy(srcDir, dstDir);
|
|
|
-
|
|
|
- // 4. 安装白名单插件
|
|
|
- // execSync('npx cordova plugin add cordova-plugin-whitelist', { cwd: cordovaPrjDir, stdio: 'inherit' });
|
|
|
+// 3.1 需要修改 index.html,加入 Cordova 脚本引用
|
|
|
+ const indexPath = path.join(dstDir, 'index.html');
|
|
|
+ let indexContent = fs.readFileSync(indexPath, 'utf8');
|
|
|
+ if (!indexContent.includes('cordova.js')) {
|
|
|
+ indexContent = indexContent.replace(
|
|
|
+ '<head>',
|
|
|
+ '<head> \n \
|
|
|
+ <!--在业务代码执行之前行加载cordova--> \n \
|
|
|
+ <script src="cordova.js"></script>\n'
|
|
|
+ );
|
|
|
+ fs.writeFileSync(indexPath, indexContent, 'utf8');
|
|
|
+ console.log('✅ 已在 index.html 中添加 cordova.js 引用');
|
|
|
+ } else {
|
|
|
+ console.log('✅ index.html 已包含 cordova.js 引用,跳过添加');
|
|
|
+ }
|
|
|
+ // 3.2 把.build\dros\platforms\android\platform_www\cordova.js复制到.build\dros\www目录下
|
|
|
+ const cordovaJsSrc = path.join(cordovaPrjDir, 'platforms', 'android', 'platform_www', 'cordova.js');
|
|
|
+ const cordovaJsDst = path.join(dstDir, 'cordova.js');
|
|
|
+ fs.copyFileSync(cordovaJsSrc, cordovaJsDst);
|
|
|
+ console.log('✅ 已复制 cordova.js 到 www 目录');
|
|
|
+ // 4. 安装插件 : 为了本地保存网络配置等数据
|
|
|
+ execSync('npx cordova plugin add cordova-plugin-nativestorage', { cwd: cordovaPrjDir, stdio: 'inherit' });
|
|
|
|
|
|
// 5. 复制预配置好的config.xml
|
|
|
fs.copyFileSync(path.join(__dirname, 'config.xml'), path.join(cordovaPrjDir, 'config.xml'));
|