uniapp-android-cli 0.1.2 → 0.1.3
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/README.md +9 -0
- package/package.json +1 -1
- package/src/core/build.js +1 -0
- package/src/core/patch/assets.js +63 -32
package/README.md
CHANGED
|
@@ -89,6 +89,14 @@ uni-pack debug -p <项目> # 真机调试
|
|
|
89
89
|
| `JAVA_HOME` | JDK 17+ 根目录 |
|
|
90
90
|
| `UNI_PACK_TEMP` | 前端构建临时目录,默认 `<workDir>/<项目>/tmp` |
|
|
91
91
|
|
|
92
|
+
### 应用图标与启动图
|
|
93
|
+
|
|
94
|
+
正式包需要准备 Android 图标和启动图。不配置也能构建,但会回退到离线 SDK 的默认资源(DCloud 图标和启动图)并给出告警,发布前请务必替换:
|
|
95
|
+
|
|
96
|
+
- 在 manifest 的 `app-plus.distribute.icons.android` / `app-plus.distribute.splashscreen.android` 中填写 hdpi / xhdpi / xxhdpi / xxxhdpi 路径;
|
|
97
|
+
- 或放到默认目录:`src/static/app/icons/`(`72x72.png`、`96x96.png`、`144x144.png`、`192x192.png`)与 `src/static/app/splash/`(`splash-hdpi.png` 等);
|
|
98
|
+
- 只配置部分密度时,会使用已有最高密度自动补齐其它密度和 `res/drawable/` 兜底图。
|
|
99
|
+
|
|
92
100
|
## 安装
|
|
93
101
|
|
|
94
102
|
```bash
|
|
@@ -331,6 +339,7 @@ uni-pack debug -p PRO_PHONE
|
|
|
331
339
|
| 多设备安装到了错误的设备 | 传 `--device <序列号/型号/唯一子串>` |
|
|
332
340
|
| 无线配对超时 | 同网段、关闭 VPN/代理、放行防火墙、升级 platform-tools |
|
|
333
341
|
| 前端构建 `esbuild-*: Access is denied` | 系统/用户 TEMP 被杀毒或索引服务占用,设置 `UNI_PACK_TEMP` 指向非用户目录 |
|
|
342
|
+
| 应用图标/启动图没配 | 使用 SDK 默认 DCloud 资源并告警,发布前在 manifest 或默认目录补齐 |
|
|
334
343
|
| Gradle 大量 `D8 ... Kotlin metadata` | DCloud AAR 由更高版本 Kotlin 编译,模板 R8 提示;不影响产物,默认已折叠 |
|
|
335
344
|
| 当前基座不包含原生插件 | 自定义基座较旧,在 HBuilderX 重新制作包含该插件的基座 |
|
|
336
345
|
| 日志看不到 JS 输出 | HBuilderX 模式看项目 `console` 日志;自建基座加 `--logs` |
|
package/package.json
CHANGED
package/src/core/build.js
CHANGED
package/src/core/patch/assets.js
CHANGED
|
@@ -13,6 +13,7 @@ import { copyTree, ensureDir, exists, readText, writeText } from '../fsx.js'
|
|
|
13
13
|
* @property {boolean} debug
|
|
14
14
|
* @property {string} projectDir
|
|
15
15
|
* @property {any} [manifest] 项目 manifest,用于读取图标与启动图路径
|
|
16
|
+
* @property {import('../logger.js').Logger} [logger]
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -30,7 +31,7 @@ export async function applyAssets(context) {
|
|
|
30
31
|
await copyTree(context.resourcesDir, wwwDir, (relative) => /^uni_modules\/[^/]+\/utssdk(\/|$)/.test(relative))
|
|
31
32
|
await writeControlFile(assetsData, context)
|
|
32
33
|
await patchStrings(mainDir, context.appName)
|
|
33
|
-
await applyIcons(mainDir, context.projectDir, context.manifest)
|
|
34
|
+
await applyIcons(mainDir, context.projectDir, context.manifest, context.logger)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
@@ -61,54 +62,84 @@ const CLIENT_ICON_FILES = { hdpi: '72x72.png', xhdpi: '96x96.png', xxhdpi: '144x
|
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* 图标与启动图优先用 manifest 声明的路径(CLI 与 HBuilderX 都适用),
|
|
64
|
-
*
|
|
65
|
+
* 其次回退到两种项目各自的默认目录。只配置部分密度时,用已有最高密度补齐;
|
|
66
|
+
* 完全没配置时保留 SDK 模板资源,并提示使用默认图。
|
|
65
67
|
* @param {string} mainDir
|
|
66
68
|
* @param {string} projectDir
|
|
67
69
|
* @param {any} [manifest]
|
|
70
|
+
* @param {import('../logger.js').Logger} [logger]
|
|
68
71
|
*/
|
|
69
|
-
async function applyIcons(mainDir, projectDir, manifest) {
|
|
72
|
+
async function applyIcons(mainDir, projectDir, manifest, logger) {
|
|
70
73
|
const distribute = manifest?.['app-plus']?.distribute ?? {}
|
|
71
74
|
const manifestIcons = distribute.icons?.android ?? {}
|
|
72
75
|
const manifestSplash = distribute.splashscreen?.android ?? {}
|
|
73
76
|
|
|
77
|
+
const icons = await resolveDensitySources(projectDir, manifestIcons, (density) => [
|
|
78
|
+
path.join(projectDir, 'src/static/app/icons', CLIENT_ICON_FILES[density]),
|
|
79
|
+
path.join(projectDir, 'unpackage/res/icons', CLIENT_ICON_FILES[density]),
|
|
80
|
+
])
|
|
81
|
+
const splash = await resolveDensitySources(projectDir, manifestSplash, (density) => [
|
|
82
|
+
path.join(projectDir, 'src/static/app/splash', `splash-${density}.png`),
|
|
83
|
+
path.join(projectDir, 'unpackage/res/splash/splash.png'),
|
|
84
|
+
path.join(projectDir, 'unpackage/res/splash', `splash-${density}.png`),
|
|
85
|
+
])
|
|
86
|
+
|
|
87
|
+
const bestIcon = bestSource(icons)
|
|
88
|
+
const bestSplash = bestSource(splash)
|
|
89
|
+
|
|
74
90
|
for (const density of ICON_DENSITIES) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
path.join(
|
|
78
|
-
path.join(projectDir, 'unpackage/res/icons', CLIENT_ICON_FILES[density]),
|
|
79
|
-
])
|
|
80
|
-
if (source) {
|
|
81
|
-
await copyFile(source, path.join(mainDir, `res/drawable-${density}/icon.png`))
|
|
91
|
+
const icon = icons[density] || bestIcon
|
|
92
|
+
if (icon) {
|
|
93
|
+
await copyFile(icon, path.join(mainDir, `res/drawable-${density}/icon.png`))
|
|
82
94
|
}
|
|
83
95
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
path.join(
|
|
87
|
-
path.join(projectDir, 'unpackage/res/splash/splash.png'),
|
|
88
|
-
path.join(projectDir, 'unpackage/res/splash', `splash-${density}.png`),
|
|
89
|
-
])
|
|
90
|
-
if (splash) {
|
|
91
|
-
await copyFile(splash, path.join(mainDir, `res/drawable-${density}/splash.png`))
|
|
96
|
+
const splashSource = splash[density] || bestSplash
|
|
97
|
+
if (splashSource) {
|
|
98
|
+
await copyFile(splashSource, path.join(mainDir, `res/drawable-${density}/splash.png`))
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
])
|
|
100
|
-
if (fallbackIcon) {
|
|
101
|
-
await copyFile(fallbackIcon, path.join(mainDir, 'res/drawable/icon.png'))
|
|
102
|
+
if (bestIcon) {
|
|
103
|
+
await copyFile(bestIcon, path.join(mainDir, 'res/drawable/icon.png'))
|
|
104
|
+
} else {
|
|
105
|
+
logger?.warn('未配置应用图标(app-plus.distribute.icons.android),使用 SDK 默认图标(DCloud),发布前请替换')
|
|
102
106
|
}
|
|
107
|
+
if (bestSplash) {
|
|
108
|
+
await copyFile(bestSplash, path.join(mainDir, 'res/drawable/splash.png'))
|
|
109
|
+
} else {
|
|
110
|
+
logger?.warn('未配置启动图(app-plus.distribute.splashscreen.android),使用 SDK 默认启动图,发布前请替换')
|
|
111
|
+
}
|
|
112
|
+
}
|
|
103
113
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
/**
|
|
115
|
+
* @param {string} projectDir
|
|
116
|
+
* @param {Record<string, any>} declared
|
|
117
|
+
* @param {(density: string) => string[]} defaults
|
|
118
|
+
* @returns {Promise<Record<string, string>>}
|
|
119
|
+
*/
|
|
120
|
+
async function resolveDensitySources(projectDir, declared, defaults) {
|
|
121
|
+
/** @type {Record<string, string>} */
|
|
122
|
+
const sources = {}
|
|
123
|
+
for (const density of ICON_DENSITIES) {
|
|
124
|
+
const source = await firstExisting([resolveMaybeRelative(projectDir, declared[density]), ...defaults(density)])
|
|
125
|
+
if (source) {
|
|
126
|
+
sources[density] = source
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return sources
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {Record<string, string>} sources
|
|
134
|
+
* @returns {string}
|
|
135
|
+
*/
|
|
136
|
+
function bestSource(sources) {
|
|
137
|
+
for (const density of [...ICON_DENSITIES].reverse()) {
|
|
138
|
+
if (sources[density]) {
|
|
139
|
+
return sources[density]
|
|
140
|
+
}
|
|
111
141
|
}
|
|
142
|
+
return ''
|
|
112
143
|
}
|
|
113
144
|
|
|
114
145
|
/**
|