zcw-shared 1.38.2 → 1.40.1
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/dist/constants/hybridConstants.d.ts +37 -0
- package/dist/constants/hybridConstants.js +38 -0
- package/dist/constants/hybridConstants.js.map +1 -0
- package/dist/functions/hybrid/createBridgeMessage.d.ts +25 -0
- package/dist/functions/hybrid/createBridgeMessage.js +33 -0
- package/dist/functions/hybrid/createBridgeMessage.js.map +1 -0
- package/dist/functions/hybrid/detectBridgeEnvironment.d.ts +11 -0
- package/dist/functions/hybrid/detectBridgeEnvironment.js +26 -0
- package/dist/functions/hybrid/detectBridgeEnvironment.js.map +1 -0
- package/dist/functions/hybrid/generateBridgeMessageId.d.ts +10 -0
- package/dist/functions/hybrid/generateBridgeMessageId.js +11 -0
- package/dist/functions/hybrid/generateBridgeMessageId.js.map +1 -0
- package/dist/functions/hybrid/postBridgeMessage.d.ts +16 -0
- package/dist/functions/hybrid/postBridgeMessage.js +68 -0
- package/dist/functions/hybrid/postBridgeMessage.js.map +1 -0
- package/dist/functions/hybrid/validateBridgeMessage.d.ts +5 -0
- package/dist/functions/hybrid/validateBridgeMessage.js +55 -0
- package/dist/functions/hybrid/validateBridgeMessage.js.map +1 -0
- package/dist/functions/ios/integrateThirdPartyModule.js +1 -44
- package/dist/functions/ios/integrateThirdPartyModule.js.map +1 -1
- package/dist/functions/ios/modifyInfoPlistKeyValue.d.ts +2 -0
- package/dist/functions/ios/modifyInfoPlistKeyValue.js +45 -0
- package/dist/functions/ios/modifyInfoPlistKeyValue.js.map +1 -0
- package/dist/functions/ios/safelyModifyProjectPbxproj.d.ts +16 -0
- package/dist/functions/ios/safelyModifyProjectPbxproj.js +87 -0
- package/dist/functions/ios/safelyModifyProjectPbxproj.js.map +1 -0
- package/dist/functions/uniapp/app-plus/buildAndroidApp.d.ts +1 -0
- package/dist/functions/uniapp/app-plus/buildAndroidApp.js +190 -111
- package/dist/functions/uniapp/app-plus/buildAndroidApp.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildAndroidPlugin.d.ts +3 -0
- package/dist/functions/uniapp/app-plus/buildAndroidPlugin.js +501 -0
- package/dist/functions/uniapp/app-plus/buildAndroidPlugin.js.map +1 -0
- package/dist/functions/uniapp/app-plus/buildIOSApp.d.ts +2 -2
- package/dist/functions/uniapp/app-plus/buildIOSApp.js +94 -521
- package/dist/functions/uniapp/app-plus/buildIOSApp.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildIOSPlugin.d.ts +3 -0
- package/dist/functions/uniapp/app-plus/buildIOSPlugin.js +383 -0
- package/dist/functions/uniapp/app-plus/buildIOSPlugin.js.map +1 -0
- package/dist/hybrid/constants.d.ts +37 -0
- package/dist/hybrid/constants.js +38 -0
- package/dist/hybrid/constants.js.map +1 -0
- package/dist/hybrid/createBridgeMessage.d.ts +17 -0
- package/dist/hybrid/createBridgeMessage.js +81 -0
- package/dist/hybrid/createBridgeMessage.js.map +1 -0
- package/dist/hybrid/types.d.ts +88 -0
- package/dist/hybrid/types.js +2 -0
- package/dist/hybrid/types.js.map +1 -0
- package/dist/vue-hooks/browser/useBridgeMessage.d.ts +34 -0
- package/dist/vue-hooks/browser/useBridgeMessage.js +87 -0
- package/dist/vue-hooks/browser/useBridgeMessage.js.map +1 -0
- package/dist/vue-hooks/browser/useWechatJSSDK.d.ts +2 -0
- package/dist/vue-hooks/browser/useWechatJSSDK.js +16 -1
- package/dist/vue-hooks/browser/useWechatJSSDK.js.map +1 -1
- package/package.json +13 -3
- package/references/hybrid.d.ts +83 -0
- package/types/hybrid.d.ts +119 -0
- package/types/uniapp-android-build.d.ts +25 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function modifyInfoPlistKeyValue(xmlDoc, keyName, value, valueType = 'string') {
|
|
2
|
+
const dictElement = xmlDoc.getElementsByTagName('dict')[0];
|
|
3
|
+
if (!dictElement)
|
|
4
|
+
return false;
|
|
5
|
+
const childNodes = Array.from(dictElement.childNodes || []).filter((node) => node.nodeType === 1);
|
|
6
|
+
let found = false;
|
|
7
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
8
|
+
const node = childNodes[i];
|
|
9
|
+
if (node.nodeName === 'key' && node.textContent === keyName) {
|
|
10
|
+
if (i + 1 < childNodes.length) {
|
|
11
|
+
const valueNode = childNodes[i + 1];
|
|
12
|
+
if (valueType === 'string' && valueNode.nodeName === 'string') {
|
|
13
|
+
valueNode.textContent = String(value);
|
|
14
|
+
found = true;
|
|
15
|
+
}
|
|
16
|
+
else if ((valueType === 'true' || valueType === 'false') && (valueNode.nodeName === 'true' || valueNode.nodeName === 'false')) {
|
|
17
|
+
const newElement = xmlDoc.createElement(valueType);
|
|
18
|
+
const parentNode = valueNode.parentNode;
|
|
19
|
+
if (parentNode && 'replaceChild' in parentNode) {
|
|
20
|
+
parentNode.replaceChild(newElement, valueNode);
|
|
21
|
+
}
|
|
22
|
+
found = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!found) {
|
|
29
|
+
const keyElement = xmlDoc.createElement('key');
|
|
30
|
+
keyElement.textContent = keyName;
|
|
31
|
+
let valueElement;
|
|
32
|
+
if (valueType === 'string') {
|
|
33
|
+
valueElement = xmlDoc.createElement('string');
|
|
34
|
+
valueElement.textContent = String(value);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
valueElement = xmlDoc.createElement(valueType);
|
|
38
|
+
}
|
|
39
|
+
dictElement.appendChild(keyElement);
|
|
40
|
+
dictElement.appendChild(valueElement);
|
|
41
|
+
found = true;
|
|
42
|
+
}
|
|
43
|
+
return found;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=modifyInfoPlistKeyValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modifyInfoPlistKeyValue.js","sourceRoot":"","sources":["../../../src/functions/ios/modifyInfoPlistKeyValue.ts"],"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,CAAC,SAAS,CAAC,CAAA;oBAClD,MAAM,UAAU,GAAG,SAAS,CAAC,UAA+B,CAAA;oBAC5D,IAAI,UAAU,IAAI,cAAc,IAAI,UAAU,EAAE,CAAC;wBAC9C,UAAkB,CAAC,YAAY,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;oBACzD,CAAC;oBACD,KAAK,GAAG,IAAI,CAAA;gBACd,CAAC;YACH,CAAC;YACD,MAAK;QACP,CAAC;IACH,CAAC;IAGD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QAC9C,UAAU,CAAC,WAAW,GAAG,OAAO,CAAA;QAChC,IAAI,YAAwB,CAAA;QAC5B,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC3B,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;YAC7C,YAAY,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QAC1C,CAAC;aAAM,CAAC;YACN,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;QAChD,CAAC;QACD,WAAW,CAAC,WAAW,CAAC,UAAU,CAAC,CAAA;QACnC,WAAW,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;QACrC,KAAK,GAAG,IAAI,CAAA;IACd,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileSystem } from '../../../references/node.d';
|
|
2
|
+
export declare function safelyModifyProjectPbxproj(projectPbxprojPath: string, options: {
|
|
3
|
+
bundleId?: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
buildNumber?: string;
|
|
6
|
+
teamId?: string;
|
|
7
|
+
codeSignIdentity?: string;
|
|
8
|
+
clearProvisioningProfile?: boolean;
|
|
9
|
+
}, deps: {
|
|
10
|
+
existsSync: FileSystem['existsSync'];
|
|
11
|
+
readFileSync: FileSystem['readFileSync'];
|
|
12
|
+
writeFileSync: FileSystem['writeFileSync'];
|
|
13
|
+
}): {
|
|
14
|
+
success: boolean;
|
|
15
|
+
error?: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export function safelyModifyProjectPbxproj(projectPbxprojPath, options, deps) {
|
|
2
|
+
try {
|
|
3
|
+
if (!deps.existsSync(projectPbxprojPath)) {
|
|
4
|
+
return { success: false, error: `project.pbxproj 文件不存在: ${projectPbxprojPath}` };
|
|
5
|
+
}
|
|
6
|
+
let content = deps.readFileSync(projectPbxprojPath, 'utf8');
|
|
7
|
+
let modified = false;
|
|
8
|
+
const checkAndReplace = (regex, newValue) => {
|
|
9
|
+
const match = content.match(regex);
|
|
10
|
+
if (match) {
|
|
11
|
+
const currentValue = match[0].replace(/^\s*\w+\s*=\s*/, '').replace(/;\s*$/, '').replace(/^["']|["']$/g, '');
|
|
12
|
+
if (currentValue !== newValue) {
|
|
13
|
+
content = content.replace(regex, newValue);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
if (options.bundleId) {
|
|
20
|
+
const bundleIdRegex = /PRODUCT_BUNDLE_IDENTIFIER\s*=\s*[^;]+;/g;
|
|
21
|
+
if (checkAndReplace(bundleIdRegex, `PRODUCT_BUNDLE_IDENTIFIER = ${options.bundleId};`)) {
|
|
22
|
+
modified = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (options.version) {
|
|
26
|
+
const marketingVersionRegex = /MARKETING_VERSION\s*=\s*[^;]+;/g;
|
|
27
|
+
if (checkAndReplace(marketingVersionRegex, `MARKETING_VERSION = ${options.version};`)) {
|
|
28
|
+
modified = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (options.buildNumber) {
|
|
32
|
+
const currentProjectVersionRegex = /CURRENT_PROJECT_VERSION\s*=\s*[^;]+;/g;
|
|
33
|
+
if (checkAndReplace(currentProjectVersionRegex, `CURRENT_PROJECT_VERSION = ${options.buildNumber};`)) {
|
|
34
|
+
modified = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (options.teamId) {
|
|
38
|
+
const devTeamRegex = /DEVELOPMENT_TEAM\s*=\s*[^;]+;/g;
|
|
39
|
+
if (checkAndReplace(devTeamRegex, `DEVELOPMENT_TEAM = ${options.teamId};`)) {
|
|
40
|
+
modified = true;
|
|
41
|
+
}
|
|
42
|
+
const devTeamSdkRegex = /"DEVELOPMENT_TEAM\[sdk=iphoneos\*\]"\s*=\s*[^;]+;/g;
|
|
43
|
+
if (checkAndReplace(devTeamSdkRegex, `"DEVELOPMENT_TEAM[sdk=iphoneos*]" = ${options.teamId};`)) {
|
|
44
|
+
modified = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (options.codeSignIdentity) {
|
|
48
|
+
const identity = options.codeSignIdentity;
|
|
49
|
+
const codeSignIdentityRegex = /CODE_SIGN_IDENTITY\s*=\s*"[^"]*";/g;
|
|
50
|
+
if (checkAndReplace(codeSignIdentityRegex, `CODE_SIGN_IDENTITY = "${identity}";`)) {
|
|
51
|
+
modified = true;
|
|
52
|
+
}
|
|
53
|
+
const codeSignIdentitySdkRegex = /"CODE_SIGN_IDENTITY\[sdk=iphoneos\*\]"\s*=\s*"[^"]*";/g;
|
|
54
|
+
if (checkAndReplace(codeSignIdentitySdkRegex, `"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "${identity}";`)) {
|
|
55
|
+
modified = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (options.clearProvisioningProfile !== false) {
|
|
59
|
+
const provProfileRegex = /PROVISIONING_PROFILE\s*=\s*"[^"]*";/g;
|
|
60
|
+
if (provProfileRegex.test(content)) {
|
|
61
|
+
content = content.replace(provProfileRegex, `PROVISIONING_PROFILE = "";`);
|
|
62
|
+
modified = true;
|
|
63
|
+
}
|
|
64
|
+
const provProfileSpecifierRegex = /PROVISIONING_PROFILE_SPECIFIER\s*=\s*"[^"]*";/g;
|
|
65
|
+
if (provProfileSpecifierRegex.test(content)) {
|
|
66
|
+
content = content.replace(provProfileSpecifierRegex, `PROVISIONING_PROFILE_SPECIFIER = "";`);
|
|
67
|
+
modified = true;
|
|
68
|
+
}
|
|
69
|
+
const provProfileSpecifierSdkRegex = /"PROVISIONING_PROFILE_SPECIFIER\[sdk=iphoneos\*\]"\s*=\s*"[^"]*";/g;
|
|
70
|
+
if (provProfileSpecifierSdkRegex.test(content)) {
|
|
71
|
+
content = content.replace(provProfileSpecifierSdkRegex, `"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "";`);
|
|
72
|
+
modified = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (modified) {
|
|
76
|
+
deps.writeFileSync(projectPbxprojPath, content, 'utf8');
|
|
77
|
+
}
|
|
78
|
+
return { success: true };
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: `修改 project.pbxproj 失败: ${error instanceof Error ? error.message : String(error)}`
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=safelyModifyProjectPbxproj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safelyModifyProjectPbxproj.js","sourceRoot":"","sources":["../../../src/functions/ios/safelyModifyProjectPbxproj.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,0BAA0B,CACxC,kBAA0B,EAC1B,OAaC,EACD,IAOC;IAED,IAAI,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACzC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,0BAA0B,kBAAkB,EAAE,EAAE,CAAA;QAClF,CAAC;QAED,IAAI,OAAO,GAAG,IAAI,CAAC,YAAY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CAAA;YAClF,IAAI,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5C,OAAO,GAAG,OAAO,CAAC,OAAO,CACvB,yBAAyB,EACzB,sCAAsC,CACvC,CAAA;gBACD,QAAQ,GAAG,IAAI,CAAA;YACjB,CAAC;YAED,MAAM,4BAA4B,GAChC,oEAAoE,CAAA;YACtE,IAAI,4BAA4B,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/C,OAAO,GAAG,OAAO,CAAC,OAAO,CACvB,4BAA4B,EAC5B,uDAAuD,CACxD,CAAA;gBACD,QAAQ,GAAG,IAAI,CAAA;YACjB,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QACzD,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAC1F,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -98,66 +98,47 @@ export async function buildAndroidApp(options, deps) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
logs.push('配置 AndroidManifest.xml');
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
const shouldResolveAllowBackupConflict = options.resolveAllowBackupConflict !== false;
|
|
116
|
-
if (shouldResolveAllowBackupConflict) {
|
|
117
|
-
manifestModifications.push({
|
|
118
|
-
xpath: "//manifest",
|
|
119
|
-
action: 'setAttribute',
|
|
120
|
-
attributeName: 'xmlns:tools',
|
|
121
|
-
value: 'http://schemas.android.com/tools'
|
|
122
|
-
});
|
|
123
|
-
manifestModifications.push({
|
|
124
|
-
xpath: "//application",
|
|
125
|
-
action: 'setAttribute',
|
|
126
|
-
attributeName: 'tools:replace',
|
|
127
|
-
value: 'android:allowBackup'
|
|
128
|
-
});
|
|
129
|
-
logs.push('已添加 allowBackup 冲突解决方案');
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
logs.push('跳过 allowBackup 冲突解决方案');
|
|
133
|
-
}
|
|
134
|
-
manifestModifications.push({
|
|
135
|
-
xpath: "//meta-data[@android:name='DCLOUD_STREAMAPP_CHANNEL']",
|
|
136
|
-
action: 'removeElement'
|
|
137
|
-
});
|
|
138
|
-
manifestModifications.push({
|
|
139
|
-
xpath: "//application",
|
|
140
|
-
action: 'addElement',
|
|
141
|
-
elementName: 'meta-data',
|
|
142
|
-
attributes: {
|
|
143
|
-
'android:name': 'DCLOUD_STREAMAPP_CHANNEL',
|
|
144
|
-
'android:value': 'google'
|
|
101
|
+
const checkElementExists = (manifestPath, xpath) => {
|
|
102
|
+
if (!deps.existsSync(manifestPath))
|
|
103
|
+
return false;
|
|
104
|
+
try {
|
|
105
|
+
const xmlContent = deps.readFileSync(manifestPath, 'utf8');
|
|
106
|
+
const parser = new deps.xmlParser();
|
|
107
|
+
const xmlDoc = parser.parseFromString(xmlContent, 'text/xml');
|
|
108
|
+
const select = deps.xpath.useNamespaces({
|
|
109
|
+
'android': 'http://schemas.android.com/apk/res/android',
|
|
110
|
+
'tools': 'http://schemas.android.com/tools'
|
|
111
|
+
});
|
|
112
|
+
const result = select(xpath, xmlDoc);
|
|
113
|
+
return Array.isArray(result) ? result.length > 0 : result !== null && result !== undefined;
|
|
145
114
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const checkAttributeExists = (manifestPath, xpath, attrName, attrValue) => {
|
|
120
|
+
if (!deps.existsSync(manifestPath))
|
|
121
|
+
return false;
|
|
122
|
+
try {
|
|
123
|
+
const xmlContent = deps.readFileSync(manifestPath, 'utf8');
|
|
124
|
+
const parser = new deps.xmlParser();
|
|
125
|
+
const xmlDoc = parser.parseFromString(xmlContent, 'text/xml');
|
|
126
|
+
const select = deps.xpath.useNamespaces({
|
|
127
|
+
'android': 'http://schemas.android.com/apk/res/android',
|
|
128
|
+
'tools': 'http://schemas.android.com/tools'
|
|
129
|
+
});
|
|
130
|
+
const elements = select(xpath, xmlDoc);
|
|
131
|
+
if (Array.isArray(elements) && elements.length > 0) {
|
|
132
|
+
const element = elements[0];
|
|
133
|
+
const existingValue = element.getAttribute(attrName);
|
|
134
|
+
return existingValue === attrValue;
|
|
158
135
|
}
|
|
159
|
-
|
|
160
|
-
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
161
142
|
const allModules = detectAllAndroidModules(options.projectPath, {
|
|
162
143
|
readdirSync: deps.readdirSync,
|
|
163
144
|
statSync: deps.statSync,
|
|
@@ -166,43 +147,91 @@ export async function buildAndroidApp(options, deps) {
|
|
|
166
147
|
});
|
|
167
148
|
logs.push(`检测到 ${allModules.length} 个Android模块: ${allModules.join(', ')}`);
|
|
168
149
|
let manifestConfigured = false;
|
|
169
|
-
|
|
150
|
+
const modulesToProcess = allModules.length > 0 ? allModules : [projectStructure.moduleDir];
|
|
151
|
+
for (const moduleDir of modulesToProcess) {
|
|
170
152
|
const manifestPath = deps.join(options.projectPath, moduleDir, 'src', 'main', 'AndroidManifest.xml');
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
153
|
+
const moduleModifications = [];
|
|
154
|
+
const shouldFixAndroidNamespace = options.fixAndroidNamespace !== false;
|
|
155
|
+
if (shouldFixAndroidNamespace) {
|
|
156
|
+
if (!checkAttributeExists(manifestPath, "//manifest", 'xmlns:android', 'http://schemas.android.com/apk/res/android')) {
|
|
157
|
+
moduleModifications.push({
|
|
158
|
+
xpath: "//manifest",
|
|
159
|
+
action: 'setAttribute',
|
|
160
|
+
attributeName: 'xmlns:android',
|
|
161
|
+
value: 'http://schemas.android.com/apk/res/android'
|
|
162
|
+
});
|
|
163
|
+
}
|
|
182
164
|
}
|
|
183
|
-
|
|
184
|
-
|
|
165
|
+
const shouldResolveAllowBackupConflict = options.resolveAllowBackupConflict !== false;
|
|
166
|
+
if (shouldResolveAllowBackupConflict) {
|
|
167
|
+
if (!checkAttributeExists(manifestPath, "//manifest", 'xmlns:tools', 'http://schemas.android.com/tools')) {
|
|
168
|
+
moduleModifications.push({
|
|
169
|
+
xpath: "//manifest",
|
|
170
|
+
action: 'setAttribute',
|
|
171
|
+
attributeName: 'xmlns:tools',
|
|
172
|
+
value: 'http://schemas.android.com/tools'
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (!checkAttributeExists(manifestPath, "//application", 'tools:replace', 'android:allowBackup')) {
|
|
176
|
+
moduleModifications.push({
|
|
177
|
+
xpath: "//application",
|
|
178
|
+
action: 'setAttribute',
|
|
179
|
+
attributeName: 'tools:replace',
|
|
180
|
+
value: 'android:allowBackup'
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (!checkAttributeExists(manifestPath, "//application", 'android:allowBackup', 'true')) {
|
|
184
|
+
moduleModifications.push({
|
|
185
|
+
xpath: "//application",
|
|
186
|
+
action: 'setAttribute',
|
|
187
|
+
attributeName: 'android:allowBackup',
|
|
188
|
+
value: 'true'
|
|
189
|
+
});
|
|
190
|
+
}
|
|
185
191
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
if (!
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
192
|
+
if (!checkElementExists(manifestPath, "//meta-data[@android:name='DCLOUD_STREAMAPP_CHANNEL']")) {
|
|
193
|
+
moduleModifications.push({
|
|
194
|
+
xpath: "//application",
|
|
195
|
+
action: 'addElement',
|
|
196
|
+
elementName: 'meta-data',
|
|
197
|
+
attributes: {
|
|
198
|
+
'android:name': 'DCLOUD_STREAMAPP_CHANNEL',
|
|
199
|
+
'android:value': 'google'
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (options.appkey && !checkElementExists(manifestPath, "//meta-data[@android:name='dcloud_appkey']")) {
|
|
204
|
+
moduleModifications.push({
|
|
205
|
+
xpath: "//application",
|
|
206
|
+
action: 'addElement',
|
|
207
|
+
elementName: 'meta-data',
|
|
208
|
+
attributes: {
|
|
209
|
+
'android:name': 'dcloud_appkey',
|
|
210
|
+
'android:value': options.appkey
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (moduleModifications.length > 0) {
|
|
215
|
+
const manifestResult = await modifyManifest(manifestPath, moduleModifications, {
|
|
216
|
+
existsSync: deps.existsSync,
|
|
217
|
+
readFileSync: deps.readFileSync,
|
|
218
|
+
writeFileSync: deps.writeFileSync,
|
|
219
|
+
xmlParser: deps.xmlParser,
|
|
220
|
+
xmlSerializer: deps.xmlSerializer,
|
|
221
|
+
xpath: deps.xpath
|
|
222
|
+
});
|
|
223
|
+
if (manifestResult.success) {
|
|
224
|
+
logs.push(`${moduleDir} 模块的 AndroidManifest.xml 配置完成(应用了 ${moduleModifications.length} 个修改)`);
|
|
225
|
+
manifestConfigured = true;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
logs.push(`${moduleDir} 模块的 AndroidManifest.xml 配置失败: ${manifestResult.error}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
logs.push(`${moduleDir} 模块的 AndroidManifest.xml 无需修改(所有配置已存在)`);
|
|
233
|
+
manifestConfigured = true;
|
|
203
234
|
}
|
|
204
|
-
logs.push('AndroidManifest.xml 配置完成');
|
|
205
|
-
manifestConfigured = true;
|
|
206
235
|
}
|
|
207
236
|
if (!manifestConfigured) {
|
|
208
237
|
return {
|
|
@@ -307,9 +336,21 @@ export async function buildAndroidApp(options, deps) {
|
|
|
307
336
|
const hbuilderElements = xmlDoc.getElementsByTagName('hbuilder');
|
|
308
337
|
if (hbuilderElements.length > 0) {
|
|
309
338
|
const hbuilderElement = hbuilderElements[0];
|
|
310
|
-
|
|
311
|
-
hbuilderElement.
|
|
312
|
-
|
|
339
|
+
let hasChanges = false;
|
|
340
|
+
if (hbuilderElement.getAttribute('debug') !== 'true') {
|
|
341
|
+
hbuilderElement.setAttribute('debug', 'true');
|
|
342
|
+
hasChanges = true;
|
|
343
|
+
}
|
|
344
|
+
if (hbuilderElement.getAttribute('syncDebug') !== 'true') {
|
|
345
|
+
hbuilderElement.setAttribute('syncDebug', 'true');
|
|
346
|
+
hasChanges = true;
|
|
347
|
+
}
|
|
348
|
+
if (hasChanges) {
|
|
349
|
+
logs.push('已添加自定义基座配置:debug="true" syncDebug="true"');
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
logs.push('自定义基座配置已存在,无需修改');
|
|
353
|
+
}
|
|
313
354
|
}
|
|
314
355
|
else {
|
|
315
356
|
logs.push('警告:未找到 hbuilder 根节点,无法添加自定义基座配置');
|
|
@@ -319,23 +360,55 @@ export async function buildAndroidApp(options, deps) {
|
|
|
319
360
|
if (appsElements.length > 0) {
|
|
320
361
|
const appsElement = appsElements[0];
|
|
321
362
|
const existingAppElements = appsElement.getElementsByTagName('app');
|
|
322
|
-
|
|
323
|
-
|
|
363
|
+
let appExists = false;
|
|
364
|
+
let hasChanges = false;
|
|
365
|
+
for (let i = 0; i < existingAppElements.length; i++) {
|
|
366
|
+
const appElement = existingAppElements[i];
|
|
367
|
+
if (appElement.getAttribute('appid') === manifest.appid) {
|
|
368
|
+
appExists = true;
|
|
369
|
+
if (appElement.getAttribute('appver') !== '') {
|
|
370
|
+
appElement.setAttribute('appver', '');
|
|
371
|
+
hasChanges = true;
|
|
372
|
+
}
|
|
373
|
+
if (options.appkey && appElement.getAttribute('appkey') !== options.appkey) {
|
|
374
|
+
appElement.setAttribute('appkey', options.appkey);
|
|
375
|
+
hasChanges = true;
|
|
376
|
+
logs.push(`更新 appkey: ${options.appkey}`);
|
|
377
|
+
}
|
|
378
|
+
if (hasChanges) {
|
|
379
|
+
logs.push(`更新现有 app 元素,appid: ${manifest.appid}`);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
logs.push(`app 元素已存在且配置正确,appid: ${manifest.appid}`);
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (!appExists) {
|
|
388
|
+
while (existingAppElements.length > 0) {
|
|
389
|
+
appsElement.removeChild(existingAppElements[0]);
|
|
390
|
+
}
|
|
391
|
+
logs.push('已删除所有现有的 app 元素');
|
|
392
|
+
const newAppElement = xmlDoc.createElement('app');
|
|
393
|
+
newAppElement.setAttribute('appid', manifest.appid);
|
|
394
|
+
newAppElement.setAttribute('appver', '');
|
|
395
|
+
if (options.appkey) {
|
|
396
|
+
newAppElement.setAttribute('appkey', options.appkey);
|
|
397
|
+
logs.push(`设置 appkey: ${options.appkey}`);
|
|
398
|
+
}
|
|
399
|
+
appsElement.appendChild(newAppElement);
|
|
400
|
+
logs.push(`添加新的 app 元素,appid: ${manifest.appid}`);
|
|
401
|
+
hasChanges = true;
|
|
324
402
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
403
|
+
if (hasChanges || !appExists) {
|
|
404
|
+
const serializer = new deps.xmlSerializer();
|
|
405
|
+
const newXmlContent = serializer.serializeToString(xmlDoc);
|
|
406
|
+
deps.writeFileSync(dcloudControlXmlPath, newXmlContent, 'utf8');
|
|
407
|
+
logs.push('dcloud_control.xml 配置完成');
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
logs.push('dcloud_control.xml 无需修改');
|
|
332
411
|
}
|
|
333
|
-
appsElement.appendChild(newAppElement);
|
|
334
|
-
logs.push(`添加新的 app 元素,appid: ${manifest.appid}`);
|
|
335
|
-
const serializer = new deps.xmlSerializer();
|
|
336
|
-
const newXmlContent = serializer.serializeToString(xmlDoc);
|
|
337
|
-
deps.writeFileSync(dcloudControlXmlPath, newXmlContent, 'utf8');
|
|
338
|
-
logs.push('dcloud_control.xml 配置完成');
|
|
339
412
|
}
|
|
340
413
|
else {
|
|
341
414
|
logs.push('dcloud_control.xml 中未找到 apps 元素');
|
|
@@ -380,8 +453,13 @@ export async function buildAndroidApp(options, deps) {
|
|
|
380
453
|
logs.push(`创建 libs 目录: ${libsDir}`);
|
|
381
454
|
}
|
|
382
455
|
const targetPath = deps.join(libsDir, 'debug-server-release.aar');
|
|
383
|
-
deps.
|
|
384
|
-
|
|
456
|
+
if (deps.existsSync(targetPath)) {
|
|
457
|
+
logs.push(`debug-server-release.aar 已存在,跳过复制: ${targetPath}`);
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
deps.copyFileSync(debugServerAarPath, targetPath);
|
|
461
|
+
logs.push(`已复制 debug-server-release.aar: ${debugServerAarPath} -> ${targetPath}`);
|
|
462
|
+
}
|
|
385
463
|
}
|
|
386
464
|
}
|
|
387
465
|
catch (error) {
|
|
@@ -729,4 +807,5 @@ export async function buildAndroidApp(options, deps) {
|
|
|
729
807
|
};
|
|
730
808
|
}
|
|
731
809
|
}
|
|
810
|
+
export { buildAndroidPlugin } from './buildAndroidPlugin';
|
|
732
811
|
//# sourceMappingURL=buildAndroidApp.js.map
|