Преглед изворни кода

build(android): modify build process and configuration to enable CORS for external network access

dengdx пре 1 месец
родитељ
комит
60907f1d9f
2 измењених фајлова са 32 додато и 3 уклоњено
  1. 6 3
      .build/build-android.js
  2. 26 0
      .build/config.xml

+ 6 - 3
.build/build-android.js

@@ -33,10 +33,13 @@ function copy(src, dst) {
   }
 }
 copy(srcDir, dstDir);
-
-// 4. 在 .build/dros 中执行 cordova build android
+// 4. 安装白名单插件
+// execSync('npx cordova plugin add cordova-plugin-whitelist', { cwd: cordovaPrjDir, stdio: 'inherit' });
+// 5. 复制预配置好的config.xml
+fs.copyFileSync(path.join(__dirname, 'config.xml'), path.join(cordovaPrjDir, 'config.xml'));
+// 6. 在 .build/dros 中执行 cordova build android
 execSync('npx cordova build android', { cwd: cordovaPrjDir, stdio: 'inherit' });
-// 5. 重命名apk文件
+// 7. 重命名apk文件
 const version='1.0.0'
 const pkg='dros'
 const src = path.join(__dirname, 'dros/platforms/android/app/build/outputs/apk/debug/app-debug.apk');

+ 26 - 0
.build/config.xml

@@ -0,0 +1,26 @@
+<?xml version='1.0' encoding='utf-8'?>
+<widget id="zskk.dros" version="1.0.0" 
+    xmlns="http://www.w3.org/ns/widgets" 
+    xmlns:cdv="http://cordova.apache.org/ns/1.0"
+    xmlns:android="http://schemas.android.com/apk/res/android">
+    <name>dros</name>
+    <description>Sample Apache Cordova App</description>
+    <author email="dev@cordova.apache.org" href="https://cordova.apache.org">
+        Apache Cordova Team
+    </author>
+    <content src="index.html" />
+    
+    <!-- 白名单配置 -->
+    <!-- <access origin="*" />
+    <allow-navigation href="*" />
+    <allow-intent href="http://*/*" />
+    <allow-intent href="https://*/*" /> -->
+
+    <!-- Android 平台配置:允许明文 HTTP -->
+    <platform name="android">
+        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
+            <application android:usesCleartextTraffic="true" />
+        </edit-config>
+        <preference name="AndroidInsecureFileModeEnabled" value="true" />
+    </platform>
+</widget>