Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android AOT compilation fail #840

Closed
naturalfreak opened this issue Jun 10, 2017 · 3 comments
Closed

Android AOT compilation fail #840

naturalfreak opened this issue Jun 10, 2017 · 3 comments
Labels

Comments

@naturalfreak
Copy link

I got this error during AOT compilation on android device.

Please change the name of one of the extended classes.
/home/alexander/Projects/Improve/Improve-application/platforms/android/src/main/java/com/tns/gen/com/facebook/imagepipeline/animated/base/AnimatedDrawable_frnal_ts_helpers_l58_c38__AnimatedImage.java
        at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:59)
        at org.nativescript.staticbindinggenerator.Main.main(Main.java:15)
:asbg:generateBindings FAILED

FAILURE: Build failed with an exception.

package.json

"dependencies": {
    "@angular/animations": "^4.1.3",
    "@angular/common": "^4.1.3",
    "@angular/compiler": "^4.1.3",
    "@angular/core": "^4.1.3",
    "@angular/forms": "^4.1.3",
    "@angular/http": "^4.1.3",
    "@angular/platform-browser": "^4.1.3",
    "@angular/platform-browser-dynamic": "^4.1.3",
    "@angular/router": "^4.1.3",
    "ios-uuid": "./packages/ios-uuid-1.0.0.tgz",
    "loading-indicator": "./packages/loading-indicator-1.0.0.tgz",
    "nativescript-angular": "^3.0.0",
    "nativescript-camera": "^3.0.0",
    "nativescript-facebook": "^2.0.0",
    "nativescript-fresco": "^3.0.2",
    "nativescript-geolocation": "^3.0.0",
    "nativescript-google-maps-sdk": "^2.1.3",
    "nativescript-imagepicker": "^3.0.1",
    "nativescript-iqkeyboardmanager": "^1.0.1",
    "nativescript-push-notifications": "^0.1.3",
    "nativescript-socket.io": "^0.5.1",
    "nativescript-telerik-ui": "^2.0.1",
    "nativescript-telerik-ui-pro": "./packages/nativescript-ui-pro.tgz",
    "reflect-metadata": "^0.1.10",
    "rxjs": "~5.4.0",
    "tns-core-modules": "^3.0.1",
    "zone.js": "~0.8.11"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~4.1.3",
    "@ngtools/webpack": "1.4.1",
    "babel-traverse": "6.24.1",
    "babel-types": "6.24.1",
    "babylon": "6.17.0",
    "codelyzer": "^3.0.0",
    "copy-webpack-plugin": "~4.0.1",
    "extract-text-webpack-plugin": "~2.1.0",
    "filewalker": "^0.1.3",
    "jasmine-core": "^2.4.1",
    "karma": "^1.6.0",
    "karma-jasmine": "^1.0.2",
    "karma-nativescript-launcher": "^0.4.0",
    "lazy": "1.0.11",
    "nativescript-css-loader": "~0.26.1",
    "nativescript-dev-android-snapshot": "0.0.9",
    "nativescript-dev-typescript": "^0.4.5",
    "nativescript-dev-webpack": "^0.6.3",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.0.2",
    "tslint": "^5.3.2",
    "typescript": "^2.3.4",
    "webpack": "~2.6.1",
    "webpack-sources": "~0.2.3"
  }

webpack.config.js


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

const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");

const { AotPlugin } = require("@ngtools/webpack");

const mainSheet = `app.css`;

module.exports = env => {
    const platform = getPlatform(env);

    // Default destination inside platforms/<platform>/...
    const path = resolve(nsWebpack.getAppPath(platform));

    const entry = {
        // Discover entry module from package.json
        bundle: `./${nsWebpack.getEntryModule()}`,

        // Vendor entry with third-party libraries
        vendor: `./vendor`,

        // Entry for stylesheet with global application styles
        [mainSheet]: `./${mainSheet}`,
    };

    const rules = getRules();
    const plugins = getPlugins(platform, env);
    const extensions = getExtensions(platform);

    return {
        context: resolve("./app"),
        target: nativescriptTarget,
        entry,
        output: {
            pathinfo: true,
            path,
            libraryTarget: "commonjs2",
            filename: "[name].js",
        },
        resolve: {
            extensions,

            // Resolve {N} system modules from tns-core-modules
            modules: [
                "node_modules/tns-core-modules",
                "node_modules",
            ]
        },
        node: {
            // Disable node shims that conflict with NativeScript
            "http": false,
            "timers": false,
            "setImmediate": false,
            "fs": "empty",
        },
        module: { rules },
        plugins,
    };
};


function getPlatform(env) {
    return env.android ? "android" :
        env.ios ? "ios" :
        () => { throw new Error("You need to provide a target platform!") };
}

function getRules() {
    return [
        {
            test: /\.html$|\.xml$/,
            use: [
                "raw-loader",
            ]
        },
        // Root stylesheet gets extracted with bundled dependencies
        {
            test: new RegExp(mainSheet),
            use: ExtractTextPlugin.extract([
                {
                    loader: "resolve-url-loader",
                    options: { silent: true },
                },
                {
                    loader: "nativescript-css-loader",
                    options: { minimize: false }
                },
                "nativescript-dev-webpack/platform-css-loader",
            ]),
        },
        // Other CSS files get bundled using the raw loader
        {
            test: /\.css$/,
            exclude: new RegExp(mainSheet),
            use: [
                "raw-loader",
            ]
        },
        // SASS support
        {
            test: /\.scss$/,
            use: [
                "raw-loader",
                "resolve-url-loader",
                "sass-loader",
            ]
        },


        // Compile TypeScript files with ahead-of-time compiler.
        {
            test: /\.ts$/,
            loaders: [
                "nativescript-dev-webpack/tns-aot-loader",
                "@ngtools/webpack",
            ]
        }

    ];
}

function getPlugins(platform, env) {
    let plugins = [
        new ExtractTextPlugin(mainSheet),

        // Vendor libs go to the vendor.js chunk
        new webpack.optimize.CommonsChunkPlugin({
            name: ["vendor"],
        }),

        // Define useful constants like TNS_WEBPACK
        new webpack.DefinePlugin({
            "global.TNS_WEBPACK": "true",
        }),

        // Copy assets to out dir. Add your own globs as needed.
        new CopyWebpackPlugin([
            { from: mainSheet },
            { from: "css/**" },
            { from: "fonts/**" },
            { from: "**/*.jpg" },
            { from: "**/*.png" },
            { from: "**/*.xml" },
        ], { ignore: ["App_Resources/**"] }),

        // Generate a bundle starter script and activate it in package.json
        new nsWebpack.GenerateBundleStarterPlugin([
            "./vendor",
            "./bundle",
        ]),

        // Angular AOT compiler
        new AotPlugin({
            tsConfigPath: "tsconfig.aot.json",
            entryModule: resolve(__dirname, "app/app.module#AppModule"),
            typeChecking: false
        }),

        // Resolve .ios.css and .android.css component stylesheets, and .ios.html and .android component views
        new nsWebpack.UrlResolvePlugin({
            platform: platform,
            resolveStylesUrls: true,
            resolveTemplateUrl: true
        }),

    ];

    if (env.uglify) {
        plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));

        // Work around an Android issue by setting compress = false
        const compress = platform !== "android";
        plugins.push(new webpack.optimize.UglifyJsPlugin({
            mangle: { except: nsWebpack.uglifyMangleExcludes },
            compress,
        }));
    }

    return plugins;
}

// Resolve platform-specific modules like module.android.js
function getExtensions(platform) {
    return Object.freeze([
        `.${platform}.ts`,
        `.${platform}.js`,
        ".aot.ts",
        ".ts",
        ".js",
        ".css",
        `.${platform}.css`,
    ]);
}

@NickIliev
Copy link

@naturalfreak on a first glance I've noticed taht you are using both nativescript-telerik-ui and nativescript-telerik-ui-pro

    "nativescript-telerik-ui": "^2.0.1",
    "nativescript-telerik-ui-pro": "./packages/nativescript-ui-pro.tgz",

However the pro plugin includeds all the functionality that comes from the base version.
Perhaps you can try to use only of the plugins and rebuild your application with web pack.

@sis0k0
Copy link
Contributor

sis0k0 commented Jul 5, 2017

Hey @naturalfreak ,

If you have any native extender classes, please check out this issue: NativeScript/android#778

Also, can share the command that you use to build the project?

@sis0k0
Copy link
Contributor

sis0k0 commented Jul 5, 2017

This issue was moved to NativeScript/nativescript-dev-webpack#213

@sis0k0 sis0k0 closed this as completed Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants