Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit d646864

Browse files
committed
refactor: improve android NDK logging
1 parent 2b77549 commit d646864

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

snapshot/android/project-snapshot-generator.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
148148
shelljs.mkdir("-p", this.getBuildPath());
149149

150150
const snapshotToolsPath = resolveRelativePath(generationOptions.snapshotToolsPath) || CONSTANTS.SNAPSHOT_TMP_DIR;
151-
const androidNdkPath = generationOptions.androidNdkPath || process.env.ANDROID_NDK_HOME;
152-
153151
console.log("Snapshot tools path: " + snapshotToolsPath);
154152

155153
// Generate snapshots
@@ -178,7 +176,7 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
178176
preprocessedInputFile: generationOptions.preprocessedInputFile,
179177
useLibs: generationOptions.useLibs || false,
180178
inputFiles: generationOptions.inputFiles || [join(this.options.projectRoot, "__snapshot.js")],
181-
androidNdkPath,
179+
androidNdkPath: generationOptions.androidNdkPath,
182180
mksnapshotParams: mksnapshotParams,
183181
snapshotInDocker: generationOptions.snapshotInDocker,
184182
recommendedAndroidNdkRevision

snapshot/android/snapshot-generator.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,26 +220,42 @@ SnapshotGenerator.prototype.getAndroidNdkBuildPath = function (androidNdkPath, r
220220
if (!fs.existsSync(androidNdkBuildPath)) {
221221
throw new Error(`The provided Android NDK path does not contain ${ndkBuildExecutableName} executable.`);
222222
} else if (localNdkRevision !== recommendedAndroidNdkRevision) {
223-
warn(`The provided Android NDK is v${localNdkRevision} while the recommended one is v${recommendedAndroidNdkRevision}`);
223+
warn(this.getRecommendedNdkWarning(localNdkRevision, recommendedAndroidNdkRevision));
224224
}
225+
console.log("Using Android NDK from webpack.config.");
225226
} else {
226-
// available globally
227-
let hasAndroidNdkInPath = true;
228-
androidNdkBuildPath = ndkBuildExecutableName;
229-
try {
230-
child_process.execSync(`${androidNdkBuildPath} --version`);
231-
console.log(`Cannot determine the version of the global Android NDK. The recommended versions is v${recommendedAndroidNdkRevision}`);
232-
} catch (_) {
233-
hasAndroidNdkInPath = false;
227+
let hasLocalNdk = true;
228+
if (process.env.ANDROID_NDK_HOME) {
229+
// check ANDROID_NDK_HOME
230+
const localNdkRevision = this.getAndroidNdkRevision(process.env.ANDROID_NDK_HOME);
231+
androidNdkBuildPath = join(process.env.ANDROID_NDK_HOME, ndkBuildExecutableName);
232+
if (!fs.existsSync(androidNdkBuildPath)) {
233+
hasLocalNdk = false;
234+
} else if (localNdkRevision !== recommendedAndroidNdkRevision) {
235+
warn(this.getRecommendedNdkWarning(localNdkRevision, recommendedAndroidNdkRevision));
236+
}
237+
console.log("Using Android NDK from ANDROID_NDK_HOME.");
238+
}
239+
240+
if (!hasLocalNdk) {
241+
// available globally
242+
androidNdkBuildPath = ndkBuildExecutableName;
243+
try {
244+
child_process.execSync(`${androidNdkBuildPath} --version`);
245+
console.log("Using Android NDK from PATH.");
246+
console.log(`Cannot determine the version of the global Android NDK. The recommended versions is v${recommendedAndroidNdkRevision}`);
247+
} catch (_) {
248+
hasLocalNdk = false;
249+
}
234250
}
235251

236-
if (!hasAndroidNdkInPath) {
252+
if (!hasLocalNdk) {
237253
// installed in ANDROID_HOME
238-
const androidHome = process.env.ANDROID_HOME;
239-
androidNdkBuildPath = join(androidHome, "ndk", recommendedAndroidNdkRevision, ndkBuildExecutableName);
254+
androidNdkBuildPath = join(process.env.ANDROID_HOME, "ndk", recommendedAndroidNdkRevision, ndkBuildExecutableName);
240255
if (!fs.existsSync(androidNdkBuildPath)) {
241-
throw new Error(`Android NDK v${recommendedAndroidNdkRevision} is not installed. You can find installation instructions in this article: https://developer.android.com/studio/projects/install-ndk#specific-version`);
256+
throw new Error(`Android NDK v${recommendedAndroidNdkRevision} is not installed. Install it from Android Studio or download it and set ANDROID_NDK_HOME or add it to your PATH. You can find installation instructions in this article: https://developer.android.com/studio/projects/install-ndk#specific-version`);
242257
}
258+
console.log("Using Android NDK from ANDROID_HOME.");
243259
}
244260
}
245261

@@ -369,6 +385,10 @@ SnapshotGenerator.prototype.buildCSource = function (androidArch, blobInputDir,
369385
});
370386
}
371387

388+
SnapshotGenerator.prototype.getRecommendedNdkWarning = function (localNdkRevision, recommendedAndroidNdkRevision) {
389+
return `The provided Android NDK is v${localNdkRevision} while the recommended one is v${recommendedAndroidNdkRevision}`;
390+
}
391+
372392
SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams, inputFile, snapshotInDocker, snapshotToolsPath, buildCSource) {
373393
const toolPath = tool.path;
374394
const androidArch = this.convertToAndroidArchName(tool.arch);

0 commit comments

Comments
 (0)