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

Android build fails. Webpack + Jscrambler. #326

Closed
terreb opened this issue Nov 17, 2017 · 2 comments
Closed

Android build fails. Webpack + Jscrambler. #326

terreb opened this issue Nov 17, 2017 · 2 comments

Comments

@terreb
Copy link

terreb commented Nov 17, 2017

I'm building my vanila nativescript project with webpack + jscrambler. For iOS it builds with no issues, however for Android it fails with "[ERROR] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory".

My environment:

tns cli 3.3.0

package.json

{
  "nativescript": {
    "id": "com.example.app",
    "tns-android": {
      "version": "3.3.0"
    },
    "tns-ios": {
      "version": "3.3.0"
    }
  },
  "dependencies": {
    "nativescript-appversion": "^1.4.1",
    "nativescript-background-http": "^3.1.0",
    "nativescript-bitmap-factory": "^1.7.1",
    "nativescript-camera": "^3.0.2",
    "nativescript-cardview": "^2.0.2",
    "nativescript-carousel": "^3.1.0",
    "nativescript-drop-down": "^3.1.1",
    "nativescript-feedback": "^1.0.6",
    "nativescript-fresco": "^3.0.6",
    "nativescript-imagepicker": "^3.0.2",
    "nativescript-intl": "0.0.10",
    "nativescript-iqkeyboardmanager": "^1.1.0",
    "nativescript-loading-indicator": "^2.4.0",
    "nativescript-localstorage": "^1.1.5",
    "nativescript-permissions": "^1.2.3",
    "nativescript-pro-ui": "^3.1.4",
    "nativescript-push-notifications": "^0.1.5",
    "nativescript-sqlite": "^1.1.7",
    "nativescript-unit-test-runner": "^0.3.4",
    "tns-core-modules": "^3.3.0"
  },
  "devDependencies": {
    "awesome-typescript-loader": "~3.1.3",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-traverse": "6.25.0",
    "babel-types": "6.25.0",
    "babylon": "6.17.4",
    "chai": "^3.5.0",
    "copy-webpack-plugin": "~4.0.1",
    "extract-text-webpack-plugin": "~3.0.0",
    "jscrambler-webpack-plugin": "^1.3.3",
    "karma": "^1.7.0",
    "karma-chai": "^0.1.0",
    "karma-mocha": "^1.3.0",
    "karma-nativescript-launcher": "^0.4.0",
    "lazy": "1.0.11",
    "nativescript-css-loader": "~0.26.0",
    "nativescript-dev-sass": "^1.3.2",
    "nativescript-dev-typescript": "~0.5.0",
    "nativescript-dev-webpack": "^0.8.0",
    "nativescript-worker-loader": "~0.8.1",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.1.0",
    "tns-platform-declarations": "^3.2.0",
    "typescript": "~2.2.1",
    "uglifyjs-webpack-plugin": "^1.0.0-beta.2",
    "webpack": "~3.2.0",
    "webpack-bundle-analyzer": "^2.8.2",
    "webpack-sources": "~1.0.1"
  },
  "scripts": {
    "update-ns-webpack": "update-ns-webpack",
    "ns-bundle": "ns-bundle",
    "publish-ios-bundle": "npm run ns-bundle --ios --publish-app",
    "generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install",
    "start-android-bundle": "npm run ns-bundle --android --run-app",
    "start-ios-bundle": "npm run ns-bundle --ios --run-app",
    "build-android-bundle": "npm run ns-bundle --android --build-app",
    "build-ios-bundle": "npm run ns-bundle --ios --build-app"
  }
}

Error:

Running full build
Warning: there already is an extend called undefined.
Warning: The static binding generator will generate extend from:vendor.js implementation

<--- Last few GCs --->

[3765:0x102801600] 120827 ms: Mark-sweep 1403.2 (1463.6) -> 1403.1 (1432.6) MB, 3170.3 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 3170 ms) last resort
[3765:0x102801600] 123679 ms: Mark-sweep 1403.1 (1432.6) -> 1403.1 (1432.6) MB, 2852.6 / 0.0 ms last resort

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x13f996a266a1
1: get [/Users/user/Documents/dev/NativeScript/MyApp/node_modules/babel-traverse/lib/path/index.js:~76] [pc=0xfd743b32069](this=0x284745236711 <JS Function NodePath (SharedFunctionInfo 0x317ec69995a1)>,_ref=0x3fe4114bab71 <an Object with map 0x3405d470ec79>)
2: node [/Users/user/Documents/dev/NativeScript/MyApp/node_modules/babel-traverse/lib/index.js:~94] [pc=0xfd743bbfcee](t...

gave the following error:
[ERROR] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
5: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
6: 0xfd74390ed46
7: 0xfd743b32069

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1967)
at org.nativescript.staticbindinggenerator.Generator.getBaseDir(Generator.java:307)
at org.nativescript.staticbindinggenerator.Generator.generateBinding(Generator.java:86)
at org.nativescript.staticbindinggenerator.Generator.processRows(Generator.java:157)
at org.nativescript.staticbindinggenerator.Generator.generateBindings(Generator.java:77)
at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:54)
at org.nativescript.staticbindinggenerator.Main.main(Main.java:15)

FAILURE: Build failed with an exception.

  • Where:
    Build file '/Users/user/Documents/dev/NativeScript/MyApp/platforms/android/build-tools/android-static-binding-generator/build.gradle' line: 279

  • What went wrong:
    Execution failed for task ':asbg:generateBindings'.

Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

@NickIliev
Copy link
Contributor

@terreb try increasing your heap with the solution suggested here

@terreb
Copy link
Author

terreb commented Nov 28, 2017

@NickIliev, thank you, but I did try all of those before and it didn't help.

The Jscrambler support helped me to fix the issue. This is their reply "...the problem lies in the usage of the duplicateLiterals removal transformation. Since you have a lot of numbers in your source code, the transformation is generating a bundle that can go up to 10 times the size of the original. " I adjusted jscrambler.json like they had suggested and it fixed the issue for me. Maybe this will be useful for someone else struggling with the error.

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

No branches or pull requests

2 participants