If your on Linux or OSX you can skip this post; it only applies to us pathetic people that prefer Windows (like me ). I do have Linux and OSX, so maybe I'm not that pathetic; but since I do prefer Windows, maybe I am.
If you don't want to read the reason this occurs but all you want is the fix; then scroll down to the fix!
Well if you see this error: Command [Some Path]\gradlew.bat failed with exit code 1 then you more than likely ran into this error if you see a lot of messages above it with "No Delegate Set" and errors.
Well to understand the issue you need to understand that this is a issue between Windows, Gradle and how NativeScript (A fix might show up by v1.8 of NativeScript) currently does Android plugins. Windows, if it supported larger path sizes; this wouldn't be an issue (which is why it works on Mac/Linux). NativeScript if it handled plugins differently might not run into this issue either. But at the current place we are at; it does so here is the crux of the issue.
1. Windows only supports 255 character path sizes (if they are not UNC or Unicode path's)
2. NativeScript scans all your plugins; any that have a platforms/android folder; it will use the include.gradle file found in that folder. If there is NOT a include.gradle file; it will create one for you using the plugin name as the information.
3. Gradle combines all the productFlavors (which are inside the include.gradle files) into one long string.
Ok, lets look at a sample include.gradle file (this is also what is also generated for you, if it doesn't exist)
So lets pretend your code exists at: C:\nativescript\AwesomeProject\
, so there is (32) characters. Now add platforms\android\
(18). Next add build\intermediates\res\merged\
(31) as this is where Gradle does its resource merging. So lets say you are using the Telerik NativeScript UI plugin; and lets grab one of the image names \debug\drawable-xxhdpi\someimage.png
which is of course adds another 49 characters. So this means we are using 130 characters already; leaving us with 122 characters left to play with.
So if you have a plugin installed like nativescript-websockets you get 23 characters used just for a single plugin. I bet you can see where this is going. Add on the cool nativescript-telerik-ui plugin and you have another 23 characters used. Add just a couple more plugins, and yes -- you are now well over 255 character limit!
Guess what happens??? Well if you are following the story so far; you get a nice error that gradle quit with error 1.
Now for the good news; here is how you can continue developing!
- Go to your app folder and do a tns platform remove android to safely recover, you need to kill your existing android platforms folder.
- Go into you node_modules folder, and then you need to repeat this next set of steps for EACH of the plugins you have installed.
- Do a nativescript platform add android to re-install the platform after you are all done, and then you should be good to go.
Please note this potential side effect: I have confirmation below that if you are using a plugin that requires additional permissions; this work around will unfortunately not merge the info from the plugins AndroidManifest.xml file. With all the plugins I had, I never saw this issue; but depending on what you are doing this is something you may run into. You have two choices to deal with this:
- Don't rename that specific plugin inside the include.gradle file. This way the AndroidManifest.xml file will get merged properly. You an afford a couple plugins to still have large names.
- Copy the information that you need (like permissions) from the plugins AndroidManifest and manually merge it into your master manifest located at App/App_Resources/Android/AndroidManifest.xml
The bug report so you can track this is Android/369 and based on the conversation with the NativeScript devs this should hopefully be fixed in v1.8 (but no promises).