{"id":270,"date":"2016-03-09T01:50:51","date_gmt":"2016-03-09T01:50:51","guid":{"rendered":"http:\/\/fluentreports.com\/blog\/?p=270"},"modified":"2016-03-09T14:27:02","modified_gmt":"2016-03-09T14:27:02","slug":"nativescript-android-plugins-and-windows-path-size-issues","status":"publish","type":"post","link":"http:\/\/fluentreports.com\/blog\/?p=270","title":{"rendered":"NativeScript: Android plugins and Windows path size issues"},"content":{"rendered":"<p>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.<\/p>\n<p>If you don't want to read the reason this occurs but all you want is the fix; then scroll down to <a href=\"#theFix\">the fix<\/a>!<\/p>\n<p>Well if you see this error: <strong>Command [Some Path]\\gradlew.bat failed with exit code 1<\/strong> then you more than likely ran into this error if you see a lot of messages above it with \"No Delegate Set\" and errors.<\/p>\n<p>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.<\/p>\n<p>1. Windows only supports 255 character path sizes (if they are not UNC or Unicode path's)<\/p>\n<p>2. NativeScript scans all your plugins; any that have a platforms\/android folder; it will use the <em>include.gradle<\/em> file found in that folder.\u00a0 If there is NOT a <em>include.gradle<\/em> file; it will create one for you using the plugin name as the information.<\/p>\n<p>3. Gradle combines all the productFlavors (which are inside the <em>include.gradle<\/em> files) into one long string.<\/p>\n<p>Ok, lets look at a sample <em>include.gradle<\/em> file (this is also what is also generated for you, if it doesn't exist)<br \/>\n<pre>android {\n&nbsp;&nbsp;&nbsp;&nbsp;productFlavors {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;nativescript-websockets&quot; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dimension &quot;nativescript-websockets&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}<\/pre><br \/>\nSo lets pretend your code exists at: <strong>C:\\nativescript\\AwesomeProject\\<\/strong>, so there is (32) characters. Now add <strong>platforms\\android\\<\/strong> (18). Next add <strong>build\\intermediates\\res\\merged\\<\/strong> (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 <strong>\\debug\\drawable-xxhdpi\\someimage.png<\/strong> 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.<\/p>\n<p>So if you have a plugin installed like <strong>nativescript-websockets<\/strong> you get 23 characters used just for a single plugin. I bet you can see where this is going. Add on the cool <strong>nativescript-telerik-ui<\/strong> plugin and you have another 23 characters used. Add just a couple more plugins, and yes -- you are now well over 255 character limit!<\/p>\n<p>Guess what happens??? \u00a0\u00a0 Well if you are following the story so far; you get a nice error that gradle quit with error 1.<\/p>\n<div id=\"theFix\"><\/div>\n<h2>The Fix:<\/h2>\n<p>Now for the good news; here is how you can continue developing!<\/p>\n<ol>\n<li>Go to your app folder and do a <strong>tns platform remove android <\/strong>to safely recover, you need to kill your existing android platforms folder.<\/li>\n<li>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.\n<ul>\n<li>Enter that plugins platforms\\android folder and edit the <em>include.gradle<\/em> -- if that folder doesn't exist then you are done and can skip this plugin.\u00a0 If the folder exists but the <em>include.gradle<\/em> file doesn't exist you can choose to ignore it or create your own.\u00a0 DO NOT create a platforms\\android folder, if it doesn't exist. Only create a <em>include.gradle<\/em> if the plugin already has a platforms\\android folder and it doesn't have a <em>include.gradle<\/em>.<\/li>\n<li>Edit the <em>include.gradle<\/em> and make the name shorter; this is the formula that I used.\u00a0\u00a0 Replace nativescript with \"ns\", eliminate any dashes, and then use the first letter for each word in the plugin.\u00a0\u00a0 So \"nativescript-cardview\" becomes \"nscv\",and \"nativescript-telerik-ui\" becomes \"nstu\". So the <em>include.gradle<\/em> changes from above (nativescript-websockets) to:<br \/>\n<pre>android {\n&nbsp;&nbsp;&nbsp;&nbsp;productFlavors {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;nsws&quot; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dimension &quot;nsws&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}<\/pre><br \/>\nPretty simple huh?\u00a0\u00a0 By shorting the name, you go from 23 character per plugin to 4 characters per plugin. \u00a0 So you can now easily fit 5 plugins in the same space it used to take for 1 plugin.\u00a0 Please make sure the total letters are unique -- don't have two plugins with the same name (i.e. \"nsws\" for nativescript-websockets and nativescript-webserver)\u00a0 as the same name, make them distinct.\u00a0 Having duplicate names will probably break Gradle.<\/li>\n<\/ul>\n<\/li>\n<li>Do a <strong>nativescript platform add android<\/strong> to re-install the platform after you are all done, and then you should be good to go.<\/li>\n<\/ol>\n<p>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.\u00a0\u00a0 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.\u00a0\u00a0 You have two choices to deal with this:<\/p>\n<ol>\n<li>Don't rename that specific plugin inside the include.gradle file.\u00a0 This way the AndroidManifest.xml file will get merged properly.\u00a0\u00a0 You an afford a couple plugins to still have large names.<\/li>\n<li>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<\/li>\n<\/ol>\n<p>The bug report so you can track this is <a href=\"https:\/\/github.com\/NativeScript\/android-runtime\/issues\/369\" target=\"_blank\">Android\/369<\/a> and based on the conversation with the NativeScript devs this should hopefully be fixed in v1.8 (but no promises).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip; <a class=\"more-link\" href=\"http:\/\/fluentreports.com\/blog\/?p=270\">Continue reading <span class=\"screen-reader-text\">NativeScript: Android plugins and Windows path size issues<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[15,51,39],"tags":[17,16,34,59],"class_list":["post-270","post","type-post","status-publish","format-standard","hentry","category-nativescript","category-plugins","category-tips","tag-android","tag-nativescript","tag-plugins","tag-windows","entry"],"_links":{"self":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=270"}],"version-history":[{"count":4,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":274,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/270\/revisions\/274"}],"wp:attachment":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}