Search code examples
androidnativescriptgradlewtnsnativescript-schematics

My gradlew.bat keeps failing on tns build android


So I've been working with Angular-Nativescript for the past few months and had a project all working with Angular 9. After a short break I started working on another machine which had said project working on it but without remembering it was on Angular 7. I ran the script to upgrade Angular which took it straight to version 10 which is where my issues have all started. After all the installing, upgrading, migrating, downloading and re-installing, I'm able to generate, run and serve Angular components, but I can't build Nativescript. tns build android commands always runs till 55% then just throws out the error

Command gradlew.bat failed with exit code 1

I don't know where to look for more detailed information. I've tried echoing different steps in the batch file but can't tell what the issue if. Apologies if I'm not using the correct terms as I'm still fairly new to the frontend world.

Some supporting info... I have gotten to the point where I use an emulator on my machine. I installed Android Studio which is where I run the emulator from. So when I run tns devices, I can see a sample one as shown in the attached screenshot. From what I can tell, an apk file should be created and transferred to the emulator but I don't where to look to see if the file is being created but just not being transferred.

Any help would be appreciated with getting proper error of a fix if anyone knows what this.

The console text is

tns build android
Preparing project...
Hash: b88f22b61097dd6429ce
Version: webpack 4.44.0
Time: 72ms
Built at: 07/27/2020 18:00:16
  Asset       Size  Chunks             Chunk Names
main.js  958 bytes       0  [emitted]  main
Entrypoint main = main.js
[0] ./src/index.js 386 bytes {0} [built]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/
Project successfully prepared (android)
Building project...
Gradle build...
         + setting applicationId
         + applying user-defined configuration from C:\Repos\Sothecom\ManageTurns\src\Sothecom.ManageTurns.MobileWeb\baseline\App_Resources\Android\app.gradle
         + using android X library androidx.legacy:legacy-support-v4:1.0.0
         + adding nativescript runtime package dependency: nativescript-optimized-with-inspector
         + adding aar plugin dependency: C:\Repos\Sothecom\ManageTurns\src\Sothecom.ManageTurns.MobileWeb\baseline\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
Command gradlew.bat failed with exit code 1

The tns info is

tns info
√ Getting NativeScript components versions information...
√ Component nativescript has 6.7.8 version and is up to date.
√ Component tns-core-modules has 6.5.12 version and is up to date.
√ Component tns-android has 6.5.3 version and is up to date.
‼ Update available for component tns-ios. Your current version is 6.3.0 and the latest available version is 6.5.2.

I'm on a windows 10 laptop Device has been recognised


Solution

  • Truth is, Nativescript will fail seemingly randomly with no good reason pretty easily. I'm hoping someone in authority will shout me down on this (and enlighten me in the process), but I've had a number of episodes like the one you are having, and have a particularly weird one going on now (Why does Nativescript Static Binding Generator fail for no reason and no information?), so I'm not feeling charitable toward the keepers of this platform at the moment (or their lack of relevant documentation).

    My past sad experiences aside, what I can suggest is that you follow these steps:

    1. From the project root, run ./node_modules/.bin/update-ns-webpack --deps --configs to regenerate a 'clean' webpack configuration. If you have any customizations here (like to copy other file types), you may need to put these back later.
    2. remove the directories node_modules, hooks, and platforms (if you use custom hooks, you'll need to replace these later)
    3. tns build android --log trace

    if it fails, the log trace may give you some insights. The steps before are 'brute-force' workarounds suggested commonly by others, and I've found them to be generally effective (but not a cure-all).

    Good luck with your particular variant!