diff --git a/projectHelpers.js b/projectHelpers.js index 1725579f..7ebb1652 100644 --- a/projectHelpers.js +++ b/projectHelpers.js @@ -11,6 +11,7 @@ const { } = require("./nsCliHelpers"); const APP_DIR = "app"; +const ANDROID_PROJECT_PATH = "platforms/android"; const isTypeScript = ({ projectDir, packageJson } = {}) => { packageJson = packageJson || getPackageJson(projectDir); @@ -54,6 +55,19 @@ const getAndroidRuntimeVersion = (projectDir) => { } } +const getAndroidV8Version = (projectDir) => { + try { + const androidSettingsJSON = getAndroidSettingsJson(projectDir); + if(androidSettingsJSON != null) { + return androidSettingsJSON.v8Version; + } else { + return null; + } + } catch (e) { + return null; + } +} + const getWebpackConfig = (projectDir, env, configPath = "webpack.config.js") => { const configAbsolutePath = path.resolve(projectDir, configPath); let config; @@ -82,6 +96,15 @@ const getPackageJson = projectDir => { return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); }; +const getAndroidSettingsJson = projectDir => { + const androidSettingsJsonPath = path.resolve(projectDir, ANDROID_PROJECT_PATH, "settings.json"); + if (fs.existsSync(androidSettingsJsonPath)) { + return JSON.parse(fs.readFileSync(androidSettingsJsonPath, "utf8")); + } else { + return null; + } +}; + const writePackageJson = (content, projectDir) => { const packageJsonPath = getPackageJsonPath(projectDir); fs.writeFileSync(packageJsonPath, JSON.stringify(content, null, 2)) @@ -92,14 +115,13 @@ const toReleaseVersion = version => version.replace(/-.*/, ""); const getAndroidProjectPath = ({androidPackageVersion, projectRoot}) => { - const ANDROID_PROJECT_PATH = "platforms/android"; if (projectRoot) { androidPackageVersion = getAndroidRuntimeVersion(projectRoot); } return semver.lt(androidPackageVersion, "3.4.0") ? ANDROID_PROJECT_PATH : - path.join(ANDROID_PROJECT_PATH, "app"); + path.join(ANDROID_PROJECT_PATH, APP_DIR); }; @@ -153,6 +175,7 @@ module.exports = { getAppResourcesPathFromProjectData, getAndroidProjectPath, getAndroidRuntimeVersion, + getAndroidV8Version, getPackageJson, getProjectDir, getWebpackConfig, diff --git a/snapshot/android/project-snapshot-generator.js b/snapshot/android/project-snapshot-generator.js index 31813e87..267e7cb9 100644 --- a/snapshot/android/project-snapshot-generator.js +++ b/snapshot/android/project-snapshot-generator.js @@ -14,6 +14,7 @@ const { getPackageJson, getAndroidRuntimeVersion, getAndroidProjectPath, + getAndroidV8Version, resolveAndroidAppPath, resolveAndroidConfigurationsPath, } = require("../../projectHelpers"); @@ -160,6 +161,12 @@ ProjectSnapshotGenerator.prototype.getV8Version = function (generationOptions) { return resolve(maybeV8Version); } + // try to get the V8 Version from the settings.json file in android runtime folder + const runtimeV8Version = getAndroidV8Version(this.options.projectRoot); + if(runtimeV8Version) { + return resolve(runtimeV8Version); + } + const runtimeVersion = getAndroidRuntimeVersion(this.options.projectRoot); getV8VersionsMap(runtimeVersion) .then(({ versionsMap, latest }) => { diff --git a/snapshot/android/snapshot-generator.js b/snapshot/android/snapshot-generator.js index 2f699a48..bbe8f7aa 100644 --- a/snapshot/android/snapshot-generator.js +++ b/snapshot/android/snapshot-generator.js @@ -94,7 +94,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu const androidArch = this.convertToAndroidArchName(arch); console.log("***** Generating snapshot for " + androidArch + " *****"); - + // Generate .blob file const currentArchBlobOutputPath = join(this.buildPath, "snapshots/blobs", androidArch); shelljs.mkdir("-p", currentArchBlobOutputPath); @@ -157,14 +157,16 @@ SnapshotGenerator.prototype.generate = function(options) { if (!options.snapshotToolsPath) { throw new Error("snapshotToolsPath option is not specified."); } const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed"); + console.log("***** Starting snapshot generation using V8 version: ", options.v8Version); + this.preprocessInputFiles(options.inputFiles, preprocessedInputFile); // generates the actual .blob and .c files return this.runMksnapshotTool( - options.snapshotToolsPath, - preprocessedInputFile, - options.v8Version, - options.targetArchs, + options.snapshotToolsPath, + preprocessedInputFile, + options.v8Version, + options.targetArchs, options.useLibs ).then(() => { this.buildIncludeGradle();