@capacitor/cli 9.0.0-nightly-20260210T152917.0 → 9.0.0-rc.0
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/assets/android-template.tar.gz +0 -0
- package/assets/capacitor-cordova-android-plugins.tar.gz +0 -0
- package/assets/capacitor-cordova-ios-plugins.tar.gz +0 -0
- package/assets/ios-pods-template.tar.gz +0 -0
- package/assets/ios-spm-template.tar.gz +0 -0
- package/dist/android/local-network.js +123 -0
- package/dist/android/network-security-config.js +230 -0
- package/dist/android/run.js +13 -1
- package/dist/android/update.js +54 -45
- package/dist/common.js +1 -1
- package/dist/config.js +25 -9
- package/dist/cordova.js +8 -4
- package/dist/declarations.d.ts +115 -5
- package/dist/index.js +7 -21
- package/dist/ios/common.js +10 -1
- package/dist/ios/update.js +60 -342
- package/dist/ipc.js +53 -13
- package/dist/plugin.js +1 -1
- package/dist/run-context/declared.js +54 -0
- package/dist/run-context/index.js +111 -0
- package/dist/run-context/registry.js +45 -0
- package/dist/run-context/signals.js +115 -0
- package/dist/run-context/types.js +2 -0
- package/dist/run-context/unknown.js +46 -0
- package/dist/run-context/version.js +74 -0
- package/dist/tasks/copy.js +3 -1
- package/dist/tasks/doctor.js +4 -1
- package/dist/tasks/list.js +1 -1
- package/dist/tasks/migrate-debug-xcconfig.js +60 -0
- package/dist/tasks/migrate-edge-to-edge.js +158 -0
- package/dist/tasks/migrate-spm.js +0 -1
- package/dist/tasks/migrate-swiftui.js +625 -0
- package/dist/tasks/migrate-to-modern-project.js +27 -0
- package/dist/tasks/migrate.js +235 -62
- package/dist/tasks/run.js +28 -10
- package/dist/tasks/sourcemaps.js +1 -1
- package/dist/tasks/telemetry.js +8 -1
- package/dist/telemetry.js +321 -54
- package/dist/util/capacitor-package.js +246 -0
- package/dist/util/cordova-ios.js +509 -0
- package/dist/util/iosplugin.js +1 -0
- package/dist/util/js.js +1 -1
- package/dist/util/livereload.js +4 -110
- package/dist/util/monorepotools.js +2 -2
- package/dist/util/node.js +61 -6
- package/dist/util/npm.js +120 -0
- package/dist/util/spm.js +210 -38
- package/dist/util/subprocess.js +2 -2
- package/dist/util/xcode.js +239 -0
- package/dist/util/xml.js +1 -1
- package/package.json +5 -2
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grantAndroidLocalNetworkPermission = exports.setAndroidLocalNetworkDeclaration = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const os_1 = require("os");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const log_1 = require("../log");
|
|
8
|
+
const subprocess_1 = require("../util/subprocess");
|
|
9
|
+
/**
|
|
10
|
+
* Handles the Android 17 (API 37) `ACCESS_LOCAL_NETWORK` permission for live reload (`cap run --url`).
|
|
11
|
+
*
|
|
12
|
+
* Pages loaded from a local network URL (live reload, `server.url`) fail before any JavaScript runs when the
|
|
13
|
+
* permission isn't granted, so the app can't request it itself. For a live reload run the CLI declares the
|
|
14
|
+
* permission in the app manifest just for the Gradle build, then grants it with `adb` after the install.
|
|
15
|
+
*
|
|
16
|
+
* The declaration the CLI adds is tracked by a marker comment so the revert only removes what the CLI added:
|
|
17
|
+
*
|
|
18
|
+
* <!-- capacitor:local-network -->
|
|
19
|
+
* <uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
|
|
20
|
+
*/
|
|
21
|
+
const PERMISSION = 'android.permission.ACCESS_LOCAL_NETWORK';
|
|
22
|
+
const MARKER = '<!-- capacitor:local-network -->';
|
|
23
|
+
const PERMISSION_ELEMENT = `<uses-permission android:name="${PERMISSION}" />`;
|
|
24
|
+
const MARKED_BLOCK_REGEX = /[ \t]*<!--\s*capacitor:local-network\s*-->[ \t]*\r?\n[ \t]*<uses-permission\b[^>]*\/>[ \t]*\r?\n?/;
|
|
25
|
+
const MIN_API_LEVEL = 37;
|
|
26
|
+
/**
|
|
27
|
+
* Adds or removes the permission declaration the CLI owns in the app manifest.
|
|
28
|
+
* Returns `true` when the manifest holds a declaration owned by the CLI (added now, or left over from an
|
|
29
|
+
* interrupted build) that the caller should revert, `false` when there was nothing to do, for example because the
|
|
30
|
+
* app already declares the permission itself. A declaration the app owns is never removed.
|
|
31
|
+
*/
|
|
32
|
+
async function setAndroidLocalNetworkDeclaration(config, enabled) {
|
|
33
|
+
const manifestPath = (0, path_1.join)(config.android.srcMainDirAbs, 'AndroidManifest.xml');
|
|
34
|
+
if (!(await (0, fs_extra_1.pathExists)(manifestPath))) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const manifest = await (0, fs_extra_1.readFile)(manifestPath, 'utf-8');
|
|
38
|
+
if (enabled) {
|
|
39
|
+
// A marked block left behind by an interrupted build is the CLI's own, so the revert after this build removes it.
|
|
40
|
+
if (MARKED_BLOCK_REGEX.test(manifest)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (manifest.includes(PERMISSION)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const closing = manifest.lastIndexOf('</manifest>');
|
|
47
|
+
if (closing === -1) {
|
|
48
|
+
log_1.logger.warn(`Could not declare the local network permission: no </manifest> found in ${manifestPath}.`);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
await (0, fs_extra_1.writeFile)(manifestPath, `${manifest.slice(0, closing)} ${MARKER}\n ${PERMISSION_ELEMENT}\n${manifest.slice(closing)}`);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (!MARKED_BLOCK_REGEX.test(manifest)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
await (0, fs_extra_1.writeFile)(manifestPath, manifest.replace(MARKED_BLOCK_REGEX, ''));
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
exports.setAndroidLocalNetworkDeclaration = setAndroidLocalNetworkDeclaration;
|
|
61
|
+
function defaultAndroidSdkDir() {
|
|
62
|
+
switch (process.platform) {
|
|
63
|
+
case 'darwin':
|
|
64
|
+
return (0, path_1.join)((0, os_1.homedir)(), 'Library', 'Android', 'sdk');
|
|
65
|
+
case 'linux':
|
|
66
|
+
return (0, path_1.join)((0, os_1.homedir)(), 'Android', 'sdk');
|
|
67
|
+
case 'win32':
|
|
68
|
+
return (0, path_1.join)(process.env.LOCALAPPDATA || (0, path_1.join)((0, os_1.homedir)(), 'AppData', 'Local'), 'Android', 'Sdk');
|
|
69
|
+
default:
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Finds `adb` the same way native-run finds the Android SDK for the install: `ANDROID_HOME`, then
|
|
75
|
+
* `ANDROID_SDK_ROOT`, then the default SDK location of the platform. Falls back to `adb` on the PATH.
|
|
76
|
+
*/
|
|
77
|
+
async function resolveAdb() {
|
|
78
|
+
const sdkRoots = [process.env.ANDROID_HOME, process.env.ANDROID_SDK_ROOT, defaultAndroidSdkDir()];
|
|
79
|
+
const adbName = process.platform === 'win32' ? 'adb.exe' : 'adb';
|
|
80
|
+
for (const sdkRoot of sdkRoots) {
|
|
81
|
+
if (!sdkRoot) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const adbPath = (0, path_1.join)(sdkRoot, 'platform-tools', adbName);
|
|
85
|
+
if (await (0, fs_extra_1.pathExists)(adbPath)) {
|
|
86
|
+
return adbPath;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return 'adb';
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Grants the permission to the installed app and relaunches it, since the first page load already failed.
|
|
93
|
+
* Does nothing below Android 17, where the permission doesn't exist.
|
|
94
|
+
*/
|
|
95
|
+
async function grantAndroidLocalNetworkPermission(config, targetId) {
|
|
96
|
+
const adb = await resolveAdb();
|
|
97
|
+
const appId = config.app.appId;
|
|
98
|
+
try {
|
|
99
|
+
const apiLevel = parseInt((await (0, subprocess_1.runCommand)(adb, ['-s', targetId, 'shell', 'getprop', 'ro.build.version.sdk'])).trim(), 10);
|
|
100
|
+
if (apiLevel < MIN_API_LEVEL) {
|
|
101
|
+
log_1.logger.info(`Skipping the local network permission: it only exists on Android 17 (API ${MIN_API_LEVEL}) and later.`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
await (0, subprocess_1.runCommand)(adb, ['-s', targetId, 'shell', 'pm', 'grant', appId, PERMISSION]);
|
|
105
|
+
log_1.logger.info(`Granted the local network permission to ${appId} for this live reload run. Your app still needs to declare and request it to reach the local network in production.`);
|
|
106
|
+
await (0, subprocess_1.runCommand)(adb, ['-s', targetId, 'shell', 'am', 'force-stop', appId]);
|
|
107
|
+
await (0, subprocess_1.runCommand)(adb, [
|
|
108
|
+
'-s',
|
|
109
|
+
targetId,
|
|
110
|
+
'shell',
|
|
111
|
+
'monkey',
|
|
112
|
+
'-p',
|
|
113
|
+
appId,
|
|
114
|
+
'-c',
|
|
115
|
+
'android.intent.category.LAUNCHER',
|
|
116
|
+
'1',
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
log_1.logger.warn(`Could not grant the local network permission to ${appId}: ${e}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.grantAndroidLocalNetworkPermission = grantAndroidLocalNetworkPermission;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__testables = exports.removeLegacyCordovaPluginsConfig = exports.setAndroidCleartext = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const log_1 = require("../log");
|
|
7
|
+
/**
|
|
8
|
+
* Handles opting in to cleartext (HTTP) traffic through the app module's `network-security-config.xml`.
|
|
9
|
+
*
|
|
10
|
+
* Whatever the CLI changes is tracked by a marker comment inside the config file itself, so it can be
|
|
11
|
+
* reverted later without touching anything the app owned before:
|
|
12
|
+
*
|
|
13
|
+
* <!-- capacitor:cleartext created ref orig=false -->
|
|
14
|
+
*
|
|
15
|
+
* created the CLI created the file (the revert deletes it)
|
|
16
|
+
* ref the CLI added android:networkSecurityConfig to the app manifest (the revert removes it)
|
|
17
|
+
* orig=... state of <base-config cleartextTrafficPermitted> before the CLI changed it:
|
|
18
|
+
* true | false | absent (attribute not set) | added (the CLI added the whole <base-config>)
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_CONFIG_NAME = 'network_security_config';
|
|
21
|
+
const MARKER_NAME = 'capacitor:cleartext';
|
|
22
|
+
const MARKER_REGEX = new RegExp(`[ \\t]*<!--\\s*${MARKER_NAME}([^>]*?)-->[ \\t]*\\r?\\n?`);
|
|
23
|
+
const BASE_CONFIG_REGEX = /<base-config\b[^>]*>/;
|
|
24
|
+
const CLEARTEXT_ATTR_REGEX = /(\bcleartextTrafficPermitted\s*=\s*)(["'])(.*?)\2/;
|
|
25
|
+
const ROOT_REGEX = /<network-security-config\b[^>]*?(\/?)>/;
|
|
26
|
+
const APPLICATION_REGEX = /<application\b/;
|
|
27
|
+
const CONFIG_REF_REGEX = /android:networkSecurityConfig\s*=\s*"@xml\/([^"]+)"/;
|
|
28
|
+
const LEGACY_CORDOVA_PLUGINS_CONFIG = `<?xml version="1.0" encoding="utf-8"?>
|
|
29
|
+
<network-security-config>
|
|
30
|
+
<base-config cleartextTrafficPermitted="true" />
|
|
31
|
+
</network-security-config>
|
|
32
|
+
`;
|
|
33
|
+
function parseMarker(xml) {
|
|
34
|
+
var _a;
|
|
35
|
+
const match = MARKER_REGEX.exec(xml);
|
|
36
|
+
if (!match) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const tokens = match[1].trim().split(/\s+/);
|
|
40
|
+
const orig = (_a = tokens.find((t) => t.startsWith('orig='))) === null || _a === void 0 ? void 0 : _a.slice('orig='.length);
|
|
41
|
+
return { created: tokens.includes('created'), ref: tokens.includes('ref'), orig };
|
|
42
|
+
}
|
|
43
|
+
function buildMarker(marker) {
|
|
44
|
+
const parts = [MARKER_NAME];
|
|
45
|
+
if (marker.created) {
|
|
46
|
+
parts.push('created');
|
|
47
|
+
}
|
|
48
|
+
if (marker.ref) {
|
|
49
|
+
parts.push('ref');
|
|
50
|
+
}
|
|
51
|
+
if (marker.orig) {
|
|
52
|
+
parts.push(`orig=${marker.orig}`);
|
|
53
|
+
}
|
|
54
|
+
return `<!-- ${parts.join(' ')} -->`;
|
|
55
|
+
}
|
|
56
|
+
function getCleartextValue(tag) {
|
|
57
|
+
var _a;
|
|
58
|
+
return (_a = CLEARTEXT_ATTR_REGEX.exec(tag)) === null || _a === void 0 ? void 0 : _a[3];
|
|
59
|
+
}
|
|
60
|
+
function setCleartextValue(tag, value) {
|
|
61
|
+
const hasAttr = CLEARTEXT_ATTR_REGEX.test(tag);
|
|
62
|
+
if (value === undefined) {
|
|
63
|
+
return hasAttr ? tag.replace(new RegExp(`\\s*${CLEARTEXT_ATTR_REGEX.source}`), '') : tag;
|
|
64
|
+
}
|
|
65
|
+
if (hasAttr) {
|
|
66
|
+
return tag.replace(CLEARTEXT_ATTR_REGEX, `$1$2${value}$2`);
|
|
67
|
+
}
|
|
68
|
+
return tag.replace(/\s*(\/?)>$/, (_, slash) => ` cleartextTrafficPermitted="${value}"${slash ? ' />' : '>'}`);
|
|
69
|
+
}
|
|
70
|
+
function indentOf(xml, index) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const lineStart = xml.lastIndexOf('\n', index - 1) + 1;
|
|
73
|
+
return (_b = (_a = /^[ \t]*/.exec(xml.slice(lineStart, index))) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the config XML with `cleartextTrafficPermitted="true"` on its `<base-config>`.
|
|
77
|
+
* When `xml` is undefined a minimal config is generated. Nothing else in the file is touched.
|
|
78
|
+
*/
|
|
79
|
+
function enableCleartext(xml, flags) {
|
|
80
|
+
var _a;
|
|
81
|
+
if (xml === undefined) {
|
|
82
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
83
|
+
<network-security-config>
|
|
84
|
+
${buildMarker({ created: true, ref: flags.ref })}
|
|
85
|
+
<base-config cleartextTrafficPermitted="true" />
|
|
86
|
+
</network-security-config>
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
const existing = parseMarker(xml);
|
|
90
|
+
const baseConfig = BASE_CONFIG_REGEX.exec(xml);
|
|
91
|
+
if (existing) {
|
|
92
|
+
// Already enabled by the CLI: only make sure the value is still true.
|
|
93
|
+
return baseConfig ? xml.replace(baseConfig[0], setCleartextValue(baseConfig[0], 'true')) : xml;
|
|
94
|
+
}
|
|
95
|
+
if (baseConfig) {
|
|
96
|
+
const original = (_a = getCleartextValue(baseConfig[0])) !== null && _a !== void 0 ? _a : 'absent';
|
|
97
|
+
const indent = indentOf(xml, baseConfig.index);
|
|
98
|
+
const marker = `${buildMarker({ created: false, ref: flags.ref, orig: original })}\n${indent}`;
|
|
99
|
+
return (xml.slice(0, baseConfig.index) +
|
|
100
|
+
marker +
|
|
101
|
+
setCleartextValue(baseConfig[0], 'true') +
|
|
102
|
+
xml.slice(baseConfig.index + baseConfig[0].length));
|
|
103
|
+
}
|
|
104
|
+
const root = ROOT_REGEX.exec(xml);
|
|
105
|
+
if (!root) {
|
|
106
|
+
throw new Error('missing <network-security-config> root element');
|
|
107
|
+
}
|
|
108
|
+
const marker = buildMarker({ created: false, ref: flags.ref, orig: 'added' });
|
|
109
|
+
const addition = `\n ${marker}\n <base-config cleartextTrafficPermitted="true" />`;
|
|
110
|
+
if (root[1] === '/') {
|
|
111
|
+
const open = root[0].replace(/\s*\/>$/, '>');
|
|
112
|
+
return xml.replace(root[0], `${open}${addition}\n</network-security-config>`);
|
|
113
|
+
}
|
|
114
|
+
const end = root.index + root[0].length;
|
|
115
|
+
return xml.slice(0, end) + addition + (/^\s/.test(xml.slice(end)) ? '' : '\n') + xml.slice(end);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Undoes `enableCleartext`. Returns `null` when the file should be deleted, `undefined` when the CLI
|
|
119
|
+
* never touched it, and the restored XML otherwise.
|
|
120
|
+
*/
|
|
121
|
+
function revertCleartext(xml) {
|
|
122
|
+
const marker = parseMarker(xml);
|
|
123
|
+
if (!marker) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
if (marker.created) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const withoutMarker = xml.replace(MARKER_REGEX, '');
|
|
130
|
+
const baseConfig = BASE_CONFIG_REGEX.exec(withoutMarker);
|
|
131
|
+
if (!baseConfig) {
|
|
132
|
+
return withoutMarker;
|
|
133
|
+
}
|
|
134
|
+
if (marker.orig === 'added') {
|
|
135
|
+
const isSelfClosing = baseConfig[0].endsWith('/>');
|
|
136
|
+
if (isSelfClosing) {
|
|
137
|
+
const indent = indentOf(withoutMarker, baseConfig.index);
|
|
138
|
+
return withoutMarker.replace(new RegExp(`${indent}${escapeRegex(baseConfig[0])}[ \\t]*\\r?\\n?`), '');
|
|
139
|
+
}
|
|
140
|
+
return withoutMarker.replace(baseConfig[0], setCleartextValue(baseConfig[0], 'false'));
|
|
141
|
+
}
|
|
142
|
+
const original = marker.orig === 'absent' || marker.orig === undefined ? undefined : marker.orig;
|
|
143
|
+
return withoutMarker.replace(baseConfig[0], setCleartextValue(baseConfig[0], original));
|
|
144
|
+
}
|
|
145
|
+
function escapeRegex(value) {
|
|
146
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
147
|
+
}
|
|
148
|
+
function addManifestRef(manifest) {
|
|
149
|
+
return manifest.replace(APPLICATION_REGEX, `<application android:networkSecurityConfig="@xml/${DEFAULT_CONFIG_NAME}"`);
|
|
150
|
+
}
|
|
151
|
+
function removeManifestRef(manifest) {
|
|
152
|
+
return manifest.replace(new RegExp(`\\s+android:networkSecurityConfig\\s*=\\s*"@xml/${DEFAULT_CONFIG_NAME}"`), '');
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Enables or disables cleartext traffic on the app module (`android/app`), leaving any
|
|
156
|
+
* network-security-config the app already has intact besides `cleartextTrafficPermitted`.
|
|
157
|
+
*/
|
|
158
|
+
async function setAndroidCleartext(config, enabled) {
|
|
159
|
+
var _a;
|
|
160
|
+
const manifestPath = (0, path_1.join)(config.android.srcMainDirAbs, 'AndroidManifest.xml');
|
|
161
|
+
if (!(await (0, fs_extra_1.pathExists)(manifestPath))) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const manifest = await (0, fs_extra_1.readFile)(manifestPath, 'utf-8');
|
|
165
|
+
const referencedName = (_a = CONFIG_REF_REGEX.exec(manifest)) === null || _a === void 0 ? void 0 : _a[1];
|
|
166
|
+
const configPath = (0, path_1.join)(config.android.resDirAbs, 'xml', `${referencedName !== null && referencedName !== void 0 ? referencedName : DEFAULT_CONFIG_NAME}.xml`);
|
|
167
|
+
const configExists = await (0, fs_extra_1.pathExists)(configPath);
|
|
168
|
+
if (enabled) {
|
|
169
|
+
if (referencedName && !configExists) {
|
|
170
|
+
log_1.logger.warn(`Could not enable cleartext traffic: ${manifestPath} references @xml/${referencedName}, but ${configPath} does not exist.`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const current = configExists ? await (0, fs_extra_1.readFile)(configPath, 'utf-8') : undefined;
|
|
174
|
+
const addRef = !referencedName;
|
|
175
|
+
let updated;
|
|
176
|
+
try {
|
|
177
|
+
updated = enableCleartext(current, { ref: addRef });
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
log_1.logger.warn(`Could not enable cleartext traffic: ${configPath} is not a valid network security config (${e.message}).`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
await (0, fs_extra_1.ensureDir)((0, path_1.dirname)(configPath));
|
|
184
|
+
await (0, fs_extra_1.writeFile)(configPath, updated);
|
|
185
|
+
if (addRef) {
|
|
186
|
+
await (0, fs_extra_1.writeFile)(manifestPath, addManifestRef(manifest));
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (!configExists) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const current = await (0, fs_extra_1.readFile)(configPath, 'utf-8');
|
|
194
|
+
const marker = parseMarker(current);
|
|
195
|
+
const reverted = revertCleartext(current);
|
|
196
|
+
if (reverted === undefined) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (reverted === null) {
|
|
200
|
+
await (0, fs_extra_1.remove)(configPath);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
await (0, fs_extra_1.writeFile)(configPath, reverted);
|
|
204
|
+
}
|
|
205
|
+
if ((marker === null || marker === void 0 ? void 0 : marker.ref) && referencedName === DEFAULT_CONFIG_NAME) {
|
|
206
|
+
await (0, fs_extra_1.writeFile)(manifestPath, removeManifestRef(manifest));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.setAndroidCleartext = setAndroidCleartext;
|
|
210
|
+
/**
|
|
211
|
+
* Cleartext used to be written to the generated `capacitor-cordova-android-plugins` module, where it never
|
|
212
|
+
* reached Capacitor-only apps. Removes the file generated by older CLI versions.
|
|
213
|
+
*/
|
|
214
|
+
async function removeLegacyCordovaPluginsConfig(config) {
|
|
215
|
+
const legacyPath = (0, path_1.join)(config.android.cordovaPluginsDirAbs, 'src', 'main', 'res', 'xml', `${DEFAULT_CONFIG_NAME}.xml`);
|
|
216
|
+
if (!(await (0, fs_extra_1.pathExists)(legacyPath))) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if ((await (0, fs_extra_1.readFile)(legacyPath, 'utf-8')).trim() === LEGACY_CORDOVA_PLUGINS_CONFIG.trim()) {
|
|
220
|
+
await (0, fs_extra_1.remove)(legacyPath);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.removeLegacyCordovaPluginsConfig = removeLegacyCordovaPluginsConfig;
|
|
224
|
+
exports.__testables = {
|
|
225
|
+
enableCleartext,
|
|
226
|
+
revertCleartext,
|
|
227
|
+
addManifestRef,
|
|
228
|
+
removeManifestRef,
|
|
229
|
+
parseMarker,
|
|
230
|
+
};
|
package/dist/android/run.js
CHANGED
|
@@ -8,14 +8,18 @@ const colors_1 = tslib_1.__importDefault(require("../colors"));
|
|
|
8
8
|
const common_1 = require("../common");
|
|
9
9
|
const native_run_1 = require("../util/native-run");
|
|
10
10
|
const subprocess_1 = require("../util/subprocess");
|
|
11
|
+
const local_network_1 = require("./local-network");
|
|
11
12
|
const debug = (0, debug_1.default)('capacitor:android:run');
|
|
12
|
-
async function runAndroid(config, { target: selectedTarget, targetName: selectedTargetName, targetNameSdkVersion: selectedTargetSdkVersion, flavor: selectedFlavor, forwardPorts: selectedPorts, }) {
|
|
13
|
+
async function runAndroid(config, { target: selectedTarget, targetName: selectedTargetName, targetNameSdkVersion: selectedTargetSdkVersion, flavor: selectedFlavor, forwardPorts: selectedPorts, url: liveReloadUrl, }) {
|
|
13
14
|
var _a;
|
|
14
15
|
const target = await (0, common_1.promptForPlatformTarget)(await (0, native_run_1.getPlatformTargets)('android'), selectedTarget !== null && selectedTarget !== void 0 ? selectedTarget : selectedTargetName, selectedTargetSdkVersion, selectedTargetName !== undefined);
|
|
15
16
|
const runFlavor = selectedFlavor || ((_a = config.android) === null || _a === void 0 ? void 0 : _a.flavor) || '';
|
|
16
17
|
const arg = `assemble${runFlavor}Debug`;
|
|
17
18
|
const gradleArgs = [arg];
|
|
18
19
|
debug('Invoking ./gradlew with args: %O', gradleArgs);
|
|
20
|
+
// Live reload loads the app from a local network URL, which Android 17 only allows with the local network
|
|
21
|
+
// permission. The declaration is only needed while Gradle builds the APK, so it is reverted right after the build.
|
|
22
|
+
const declaredLocalNetwork = liveReloadUrl ? await (0, local_network_1.setAndroidLocalNetworkDeclaration)(config, true) : false;
|
|
19
23
|
try {
|
|
20
24
|
await (0, common_1.runTask)('Running Gradle build', async () => (0, subprocess_1.runCommand)('./gradlew', gradleArgs, {
|
|
21
25
|
cwd: config.android.platformDirAbs,
|
|
@@ -29,6 +33,11 @@ async function runAndroid(config, { target: selectedTarget, targetName: selected
|
|
|
29
33
|
throw e;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
36
|
+
finally {
|
|
37
|
+
if (declaredLocalNetwork) {
|
|
38
|
+
await (0, local_network_1.setAndroidLocalNetworkDeclaration)(config, false);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
32
41
|
const pathToApk = `${config.android.platformDirAbs}/${config.android.appDir}/build/outputs/apk${runFlavor !== '' ? '/' + runFlavor : ''}/debug`;
|
|
33
42
|
const apkName = (0, common_1.parseApkNameFromFlavor)(runFlavor);
|
|
34
43
|
const apkPath = (0, path_1.resolve)(pathToApk, apkName);
|
|
@@ -38,5 +47,8 @@ async function runAndroid(config, { target: selectedTarget, targetName: selected
|
|
|
38
47
|
}
|
|
39
48
|
debug('Invoking native-run with args: %O', nativeRunArgs);
|
|
40
49
|
await (0, common_1.runTask)(`Deploying ${colors_1.default.strong(apkName)} to ${colors_1.default.input(target.id)}`, async () => (0, native_run_1.runNativeRun)(nativeRunArgs));
|
|
50
|
+
if (liveReloadUrl) {
|
|
51
|
+
await (0, common_1.runTask)('Setting up the local network permission', async () => (0, local_network_1.grantAndroidLocalNetworkPermission)(config, target.id));
|
|
52
|
+
}
|
|
41
53
|
}
|
|
42
54
|
exports.runAndroid = runAndroid;
|
package/dist/android/update.js
CHANGED
|
@@ -9,23 +9,30 @@ const colors_1 = tslib_1.__importDefault(require("../colors"));
|
|
|
9
9
|
const common_1 = require("../common");
|
|
10
10
|
const cordova_1 = require("../cordova");
|
|
11
11
|
const errors_1 = require("../errors");
|
|
12
|
+
const log_1 = require("../log");
|
|
12
13
|
const plugin_1 = require("../plugin");
|
|
13
14
|
const copy_1 = require("../tasks/copy");
|
|
14
15
|
const fs_1 = require("../util/fs");
|
|
15
16
|
const node_1 = require("../util/node");
|
|
16
17
|
const template_1 = require("../util/template");
|
|
17
18
|
const common_2 = require("./common");
|
|
19
|
+
const network_security_config_1 = require("./network-security-config");
|
|
18
20
|
const platform = 'android';
|
|
19
21
|
const debug = (0, debug_1.default)('capacitor:android:update');
|
|
20
22
|
async function updateAndroid(config) {
|
|
21
|
-
var _a;
|
|
23
|
+
var _a, _b;
|
|
22
24
|
const plugins = await getPluginsTask(config);
|
|
23
25
|
const capacitorPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
|
|
24
26
|
(0, plugin_1.printPlugins)(capacitorPlugins, 'android');
|
|
25
|
-
await writePluginsJson(config, capacitorPlugins);
|
|
26
|
-
await removePluginsNativeFiles(config);
|
|
27
27
|
const cordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
|
|
28
|
-
|
|
28
|
+
const enableCordova = cordovaPlugins.length > 0 || config.app.forceCordova;
|
|
29
|
+
await writePluginsJson(config, capacitorPlugins, enableCordova);
|
|
30
|
+
await removePluginsNativeFiles(config);
|
|
31
|
+
if (enableCordova) {
|
|
32
|
+
log_1.logger.info('Found Cordova Plugins: Including Android Cordova Support');
|
|
33
|
+
if (config.app.forceCordova) {
|
|
34
|
+
log_1.logger.info('Cordova support installation has been forced');
|
|
35
|
+
}
|
|
29
36
|
await copyPluginsNativeFiles(config, cordovaPlugins);
|
|
30
37
|
}
|
|
31
38
|
if (!(await (0, fs_extra_1.pathExists)(config.android.webDirAbs))) {
|
|
@@ -34,8 +41,13 @@ async function updateAndroid(config) {
|
|
|
34
41
|
await (0, cordova_1.handleCordovaPluginsJS)(cordovaPlugins, config, platform);
|
|
35
42
|
await (0, cordova_1.checkPluginDependencies)(plugins, platform, (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.failOnUninstalledPlugins);
|
|
36
43
|
await installGradlePlugins(config, capacitorPlugins, cordovaPlugins);
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
if (enableCordova) {
|
|
45
|
+
await handleCordovaPluginsGradle(config, cordovaPlugins);
|
|
46
|
+
await (0, cordova_1.writeCordovaAndroidManifest)(cordovaPlugins, config, platform);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
await (0, network_security_config_1.setAndroidCleartext)(config, !!((_b = config.app.extConfig.server) === null || _b === void 0 ? void 0 : _b.cleartext));
|
|
50
|
+
}
|
|
39
51
|
const incompatibleCordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 2 /* PluginType.Incompatible */);
|
|
40
52
|
(0, plugin_1.printPlugins)(incompatibleCordovaPlugins, platform, 'incompatible');
|
|
41
53
|
await (0, common_1.checkPlatformVersions)(config, platform);
|
|
@@ -44,8 +56,14 @@ exports.updateAndroid = updateAndroid;
|
|
|
44
56
|
function getGradlePackageName(id) {
|
|
45
57
|
return id.replace('@', '').replace('/', '-');
|
|
46
58
|
}
|
|
47
|
-
async function writePluginsJson(config, plugins) {
|
|
59
|
+
async function writePluginsJson(config, plugins, includeCordova) {
|
|
48
60
|
const classes = await findAndroidPluginClasses(plugins);
|
|
61
|
+
if (includeCordova) {
|
|
62
|
+
classes.push({
|
|
63
|
+
pkg: '@capacitor/android',
|
|
64
|
+
classpath: 'com.getcapacitor.cordova.CordovaPlugin',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
49
67
|
const pluginsJsonPath = (0, path_1.resolve)(config.android.assetsDirAbs, 'capacitor.plugins.json');
|
|
50
68
|
await (0, fs_extra_1.writeJSON)(pluginsJsonPath, classes, { spaces: '\t' });
|
|
51
69
|
}
|
|
@@ -64,7 +82,7 @@ async function findAndroidPluginClassesInPlugin(plugin) {
|
|
|
64
82
|
const srcFiles = await (0, fs_1.readdirp)(srcPath, {
|
|
65
83
|
filter: (entry) => !entry.stats.isDirectory() && ['.java', '.kt'].includes((0, path_1.extname)(entry.path)),
|
|
66
84
|
});
|
|
67
|
-
const classRegex = /^@
|
|
85
|
+
const classRegex = /^@CapacitorPlugin[\s\S]+?class ([\w]+)/gm;
|
|
68
86
|
const packageRegex = /^package ([\w.]+);?$/gm;
|
|
69
87
|
debug('Searching %O source files in %O by %O regex', srcFiles.length, srcPath, classRegex);
|
|
70
88
|
const entries = await Promise.all(srcFiles.map(async (srcFile) => {
|
|
@@ -96,13 +114,25 @@ async function installGradlePlugins(config, capacitorPlugins, cordovaPlugins) {
|
|
|
96
114
|
(0, errors_1.fatal)(`Unable to find ${colors_1.default.strong('node_modules/@capacitor/android')}.\n` +
|
|
97
115
|
`Are you sure ${colors_1.default.strong('@capacitor/android')} is installed?`);
|
|
98
116
|
}
|
|
117
|
+
const enableCordova = cordovaPlugins.length > 0 || config.app.forceCordova;
|
|
99
118
|
const capacitorAndroidPath = (0, path_1.resolve)((0, path_1.dirname)(capacitorAndroidPackagePath), 'capacitor');
|
|
119
|
+
const capacitorCordovaAndroidPath = (0, path_1.resolve)((0, path_1.dirname)(capacitorAndroidPackagePath), 'capacitor-cordova');
|
|
100
120
|
const settingsPath = config.android.platformDirAbs;
|
|
101
121
|
const dependencyPath = config.android.appDirAbs;
|
|
102
122
|
const relativeCapcitorAndroidPath = (0, fs_1.convertToUnixPath)((0, path_1.relative)(settingsPath, capacitorAndroidPath));
|
|
123
|
+
const relativeCapacitorCordovaAndroidPath = (0, fs_1.convertToUnixPath)((0, path_1.relative)(settingsPath, capacitorCordovaAndroidPath));
|
|
124
|
+
const cdvIncludeText = enableCordova
|
|
125
|
+
? `
|
|
126
|
+
include ':capacitor-cordova-android'
|
|
127
|
+
project(':capacitor-cordova-android').projectDir = new File('${relativeCapacitorCordovaAndroidPath}')
|
|
128
|
+
|
|
129
|
+
include ':capacitor-cordova-android-plugins'
|
|
130
|
+
project(':capacitor-cordova-android-plugins').projectDir = new File('./capacitor-cordova-android-plugins/')`
|
|
131
|
+
: '';
|
|
103
132
|
const settingsLines = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
|
104
133
|
include ':capacitor-android'
|
|
105
134
|
project(':capacitor-android').projectDir = new File('${relativeCapcitorAndroidPath}')
|
|
135
|
+
${cdvIncludeText}
|
|
106
136
|
${capacitorPlugins
|
|
107
137
|
.map((p) => {
|
|
108
138
|
if (!p.android) {
|
|
@@ -139,6 +169,20 @@ project(':${getGradlePackageName(p.id)}').projectDir = new File('${relativePlugi
|
|
|
139
169
|
});
|
|
140
170
|
prefsArray = prefsArray.concat((0, plugin_1.getAllElements)(p, platform, 'preference'));
|
|
141
171
|
});
|
|
172
|
+
const cdvRepoApplyText = enableCordova
|
|
173
|
+
? `
|
|
174
|
+
repositories {
|
|
175
|
+
flatDir{
|
|
176
|
+
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
|
|
181
|
+
`
|
|
182
|
+
: '';
|
|
183
|
+
const cdvDependencyText = enableCordova
|
|
184
|
+
? ` implementation project(':capacitor-cordova-android')\n implementation project(':capacitor-cordova-android-plugins')\n`
|
|
185
|
+
: '';
|
|
142
186
|
let frameworkString = frameworksArray.join('\n');
|
|
143
187
|
frameworkString = await replaceFrameworkVariables(config, prefsArray, frameworkString);
|
|
144
188
|
const dependencyLines = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
|
@@ -149,10 +193,9 @@ android {
|
|
|
149
193
|
targetCompatibility JavaVersion.VERSION_21
|
|
150
194
|
}
|
|
151
195
|
}
|
|
152
|
-
|
|
153
|
-
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
|
|
196
|
+
${cdvRepoApplyText}
|
|
154
197
|
dependencies {
|
|
155
|
-
${capacitorPlugins
|
|
198
|
+
${cdvDependencyText}${capacitorPlugins
|
|
156
199
|
.map((p) => {
|
|
157
200
|
return ` implementation project(':${getGradlePackageName(p.id)}')`;
|
|
158
201
|
})
|
|
@@ -170,10 +213,7 @@ if (hasProperty('postBuildExtras')) {
|
|
|
170
213
|
}
|
|
171
214
|
exports.installGradlePlugins = installGradlePlugins;
|
|
172
215
|
async function handleCordovaPluginsGradle(config, cordovaPlugins) {
|
|
173
|
-
var _a, _b, _c;
|
|
174
216
|
const pluginsGradlePath = (0, path_1.join)(config.android.cordovaPluginsDirAbs, 'build.gradle');
|
|
175
|
-
const kotlinNeeded = await kotlinNeededCheck(config, cordovaPlugins);
|
|
176
|
-
const kotlinVersionString = (_c = (_b = (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.GradlePluginKotlinVersion) !== null && _c !== void 0 ? _c : '2.2.20';
|
|
177
217
|
const frameworksArray = [];
|
|
178
218
|
let prefsArray = [];
|
|
179
219
|
const applyArray = [];
|
|
@@ -205,21 +245,10 @@ async function handleCordovaPluginsGradle(config, cordovaPlugins) {
|
|
|
205
245
|
})
|
|
206
246
|
.join('\n');
|
|
207
247
|
frameworkString = await replaceFrameworkVariables(config, prefsArray, frameworkString);
|
|
208
|
-
if (kotlinNeeded) {
|
|
209
|
-
frameworkString += `\n implementation "androidx.core:core-ktx:$androidxCoreKTXVersion"`;
|
|
210
|
-
frameworkString += `\n implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"`;
|
|
211
|
-
}
|
|
212
248
|
const applyString = applyArray.join('\n');
|
|
213
249
|
let buildGradle = await (0, fs_extra_1.readFile)(pluginsGradlePath, { encoding: 'utf-8' });
|
|
214
250
|
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + frameworkString.concat('\n') + ' $2');
|
|
215
251
|
buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + applyString.concat('\n') + '$2');
|
|
216
|
-
if (kotlinNeeded) {
|
|
217
|
-
buildGradle = buildGradle.replace(/(buildscript\s{\n(\t|\s{4})repositories\s{\n((\t{2}|\s{8}).+\n)+(\t|\s{4})}\n(\t|\s{4})dependencies\s{\n(\t{2}|\s{8}).+)\n((\t|\s{4})}\n}\n)/, `$1\n classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"\n$8`);
|
|
218
|
-
buildGradle = buildGradle.replace(/(ext\s{)/, `$1\n androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.8.0'`);
|
|
219
|
-
buildGradle = buildGradle.replace(/(buildscript\s{)/, `$1\n ext.kotlin_version = project.hasProperty('kotlin_version') ? rootProject.ext.kotlin_version : '${kotlinVersionString}'`);
|
|
220
|
-
buildGradle = buildGradle.replace(/(apply\splugin:\s'com\.android\.library')/, `$1\napply plugin: 'kotlin-android'`);
|
|
221
|
-
buildGradle = buildGradle.replace(/(compileOptions\s{\n((\t{2}|\s{8}).+\n)+(\t|\s{4})})\n(})/, `$1\n sourceSets {\n main.java.srcDirs += 'src/main/kotlin'\n }\n$5`);
|
|
222
|
-
}
|
|
223
252
|
await (0, fs_extra_1.writeFile)(pluginsGradlePath, buildGradle);
|
|
224
253
|
const cordovaVariables = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
|
225
254
|
ext {
|
|
@@ -231,26 +260,6 @@ ext {
|
|
|
231
260
|
await (0, fs_extra_1.writeFile)((0, path_1.join)(config.android.cordovaPluginsDirAbs, 'cordova.variables.gradle'), cordovaVariables);
|
|
232
261
|
}
|
|
233
262
|
exports.handleCordovaPluginsGradle = handleCordovaPluginsGradle;
|
|
234
|
-
async function kotlinNeededCheck(config, cordovaPlugins) {
|
|
235
|
-
var _a, _b;
|
|
236
|
-
if (((_b = (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.GradlePluginKotlinEnabled) !== 'true') {
|
|
237
|
-
for (const plugin of cordovaPlugins) {
|
|
238
|
-
const androidPlatform = (0, plugin_1.getPluginPlatform)(plugin, platform);
|
|
239
|
-
const sourceFiles = androidPlatform['source-file'];
|
|
240
|
-
if (sourceFiles) {
|
|
241
|
-
for (const srcFile of sourceFiles) {
|
|
242
|
-
if (/^.*\.kt$/.test(srcFile['$'].src)) {
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
263
|
async function copyPluginsNativeFiles(config, cordovaPlugins) {
|
|
255
264
|
const pluginsPath = (0, path_1.join)(config.android.cordovaPluginsDirAbs, 'src', 'main');
|
|
256
265
|
for (const p of cordovaPlugins) {
|