Nativescript 3 + Webpack build failed


#1

Updated the project to Nativescript 3 + Webpack and after I solved all Typescript errors and stuff I got this big BUILD FAILED.

I get this error when I run this command npm run start-android-bundle

FAILURE: Build failed with an exception.

* Where:
Build file 'PROJECT_PATH/platforms/android/build-tools/android-static-binding-generator/build.gradle' line: 254

* What went wrong:
Execution failed for task ':asbg:generateBindings'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

BUILD FAILED

My package.json file :

"nativescript": {
    "tns-ios": {
      "version": "3.1.0"
    },
    "tns-android": {
      "version": "3.1.1"
    }
  },
"dependencies": {
    "@angular/animations": "~4.1.0",
    "@angular/common": "~4.1.0",
    "@angular/compiler": "~4.1.0",
    "@angular/core": "~4.1.0",
    "@angular/forms": "~4.1.0",
    "@angular/http": "~4.1.0",
    "@angular/platform-browser": "~4.1.0",
    "@angular/router": "~4.1.0",
    "nativescript-accelerometer": "^2.0.1",
    "nativescript-angular": "^3.0.0",
    "nativescript-appversion": "^1.4.1",
    "nativescript-cardview": "^2.0.1",
    "nativescript-contacts-lite": "^0.2.3",
    "nativescript-email": "^1.4.0",
    "nativescript-ibeacon": "^0.8.1",
    "nativescript-iqkeyboardmanager": "^1.1.0",
    "nativescript-loading-indicator": "^2.3.2",
    "nativescript-localstorage": "^1.1.5",
    "nativescript-mixpanel": "^1.0.8",
    "nativescript-ngx-fonticon": "^2.2.1",
    "nativescript-pager": "^5.0.5",
    "nativescript-permissions": "^1.2.3",
    "nativescript-phone": "^1.3.0",
    "nativescript-status-bar": "^1.1.1",
    "nativescript-telerik-ui": "^3.0.4",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-timedatepicker": "^1.2.0",
    "nativescript-toast": "^1.4.5",
    "nativescript-trace-raven": "^1.0.0",
    "nativescript-virtual-ibeacon": "^0.8.4",
    "reflect-metadata": "~0.1.8",
    "rxjs": "^5.4.3",
    "tns-core-modules": "^3.1.0",
    "tns-platform-declarations": "^3.1.0",
    "worker-loader": "git+https://github.com/triniwiz/worker-loader.git",
    "zone.js": "~0.8.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~4.1.0",
    "@ngtools/webpack": "~1.5.0",
    "babel-traverse": "6.4.5",
    "babel-types": "6.4.5",
    "babylon": "6.4.5",
    "copy-webpack-plugin": "~4.0.1",
    "extract-text-webpack-plugin": "~3.0.0",
    "lazy": "1.0.11",
    "nativescript-bottombar": "^3.0.5",
    "nativescript-css-loader": "~0.26.0",
    "nativescript-dev-android-snapshot": "^0.*.*",
    "nativescript-dev-typescript": "^0.5.0",
    "nativescript-dev-webpack": "^0.7.3",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.1.0",
    "tns-platform-declarations": "^3.0.1",
    "typescript": "^2.4.2",
    "webpack": "~3.2.0",
    "webpack-bundle-analyzer": "^2.8.2",
    "webpack-sources": "~1.0.1"
  }

What is wrong ?
Thanks.


#2

Certainly, there is more to the build log than you are revealing. Would you share it, so that we can be of actual help to you?


#3

Hi Pete,

Sorry for delay, I was off last week.
So, I’ve attached some more logs. I hope they will be useful.

Thanks.

:config phase:  addAarDependencies
        +adding dependency: /PROJECT_PATH/platforms/android/libs/aar/Common-2017.1.719-dev-release.aar
        +adding dependency: /PROJECT_PATH/platforms/android/libs/aar/Data-2017.1.719-dev-release.aar
        +adding dependency: /PROJECT_PATH/platforms/android/libs/aar/List-2017.1.719-dev-release.aar
        +adding dependency: /PROJECT_PATH/platforms/android/libs/aar/nativescript-datetimepicker-release.aar
        +adding dependency: /PROJECT_PATH/platforms/android/libs/aar/Primitives-2017.1.719-dev-release.aar
        +adding dependency: /PROJECT_PATH/platforms/android/libs/aar/widgets-release.aar
The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
Incremental java compilation is an incubating feature.
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
        at build_ykvl1x99pjo7zwug5zr385z1.run(/PROJECT_PATH/platforms/android/build-tools/android-static-binding-generator/build.gradle:126)
:preBuild UP-TO-DATE
:preF0F1F2F3F4F5F6F7F8F9F10DebugBuild UP-TO-DATE
:checkF0F1F2F3F4F5F6F7F8F9F10DebugManifest
:preF0F1F2F3F4F5F6F7F8F9F10ReleaseBuild UP-TO-DATE
:prepareComAndroidSupportAnimatedVectorDrawable2531Library
:prepareComAndroidSupportAppcompatV72531Library
:prepareComAndroidSupportCardviewV72531Library
:prepareComAndroidSupportDesign2531Library
:prepareComAndroidSupportRecyclerviewV72531Library
:prepareComAndroidSupportSupportCompat2531Library
:prepareComAndroidSupportSupportCoreUi2531Library
:prepareComAndroidSupportSupportCoreUtils2531Library
:prepareComAndroidSupportSupportFragment2531Library
:prepareComAndroidSupportSupportMediaCompat2531Library
:prepareComAndroidSupportSupportV42531Library
:prepareComAndroidSupportSupportVectorDrawable2531Library
:prepareComAndroidSupportTransition2531Library
:prepareComAurelhubertAhbottomnavigation206Library
:prepareComEftimoffAndroidViewpagerTransformers101Library
:prepareComGoogleAndroidGmsPlayServicesBase840Library
:prepareComGoogleAndroidGmsPlayServicesBasement840Library
:prepareComGoogleAndroidGmsPlayServicesGcm840Library
:prepareComGoogleAndroidGmsPlayServicesMeasurement840Library
:prepareComMixpanelAndroidMixpanelAndroid498Library
:prepareCommon20171719DevReleaseLibrary
:prepareData20171719DevReleaseLibrary
:prepareList20171719DevReleaseLibrary
:prepareNativescriptDatetimepickerReleaseLibrary
:prepareOrgAltbeaconAndroidBeaconLibrary292Library
:preparePimRuntimeUnspecifiedLibrary
:preparePrimitives20171719DevReleaseLibrary
:prepareWidgetsReleaseLibrary
:prepareF0F1F2F3F4F5F6F7F8F9F10DebugDependencies
:compileF0F1F2F3F4F5F6F7F8F9F10DebugAidl
:compileF0F1F2F3F4F5F6F7F8F9F10DebugRenderscript
:generateF0F1F2F3F4F5F6F7F8F9F10DebugBuildConfig
:cleanLocalAarFiles
:ensureMetadataOutDir
:collectAllJars
:setProperties
:generateTypescriptDefinitions SKIPPED
:copyTypings SKIPPED
:asbg:generateInterfaceNamesList
:asbg:traverseJsFiles
:asbg:runAstParser
Running full build
finished with reading lines with js files
Warning: there already is an extend called com.tns.FragmentClass.
Warning: The static binding generator will generate extend from:d1f70040dab2b39e6eb1.worker.js implementation
:asbg:generateBindings
Exception in thread "main" java.io.IOException: File already exists. This may lead to undesired behavior.
Please change the name of one of the extended classes.
File:/PROJECT_PATH/platforms/android/src/main/java/com/tns/FragmentClass.java Class: com.tns.FragmentClass
        at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:68)
        at org.nativescript.staticbindinggenerator.Main.main(Main.java:15)
:asbg:generateBindings FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/PROJECT_PATH/platforms/android/build-tools/android-static-binding-generator/build.gradle' line: 254

* What went wrong:
Execution failed for task ':asbg:generateBindings'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 19.903 secs
Command ./gradlew failed with exit code 1

#4

I see that you have worker scripts in your app. Did you configure the worker loader plugin properly for NativeScript? If so, then you would also have to use the latest of the android-runtime. tns platform add android@rc or tns platform add android@next.


#5

I also had a similar error using worker loader from github:nativescript/worker-loader and i can confirm it is not working with tns-android v3.1.1.
Using @next as Pete suggested did solve the problem.

You might also need to transpile manually before webpacking, as it might be looking for your js at the component’s folder, which will not be there since webpack is transpiling into the bundle.js. It depends on your file loading in your worker.


#6

I use worker-loader as a dependency for nativescript-contacts-lite according to the plugin doc. Should I make other configuration ?
I changed the version of android with both android@rc and android@next but it still doesn’t work.


#7

Check out the worker-loader README at https://github.com/NativeScript/worker-loader. There’s also a demo project which you could copy the relevant worker configuration from.


#8

Did you add ‘worker-loader!’ to your require?
Did you remember to add the ‘js’ file extension?
Did you try to transpile before packing?

If you haven’t tried it, I would first make sure everything runs without webpack, just tns run android. Once this is working, make sure you have all of the above set. Also check the tns-android package.json to make sure you have the latest version really installed.


#9

I think I found the problem on my project.

According to this issue the errors is because I use getContactsWorker and this method still has problems with worker-loader.
I used the work around from there and it’s working.

Thanks guys.