-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: aPPDevTool 自动检测、下载 Android Sdk 缺少工具
APPDevTool 自动检测、下载 Android Sdk 缺少工具
- Loading branch information
Showing
13 changed files
with
196 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
for-vue2/src/packages/plugins/APPDevTool/androidServer/buildAPK.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 85 additions & 42 deletions
127
for-vue2/src/packages/plugins/APPDevTool/androidServer/checkoutDep.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,107 @@ | ||
import { spawn } from 'child_process'; | ||
import { spawnSync } from 'child_process'; | ||
import path from 'path'; | ||
import { err } from '../utils.js'; | ||
import { readdir } from 'fs/promises'; | ||
import inquirer from 'inquirer8'; | ||
import { err, log } from '../utils.js'; | ||
import { | ||
JAVA_V, COMPILE_SDK_V, BUIILD_TOOLS_V, COMMAND_SDKMANAGER, | ||
} from './constant.js'; | ||
|
||
export default async function checkoutDep() { | ||
function getJavaVersion(): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const ps = spawn('./java.exe', ['-version'], { cwd: path.resolve(process.env.JAVA_HOME as string, './bin') }); | ||
function checkoutJavaVersion() { | ||
const { stderr: stdout, error } = spawnSync( | ||
'./java', | ||
['-version'], | ||
{ | ||
cwd: path.resolve(process.env.JAVA_HOME as string, './bin'), | ||
encoding: 'utf-8', | ||
}, | ||
); | ||
|
||
ps.on('error', (e) => { | ||
reject(e); | ||
}); | ||
if (error) { | ||
err(`获取 java 版本出错:${process.env.JAVA_HOME}`, error, 'android'); | ||
} | ||
|
||
let oneTimes = true; | ||
const str = stdout.split('\r\n')[0]; | ||
|
||
ps.stderr.on('data', (data) => { | ||
if (oneTimes) { | ||
oneTimes = false; | ||
if (str.indexOf('openjdk version') !== 0 && str.indexOf('java version') !== 0) { | ||
err(`获取 java 版本出错,未知字符串:${str}`, null, 'android'); | ||
} | ||
|
||
const data1 = String(data).split('\r\n')[0]; | ||
const version = str.split(' ')[2].replace(/"/g, '').split('.'); | ||
|
||
if (data1.indexOf('openjdk version') !== 0 && data1.indexOf('java version') !== 0) { | ||
reject(new Error()); | ||
} else { | ||
const version = data1.split(' ')[2].replace(/"/g, '').split('.'); | ||
let versionStr = ''; | ||
|
||
let versionStr = ''; | ||
if (Number(version[0]) > 10) { | ||
versionStr = `JavaVersion.VERSION_${version[0]}`; | ||
} | ||
|
||
if (Number(version[0]) > 10) { | ||
versionStr = `VERSION_${version[0]}`; | ||
} | ||
if (Number(version[0]) > 25) { | ||
versionStr = 'JavaVersion.VERSION_HIGHER'; | ||
} | ||
|
||
if (Number(version[0]) > 25) { | ||
versionStr = 'VERSION_HIGHER'; | ||
} | ||
versionStr = `JavaVersion.VERSION_${version[0]}_${version[1]}`; | ||
|
||
versionStr = `VERSION_${version[0]}_${version[1]}`; | ||
if (versionStr !== JAVA_V) { | ||
err(`java 版本不兼容 | ||
resolve(versionStr); | ||
} | ||
} | ||
}); | ||
}); | ||
要求版本:${JAVA_V} | ||
当前版本:${versionStr} | ||
使用的java目录:${process.env.JAVA_HOME} | ||
`, null, 'android'); | ||
} | ||
} | ||
|
||
function checkoutBuildTool() { | ||
async function main() { | ||
const toolsPath = path.resolve(process.env.ANDROID_SDK_ROOT as string, './tools/bin'); | ||
const buildToolsPath = path.resolve(process.env.ANDROID_SDK_ROOT as string, './build-tools'); | ||
const platformsPath = path.resolve(process.env.ANDROID_SDK_ROOT as string, './platforms'); | ||
|
||
const buildToolsVersions = await readdir(buildToolsPath); | ||
const platformsVersions = await readdir(platformsPath); | ||
|
||
const installList = []; | ||
if (!buildToolsVersions.includes(BUIILD_TOOLS_V)) { | ||
installList.push(`"build-tools;${BUIILD_TOOLS_V}"`); | ||
} | ||
|
||
if (!platformsVersions.includes(`android-${COMPILE_SDK_V}`)) { | ||
installList.push(`"platforms;android-${COMPILE_SDK_V}"`); | ||
} | ||
|
||
if (installList.length !== 0) { | ||
// eslint-disable-next-line no-console | ||
console.clear(); | ||
log(`检查到本机 Android Sdk 缺少下方工具: | ||
${installList.join('\n ')}`, 'android'); | ||
|
||
const res: { confirm: boolean; } = await inquirer.prompt({ | ||
type: 'confirm', | ||
name: 'confirm', | ||
message: '是否自动安装?', | ||
}); | ||
|
||
if (res.confirm) { | ||
const { error } = spawnSync(COMMAND_SDKMANAGER, [...installList], { | ||
cwd: toolsPath, shell: true, stdio: 'inherit', encoding: 'utf-8', | ||
}); | ||
|
||
if (error) { | ||
err(`安装 android Sdk 构建工具 出错:${process.env.ANDROID_SDK_ROOT}`, error, 'android'); | ||
} else { | ||
log(`检查到本机 Android Sdk 缺少下方工具: | ||
${String(installList)} | ||
`, 'android'); | ||
} | ||
} | ||
} | ||
} | ||
|
||
let javaVersion = ''; | ||
checkoutJavaVersion(); | ||
try { | ||
javaVersion = await getJavaVersion(); | ||
await main(); | ||
} catch (e) { | ||
err('获取 java 版本出错', e, 'android'); | ||
err(`效验 android Sdk 构建工具 出错:${process.env.ANDROID_SDK_ROOT}`, e, 'android'); | ||
} | ||
|
||
return { | ||
javaVersion, | ||
}; | ||
// console.log(javaVersion); | ||
// checkoutBuildTool(); | ||
} | ||
|
||
// checkoutDep('C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.382.5-hotspot'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
for-vue2/src/packages/plugins/APPDevTool/androidServer/constant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
export const JAVA_V: string = 'JavaVersion.VERSION_1_8'; | ||
|
||
export const COMPILE_SDK_V: number = 30; | ||
|
||
export const BUIILD_TOOLS_V: string = '30.0.3'; | ||
|
||
export const DEFAULT_APP_ID: string = '__UNI__CA5CB1E'; | ||
|
||
export const DEFAULT_APP_KEY: string = '537cba7f932e287fd25900de910bc831'; | ||
|
||
export const DEFAULT_VERSION_CODE: number = 1; | ||
|
||
export const DEFAULT_VERSION_NAME: string = '1.0'; | ||
|
||
export const DEFAULT_APPLICATION_ID: string = 'com.android.testa'; | ||
|
||
export const COMMAND_SDKMANAGER: string = process.platform === 'win32' ? 'sdkmanager.bat' : './sdkmanager'; | ||
|
||
export const COMMAND_GRADLEW: string = process.platform === 'win32' ? 'gradlew.bat' : './gradlew'; | ||
|
||
export const COMMAND_ADB: string = process.platform === 'win32' ? 'adb' : './adb'; | ||
|
||
export const LF: string = process.platform === 'win32' ? '\r\n' : '\n'; | ||
|
||
export const CHOICE_DEVICE_HELP_TEXT: string = '使用 R 键刷新'; | ||
|
||
export const LISTEN_SERVER_HELP_TEXT: string = ` | ||
- 修改文件自动刷新 | ||
- 按下 R 键手动刷新 | ||
`; | ||
export const LISTEN_SERVER_DELAY: number = 200; | ||
|
||
export const COMMON_TEST_SIGNING: { | ||
keyAlias: string; | ||
keyPassword: string; | ||
storeFile: string; | ||
storePassword: string; | ||
} = { | ||
keyAlias: 'android', | ||
keyPassword: '123456', | ||
storeFile: 'default.keystore', | ||
storePassword: '123456', | ||
}; | ||
|
||
export const UNI_SDK_NAME_LIST: Array<string> = [ | ||
'uniapp-v8-release.aar', | ||
'oaid_sdk_1.0.25.aar', | ||
'lib.5plus.base-release.aar', | ||
'breakpad-build-release.aar', | ||
'android-gif-drawable-release@1.2.23.aar', | ||
]; | ||
|
||
export const DEVICE_TYPES: Array<{ name: string, str: string, type: string; }> = [ | ||
{ | ||
name: '模拟器设备', | ||
str: 'product', | ||
type: 'emulator', | ||
}, | ||
{ | ||
name: 'USB设备', | ||
str: 'product', | ||
type: 'usb', | ||
}, | ||
]; |
Oops, something went wrong.