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

refactor: improve android NDK logging #1068

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions snapshot/android/project-snapshot-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
shelljs.mkdir("-p", this.getBuildPath());

const snapshotToolsPath = resolveRelativePath(generationOptions.snapshotToolsPath) || CONSTANTS.SNAPSHOT_TMP_DIR;
const androidNdkPath = generationOptions.androidNdkPath || process.env.ANDROID_NDK_HOME;

console.log("Snapshot tools path: " + snapshotToolsPath);

// Generate snapshots
Expand Down Expand Up @@ -178,7 +176,7 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
preprocessedInputFile: generationOptions.preprocessedInputFile,
useLibs: generationOptions.useLibs || false,
inputFiles: generationOptions.inputFiles || [join(this.options.projectRoot, "__snapshot.js")],
androidNdkPath,
androidNdkPath: generationOptions.androidNdkPath,
mksnapshotParams: mksnapshotParams,
snapshotInDocker: generationOptions.snapshotInDocker,
recommendedAndroidNdkRevision
Expand Down
56 changes: 42 additions & 14 deletions snapshot/android/snapshot-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ SnapshotGenerator.prototype.buildSnapshotLibs = function (androidNdkPath, recomm

SnapshotGenerator.prototype.getAndroidNdkBuildPath = function (androidNdkPath, recommendedAndroidNdkRevision) {
const ndkBuildExecutableName = "ndk-build";
let hasNdk = false;
// fallback for Android Runtime < 6.2.0 with the 6.1.0 value
recommendedAndroidNdkRevision = recommendedAndroidNdkRevision || "20.0.5594570";
let androidNdkBuildPath = "";
Expand All @@ -220,29 +221,52 @@ SnapshotGenerator.prototype.getAndroidNdkBuildPath = function (androidNdkPath, r
if (!fs.existsSync(androidNdkBuildPath)) {
throw new Error(`The provided Android NDK path does not contain ${ndkBuildExecutableName} executable.`);
} else if (localNdkRevision !== recommendedAndroidNdkRevision) {
warn(`The provided Android NDK is v${localNdkRevision} while the recommended one is v${recommendedAndroidNdkRevision}`);
warn(this.getRecommendedNdkWarning(localNdkRevision, recommendedAndroidNdkRevision));
}

hasNdk = true;
console.log("Using Android NDK from webpack.config.");
} else {
// available globally
let hasAndroidNdkInPath = true;
androidNdkBuildPath = ndkBuildExecutableName;
try {
child_process.execSync(`${androidNdkBuildPath} --version`);
console.log(`Cannot determine the version of the global Android NDK. The recommended versions is v${recommendedAndroidNdkRevision}`);
} catch (_) {
hasAndroidNdkInPath = false;
if (process.env.ANDROID_NDK_HOME) {
// check ANDROID_NDK_HOME
const localNdkRevision = this.getAndroidNdkRevision(process.env.ANDROID_NDK_HOME);
androidNdkBuildPath = join(process.env.ANDROID_NDK_HOME, ndkBuildExecutableName);
if (fs.existsSync(androidNdkBuildPath)) {
hasNdk = true;
console.log("Using Android NDK from ANDROID_NDK_HOME.");
}

if (localNdkRevision !== recommendedAndroidNdkRevision) {
warn(this.getRecommendedNdkWarning(localNdkRevision, recommendedAndroidNdkRevision));
}
}

if (!hasNdk) {
// available globally
androidNdkBuildPath = ndkBuildExecutableName;
try {
child_process.execSync(`${androidNdkBuildPath} --version`, { stdio: "ignore" });
hasNdk = true;
console.log("Using Android NDK from PATH.");
console.log(`Cannot determine the version of the global Android NDK. The recommended versions is v${recommendedAndroidNdkRevision}`);
} catch (_) {
}
}

if (!hasAndroidNdkInPath) {
if (!hasNdk) {
// installed in ANDROID_HOME
const androidHome = process.env.ANDROID_HOME;
androidNdkBuildPath = join(androidHome, "ndk", recommendedAndroidNdkRevision, ndkBuildExecutableName);
if (!fs.existsSync(androidNdkBuildPath)) {
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`);
androidNdkBuildPath = join(process.env.ANDROID_HOME, "ndk", recommendedAndroidNdkRevision, ndkBuildExecutableName);
if (fs.existsSync(androidNdkBuildPath)) {
hasNdk = true;
console.log("Using Android NDK from ANDROID_HOME.");
}
}
}

if (!hasNdk) {
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`);
}

return androidNdkBuildPath;
}

Expand Down Expand Up @@ -369,6 +393,10 @@ SnapshotGenerator.prototype.buildCSource = function (androidArch, blobInputDir,
});
}

SnapshotGenerator.prototype.getRecommendedNdkWarning = function (localNdkRevision, recommendedAndroidNdkRevision) {
return `The provided Android NDK is v${localNdkRevision} while the recommended one is v${recommendedAndroidNdkRevision}`;
}

SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams, inputFile, snapshotInDocker, snapshotToolsPath, buildCSource) {
const toolPath = tool.path;
const androidArch = this.convertToAndroidArchName(tool.arch);
Expand Down