mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
add java_home (#15996)
This commit is contained in:
@@ -370,7 +370,7 @@ export abstract class NativePackTool {
|
||||
|
||||
protected getExcutableNameOrDefault(): string {
|
||||
const en = this.params.executableName;
|
||||
return en ? en : this.projectNameASCII();
|
||||
return en ? en : this.projectNameASCII();
|
||||
}
|
||||
|
||||
protected async excuteTemplateTask(tasks: CocosProjectTasks) {
|
||||
@@ -422,7 +422,7 @@ export abstract class NativePackTool {
|
||||
replaceFilesDelay[fp] = replaceFilesDelay[fp] || [];
|
||||
replaceFilesDelay[fp].push({
|
||||
reg: name,
|
||||
content: this.params.platformParams.packageName!,
|
||||
content: (this.params.platformParams as any).packageName!,
|
||||
});
|
||||
});
|
||||
delete tasks.projectReplacePackageName;
|
||||
@@ -454,7 +454,7 @@ export abstract class NativePackTool {
|
||||
}
|
||||
});
|
||||
Object.keys(config).forEach((key: string) => {
|
||||
if(typeof config[key] !== 'string') {
|
||||
if (typeof config[key] !== 'string') {
|
||||
console.error(`cMakeConfig.${key} is not a string, "${config[key]}"`);
|
||||
} else {
|
||||
content += config[key] + '\n';
|
||||
@@ -468,7 +468,7 @@ export abstract class NativePackTool {
|
||||
args.push(`-DRES_DIR="${cchelper.fixPath(this.paths.buildDir)}"`);
|
||||
args.push(`-DAPP_NAME="${this.params.projectName}"`);
|
||||
args.push(`-DLAUNCH_TYPE="${this.buildType}"`);
|
||||
if (this.params.platformParams?.skipUpdateXcodeProject) {
|
||||
if ((this.params.platformParams as any).skipUpdateXcodeProject) {
|
||||
args.push(`-DCMAKE_SUPPRESS_REGENERATION=ON`);
|
||||
}
|
||||
}
|
||||
@@ -543,7 +543,7 @@ export abstract class NativePackTool {
|
||||
|
||||
// cocos.compile.json
|
||||
export class CocosParams<T> {
|
||||
platformParams!: T | any;
|
||||
platformParams: T;
|
||||
public debug: boolean;
|
||||
public projectName: string;
|
||||
public cmakePath: string;
|
||||
@@ -602,7 +602,7 @@ export class CocosParams<T> {
|
||||
CC_ENABLE_SWAPPY: false,
|
||||
}
|
||||
|
||||
constructor(params: CocosParams<Object>) {
|
||||
constructor(params: CocosParams<T>) {
|
||||
this.buildAssetsDir = params.buildAssetsDir;
|
||||
this.projectName = params.projectName;
|
||||
this.debug = params.debug;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { cchelper, Paths } from "../utils";
|
||||
import * as URL from 'url';
|
||||
import { spawn, spawnSync } from 'child_process';
|
||||
import * as xml2js from 'xml2js';
|
||||
import { platform } from 'os';
|
||||
|
||||
export interface IOrientation {
|
||||
landscapeLeft: boolean;
|
||||
@@ -17,7 +18,10 @@ export interface IAndroidParams {
|
||||
packageName: string;
|
||||
sdkPath: string;
|
||||
ndkPath: string;
|
||||
javaHome: string;
|
||||
javaPath: string;
|
||||
androidInstant: boolean,
|
||||
maxAspectRatio: string;
|
||||
remoteUrl?: string;
|
||||
apiLevel: number;
|
||||
appABIs: string[];
|
||||
@@ -25,6 +29,7 @@ export interface IAndroidParams {
|
||||
keystoreAlias: string;
|
||||
keystoreAliasPassword: string;
|
||||
keystorePath: string;
|
||||
inputSDK: boolean;
|
||||
|
||||
orientation: IOrientation;
|
||||
appBundle: boolean;
|
||||
@@ -77,6 +82,18 @@ export class AndroidPackTool extends NativePackTool {
|
||||
async make() {
|
||||
const options = this.params.platformParams;
|
||||
|
||||
if (options.javaHome) {
|
||||
if (process.env.JAVA_HOME !== options.javaHome) {
|
||||
process.env.JAVA_HOME = options.javaHome;
|
||||
console.log(`Update JAVA_HOME to ${options.javaHome}`);
|
||||
}
|
||||
if (!process.env.PATH!.startsWith(options.javaHome)) {
|
||||
const sep = platform() === 'win32' ? ';' : ':';
|
||||
process.env.PATH = ps.join(options.javaHome, 'bin') + sep + process.env.PATH;
|
||||
console.log(`Add JAVA_HOME/bin to PATH`);
|
||||
}
|
||||
}
|
||||
|
||||
const projDir: string = this.paths.nativePrjDir;
|
||||
if (!fs.existsSync(projDir)) {
|
||||
throw new Error(`dir ${projDir} not exits`);
|
||||
@@ -93,7 +110,6 @@ export class AndroidPackTool extends NativePackTool {
|
||||
|
||||
// compile android
|
||||
buildMode = `${this.projectNameASCII()}:assemble${outputMode}`;
|
||||
// await cchelper.runCmd(gradle, [buildMode /* "--quiet",*/ /*"--build-cache", "--project-cache-dir", nativePrjDir */], false, projDir);
|
||||
|
||||
// pushd
|
||||
const originDir = process.cwd();
|
||||
@@ -111,7 +127,6 @@ export class AndroidPackTool extends NativePackTool {
|
||||
// compile android-instant
|
||||
if (options.androidInstant) {
|
||||
buildMode = `instantapp:assemble${outputMode}`;
|
||||
// await cchelper.runCmd(gradle, [buildMode, /*"--quiet",*/ /*"--build-cache", "--project-cache-dir", nativePrjDir*/], false, projDir);
|
||||
await cchelper.runCmd(gradle, [buildMode], false, projDir);
|
||||
}
|
||||
|
||||
@@ -122,7 +137,6 @@ export class AndroidPackTool extends NativePackTool {
|
||||
} else {
|
||||
buildMode = `${this.params.projectName}:bundle${outputMode}`;
|
||||
}
|
||||
// await cchelper.runCmd(gradle, [buildMode, /*"--quiet",*/ /*"--build-cache", "--project-cache-dir", nativePrjDir*/], false, projDir);
|
||||
await cchelper.runCmd(gradle, [buildMode], false, projDir);
|
||||
}
|
||||
return await this.copyToDist();
|
||||
@@ -214,7 +228,7 @@ export class AndroidPackTool extends NativePackTool {
|
||||
const application = data.manifest.application[0];
|
||||
//append meta-data
|
||||
application['meta-data'].push({
|
||||
$:{'android:name': 'android.max_aspect', 'android:value': `${aspectRatioFloatValue}`}
|
||||
$: { 'android:name': 'android.max_aspect', 'android:value': `${aspectRatioFloatValue}` }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ export interface OHOSParam {
|
||||
ndkPath: string;
|
||||
orientation: IOrientation;
|
||||
packageName: string;
|
||||
appABIs: string[];
|
||||
apiLevel: number;
|
||||
}
|
||||
|
||||
export class OpenHarmonyPackTool extends NativePackTool {
|
||||
@@ -143,7 +145,7 @@ export class OpenHarmonyPackTool extends NativePackTool {
|
||||
hdcExe, ['uninstall', packageName], false, hdcCwd);
|
||||
console.debug(`${hdc} install -r ${hapFile}`);
|
||||
await cchelper.runCmd(
|
||||
hdcExe,['install', '-r', hapFile], false, hdcCwd);
|
||||
hdcExe, ['install', '-r', hapFile], false, hdcCwd);
|
||||
console.debug(`${hdc} shell aa start -a ${ability} -b ${packageName}`);
|
||||
await cchelper.runCmd(
|
||||
hdcExe, ['shell', 'aa', 'start', '-a', ability, '-b', packageName, '-m', moduleName], false, hdcCwd);
|
||||
|
||||
@@ -557,7 +557,7 @@ export class Paths {
|
||||
this.buildDir = params.buildDir;
|
||||
this.buildAssetsDir = params.buildAssetsDir;
|
||||
if (params.platform === 'windows') {
|
||||
this.platformTemplateDirName = params.platformParams.targetPlatform === "win32" ? "win32" : "win64";
|
||||
this.platformTemplateDirName = (params.platformParams as any).targetPlatform === "win32" ? "win32" : "win64";
|
||||
} else {
|
||||
this.platformTemplateDirName = params.platformName ? params.platformName : this.platform;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user