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

Snapshot generation failed #591

Closed
cerireyhan opened this issue Jun 29, 2018 · 5 comments
Closed

Snapshot generation failed #591

cerireyhan opened this issue Jun 29, 2018 · 5 comments

Comments

@cerireyhan
Copy link

Android build fails on Linux with error below when snapshot is enabled. Build succeeds on macOS.

ERROR in NativeScriptSnapshot. Snapshot generation failed!
Target architecture: x86
/bin/sh: 1: /tmp/snapshot-tools/mksnapshot-tools/v8-v6.6.346.23/linux-x64/mksnapshot-ia32: not found

Local environment

  • Platform Linux
  • Node version v8.11.2

Project data

package.json

"tns-android": {
      "version": "4.1.3"
}
    },
 "dependencies": {
    "@angular/animations": "~6.0.6",
    "@angular/common": "~6.0.6",
    "@angular/compiler": "~6.0.6",
    "@angular/core": "~6.0.6",
    "@angular/forms": "~6.0.6",
    "@angular/http": "~6.0.6",
    "@angular/platform-browser": "~6.0.6",
    "@angular/platform-browser-dynamic": "~6.0.6",
    "@angular/router": "~6.0.6",
    "nativescript-angular": "~6.0.6",
    "nativescript-appversion": "~1.4.1",
    "nativescript-feedback": "~1.2.0",
    "nativescript-iqkeyboardmanager": "~1.3.0",
    "nativescript-loading-indicator": "~2.4.0",
    "nativescript-local-notifications": "~2.0.4",
    "nativescript-orientation": "~2.2.0",
    "nativescript-pdf-view": "~2.0.1",
    "nativescript-plugin-firebase": "~6.3.0",
    "nativescript-pulltorefresh": "~2.1.1",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-urlhandler": "~1.2.2",
    "nativescript-websockets": "~1.5.0",
    "reflect-metadata": "~0.1.12",
    "rxjs": "~6.2.1",
    "tns-core-modules": "~4.1.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0-rc.0",
    "@angular/compiler-cli": "~6.1.0-beta.1",
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "codelyzer": "^4.4.2",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "~0.7.1",
    "nativescript-dev-webpack": "^0.14.2",
    "tns-platform-declarations": "~4.1.0",
    "tslint": "^5.10.0",
    "typescript": "~2.7.2"
  }

webpack.config.js

const { join, relative, resolve, sep } = require("path");

const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const { AngularCompilerPlugin } = require("@ngtools/webpack");

module.exports = env => {
    // Add your custom Activities, Services and other Android app components here.
    const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
    ];

    const platform = env && (env.android && "android" || env.ios && "ios");
    if (!platform) {
        throw new Error("You need to provide a target platform!");
    }

    const extensions = ["tns", platform];
    const platformHost = new PlatformReplacementHost(extensions);

    const projectRoot = __dirname;

    // Default destination inside platforms/<platform>/...
    const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot));
    const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";

    const {
        // The 'appPath' and 'appResourcesPath' values are fetched from
        // the nsconfig.json configuration file
        // when bundling with `tns run android|ios --bundle`.
        appPath = "app",
        appResourcesPath = "app/App_Resources",

        // You can provide the following flags when running 'tns run android|ios'
        aot, // --env.aot
        snapshot, // --env.snapshot
        uglify, // --env.uglify
        report, // --env.report
    } = env;

    const appFullPath = resolve(projectRoot, appPath);
    const appResourcesFullPath = resolve(projectRoot, appResourcesPath);

    const entryModule = aot ?
        nsWebpack.getAotEntryModule(appFullPath) : 
        `${nsWebpack.getEntryModule(appFullPath)}.ts`;
    const entryPath = `.${sep}${entryModule}`;

    const config = {
        mode: uglify ? "production" : "development",
        context: appFullPath,
        watchOptions: {
            ignored: [
                appResourcesFullPath,
                // Don't watch hidden files
                "**/.*",
            ]
        },
        target: nativescriptTarget,
        entry: {
            bundle: entryPath,
        },
        output: {
            pathinfo: false,
            path: dist,
            libraryTarget: "commonjs2",
            filename: "[name].js",
            globalObject: "global",
        },
        resolve: {
            extensions: [".ts", ".js", ".scss", ".css"],
            // Resolve {N} system modules from tns-core-modules
            modules: [
                resolve(__dirname, "node_modules/tns-core-modules"),
                resolve(__dirname, "node_modules"),
                "node_modules/tns-core-modules",
                "node_modules",
            ],
            alias: {
                '~': appFullPath
            },
            symlinks: true
        },
        resolveLoader: {
            symlinks: false
        },
        node: {
            // Disable node shims that conflict with NativeScript
            "http": false,
            "timers": false,
            "setImmediate": false,
            "fs": "empty",
            "__dirname": false,
        },
        devtool: "none",
        optimization: {
            splitChunks: {
                cacheGroups: {
                    vendor: {
                        name: "vendor",
                        chunks: "all",
                        test: (module, chunks) => {
                            const moduleName = module.nameForCondition ? module.nameForCondition() : '';
                            return /[\\/]node_modules[\\/]/.test(moduleName) ||
                                    appComponents.some(comp => comp === moduleName);
                        },
                        enforce: true,
                    },
                }
            },
            minimize: !!uglify,
            minimizer: [
                new UglifyJsPlugin({
                    uglifyOptions: {
                        parallel: true,
                        cache: true,
                        output: {
                            comments: false,
                        },
                        compress: {
                            // The Android SBG has problems parsing the output
                            // when these options are enabled
                            'collapse_vars': platform !== "android",
                            sequences: platform !== "android",
                        }
                    }
                })
            ],
        },
        module: {
            rules: [
                {
                    test: new RegExp(entryPath),
                    use: [
                        // Require all Android app components
                        platform === "android" && {
                            loader: "nativescript-dev-webpack/android-app-components-loader",
                            options: { modules: appComponents }
                        },

                        {
                            loader: "nativescript-dev-webpack/bundle-config-loader",
                            options: {
                                angular: true,
                                loadCss: !snapshot, // load the application css if in debug mode
                            }
                        },
                    ].filter(loader => !!loader)
                },

                { test: /\.html$|\.xml$/, use: "raw-loader" },

                // tns-core-modules reads the app.css and its imports using css-loader
                {
                    test: /[\/|\\]app\.css$/,
                    use: {
                        loader: "css-loader",
                        options: { minimize: false, url: false },
                    }
                },
                {
                    test: /[\/|\\]app\.scss$/,
                    use: [
                        { loader: "css-loader", options: { minimize: false, url: false } },
                        "sass-loader"
                    ]
                },

                // Angular components reference css files and their imports using raw-loader
                { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" },
                { test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },

                // Compile TypeScript files with ahead-of-time compiler.
                {
                    test: /.ts$/, use: [
                        "nativescript-dev-webpack/moduleid-compat-loader",
                        "@ngtools/webpack",
                    ]
                },

                // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
                // Removing this will cause deprecation warnings to appear.
                {
                    test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
                    parser: { system: true },
                },
            ],
        },
        plugins: [
            // Define useful constants like TNS_WEBPACK
            new webpack.DefinePlugin({
                "global.TNS_WEBPACK": "true",
                "global.ENV_NAME": JSON.stringify(env.property || "prod")
            }),
            // Remove all files from the out dir.
            new CleanWebpackPlugin([ `${dist}/**/*` ]),
            // Copy native app resources to out dir.
            new CopyWebpackPlugin([
                {
                    from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
                    to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
                    context: projectRoot
                },
            ]),
            // Copy assets to out dir. Add your own globs as needed.
            new CopyWebpackPlugin([
                { from: "fonts/**" },
                { from: "**/*.jpg" },
                { from: "**/*.png" },
            ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
            // Generate a bundle starter script and activate it in package.json
            new nsWebpack.GenerateBundleStarterPlugin([
                "./vendor",
                "./bundle",
            ]),
            // For instructions on how to set up workers with webpack
            // check out https://github.com/nativescript/worker-loader
            new NativeScriptWorkerPlugin(),

            new AngularCompilerPlugin({
                host: platformHost,
                entryModule: resolve(appPath, "app.module#AppModule"),
                tsConfigPath: aot ? join(__dirname, "tsconfig.aot.esm.json") : join(__dirname, "tsconfig.esm.json"),
                skipCodeGeneration: !aot,
            }),
            // Does IPC communication with the {N} CLI to notify events when running in watch mode.
            new nsWebpack.WatchStateLoggerPlugin(),
        ],
    };

    if (report) {
        // Generate report files for bundles content
        config.plugins.push(new BundleAnalyzerPlugin({
            analyzerMode: "static",
            openAnalyzer: false,
            generateStatsFile: true,
            reportFilename: resolve(projectRoot, "report", `report.html`),
            statsFilename: resolve(projectRoot, "report", `stats.json`),
        }));
    }

    if (snapshot) {
        config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
            chunk: "vendor",
            angular: true,
            requireModules: [
                "reflect-metadata",
                "@angular/platform-browser",
                "@angular/core",
                "@angular/common",
                "@angular/router",
                "nativescript-angular/platform-static",
                "nativescript-angular/router",
            ],
            projectRoot,
            webpackConfig: config,
        }));
    }

    return config;
};
@alexmootassem
Copy link

Hi,

I got the exact same error when building a release on linux with --env.snapshot :

tns --version 5.0.1
node 10.12.0
"tns-android": {
    "version": "5.0.0"
}

when checking in /tmp/snapshot-tools/mksnapshot-tools/v8-v6.9.427.23/linux-x64/ the mksnapshot-ia32 file exists with right permissions.

Snapshots build directory: /root/mobile/platforms/android/app/snapshot-build/build
clean-webpack-plugin: /root/mobile/platforms/android/app/src/main/assets/app/**/* has been removed.

 Snapshotting bundle from /root/mobile/platforms/android/app/src/main/assets/app/snapshot-entry.js,/root/mobile/platforms/android/app/src/main/assets/app/vendor.js
Running snapshot generation with the following arguments: 
{
   "inputFiles": [
           "/root/mobile/platforms/android/app/src/main/assets/app/snapshot-entry.js",
           "/root/mobile/platforms/android/app/src/main/assets/app/vendor.js"
   ],
   "preprocessedInputFile": "/root/mobile/platforms/android/app/src/main/assets/app/_embedded_script_.js",
   "targetArchs": [
           "arm",
           "arm64",
           "ia32"
   ],
   "useLibs": false
}
Snapshot tools path: /tmp/snapshot-tools
Webpack compilation complete.
***** Starting snapshot generation using V8 version:  6.9.427.23
***** Generating snapshot for armeabi-v7a *****
***** Generating snapshot for arm64-v8a *****
***** Generating snapshot for x86 *****
Hash: 9f4961c982c30e0474c2
Version: webpack 4.26.1
Time: 12079ms
ERROR in NativeScriptSnapshot. Snapshot generation failed!
Target architecture: x86
/bin/sh: 1: /tmp/snapshot-tools/mksnapshot-tools/v8-v6.9.427.23/linux-x64/mksnapshot-ia32: not found

@anki247
Copy link

anki247 commented May 12, 2019

same issue here, since upgrading from NS4.2 to NS5.3. On v4.2 I had no problems...

tns --version 5.3.4
node 10.15.3
"tns-android": {
  "version": "5.3.1"
}
OS: MacOS

Error:

ERROR in NativeScriptSnapshot. Snapshot generation failed!
Target architecture: x86
/var/folders/2k/dgxjg1152_q954cyhfjwvd980000gn/T/snapshot-tools/mksnapshot-tools/v8-v7.3.492.25/darwin-x64/mksnapshot-ia32: line 1: syntax error near unexpected token `newline'
/var/folders/2k/dgxjg1152_q954cyhfjwvd980000gn/T/snapshot-tools/mksnapshot-tools/v8-v7.3.492.25/darwin-x64/mksnapshot-ia32: line 1: `<?xml version="1.0" encoding="utf-8"?>'

@rosen-vladimirov
Copy link
Contributor

Hey @anki247 ,
Can you please try deleting the following directory:

rm -rf /var/folders/2k/dgxjg1152_q954cyhfjwvd980000gn/T/snapshot-tools/

and try building again?

@Jmchemama
Copy link

Jmchemama commented May 13, 2019

Hello , i have same issue here

ERROR in NativeScriptSnapshot. Snapshot generation failed!
[19-05-13 12:26:21.936] (CLI) Target architecture: arm64-v8a
[19-05-13 12:26:21.936] (CLI) /var/folders/2v/6_1fbg5519qgn655q829h5_w0000gn/T/snapshot-tools/mksnapshot-tools/v8-v7.1.302.32/darwin-x64/mksnapshot-arm64: line 2: syntax error near unexpected token `newline'
[19-05-13 12:26:21.936] (CLI) /var/folders/2v/6_1fbg5519qgn655q829h5_w0000gn/T/snapshot-tools/mksnapshot-tools/v8-v7.1.302.32/darwin-x64/mksnapshot-arm64: line 2: `<?xml version="1.0" encoding="utf-8"?>'

I have remove snapshot-tools folder, restart and it works.

@anki247
Copy link

anki247 commented May 13, 2019

@rosen-vladimirov thank you very much, removing the folder helped me 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants