Groceries sample Android build fails with webpack and --uglify flag


#1

Hey all,

So I’ve hit a weird bug when trying to use UglifyJS on the NativeScript Groceries sample and I could use some help. Here’s how you can recreate the problem.

git clone https://github.com/NativeScript/sample-Groceries.git
cd sample-Groceries
npm install
npm run start-android-bundle --uglify

Here’s the exception.

Exception in thread "main" java.io.IOException: File already exists. This may lead to undesired behavior.ateBindings
Please change the name of one of the extended classes.
File:/Users/tj/dev/nativescript/sample-Groceries/platforms/android/src/main/java/com/tns/gen/java/lang/Object_frnal_ts_helpers_l58_c38__t.java Class:
        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 '/Users/tj/dev/nativescript/sample-Groceries/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_65.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

The same build works if I remove the --uglify flag. After some looking around it looks like I’ve probably hit this issue, but that doesn’t help me figure out how to workaround this; the error message isn’t the most descriptive one I’ve ever seen.

Any help would be really appreciated. Thanks!


#2

Hey TJ,

Looks like the addition of this class 18 hours ago breaks Uglify: https://github.com/NativeScript/NativeScript/blob/master/tns-core-modules/ui/frame/fragment.transitions.android.ts

I think once the code is stable (not saying it isn’t) the listener needs to be added to nativescript-dev-webpack’s mangle excludes.

You may want to lock tns-core-modules to a specific version (it’s now referring to “next”) to avoid these sudden problems.


#3

Thanks @Eddy!

I can’t believe I didn’t realize that repo was using the “next” modules :stuck_out_tongue: When I went back to the latest stable release I was indeed able to do what I needed to do.

Also, Stanimira fixed the underlying problem in like a matter of an hour or so (https://github.com/NativeScript/nativescript-dev-webpack/pull/246), so we should be good there too.

:tada:


#4

Ha lol I didn’t even see that fix yet - awesome! :heart_eyes:


#5

I am having same problem :frowning: . How can I solve this problem?

All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬───────────────┐
│ Component │ Current version │ Latest version │ Information │
│ nativescript │ 3.1.3 │ 3.1.3 │ Up to date │
│ tns-core-modules │ 3.1.1 │ 3.1.1 │ Up to date │
│ tns-android │ 3.1.1 │ 3.1.1 │ Up to date │
│ tns-ios │ │ 3.1.0 │ Not installed │
└──────────────────┴─────────────────┴────────────────┴───────────────┘

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:D:\Others\Documents\My_Work\SN_NativeScript_Final_WebPack\platforms\android\src\main\java\com\tns\gen\java\lang\Object_frnal_ts_helpers_l58_c38__t.java Class:
        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 'D:\Others\Documents\My_Work\SN_NativeScript_Final_WebPack\platforms\android\build-tools\android-static-binding-generator\build.gradle' line: 254

* What went wrong:
Execution failed for task ':asbg:generateBindings'.
> Process 'command 'C:\Program Files\Android\Android Studio\jre\bin\java.exe'' finished with non-zero exit value 1

mangle-excludes.js

    "AnimationListnerImpl",
    "AnimationListenerImpl",
    "TransitionListenerImpl",
    "CheckedChangeListenerImpl",

#6

I do not think that feature can work on windows as yet, or maybe it could be snapshot only see here: http://docs.nativescript.org/best-practices/bundling-with-webpack otherwise you can check here where there is an open issue: https://github.com/NativeScript/nativescript-cli/issues/2972