• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Gradle in Android for a simple helloworld js app


Jan 15, 2016

as I move deeper into software development, I always encountered some hurdles. Some kind of complexities in development which at first I haven't had the chance to try out. For example I tried git for svn, now I learned it and it has integrated in my soft dev most of the times for the past 2 years. I realized I should have used it before and save a ton headache managing my project history. Now here comes build systems. I just heard of it on my early days as Android dev a year ago and never even bothered by it since eclipse and similar IDEs has this play button which is going nice for me. I clicked it and my app runs on my phone. As I learn more about this build system from here, I realized I traveled into a very bad path. I am eager to believe, building systems like gradle is very very important and I got no knowledge of it whatsoever. I barely grasp gradle and build systems in general. I am developing an app which has a component written in js just for fun.

There is gradle link for js here. The guy who posted the article seems to me working on an enterprise app. This is complicated and confusing for me. Its too much to handle. What I basically need something like this.

I develop a js app which I place in myjsproject folder. Obviously it has an index.html file, I have js src files in src/ folder and lib files in lib/ folder (I have libraries like Polymer, and Require.js; I am not planning to pull them off in a central repo). As I developed my app and feel quite good about it I wanna run a build script which will copy all the contents of myjsproject folder (I am not into minification yet, just copy and run the index.html file) into my Android projects app/assets/www folder. Because what I usually does is to copy paste file back and forth and maintain two project files. It is very stupid, noobish, primitive. I don't like this, gradle does make sense at this point. I also need to run a command like
gradle appbrowser
, which basically do the same thing but instead copy the file into a bin folder (minification can be done here along with combining amd modules via require.js) and then paste it to my xampp/htdocs/js/myjsproject/. There I open it from my browser. Simple. I wanna have a groundwork in Gradle so I am starting small :p.

Also I wanted to augment gradle build script of my Android project app such that each time the Android Studio run the build script for my Android project it also run the build script for myjsproject which basically copies all the files inside excluding the *.gradle files and git files and pasting them to app/assets/folder

Unfortunately even this simple build script of copy pasting a code inside the root directory doesn't work. I
task copyTask(type : Copy) {
        println 'Copying files'
        from 'copyContents'
        into 'sample/'

        println 'Finished copying'

task build (dependsOn : 'copyTask') <<
    println "building..."

I don't know why this doesn't work. copyContents folder is empty. There is not even a sample/ folder in the root directory.

Even the company I am working on I believe doesn't deal with build system. So I don't know how I could learn gradle by doing just as I learn Git by doing it. User Guide isn't helping. They keep saying its like "Maven /Ant". The hell I don't even know those two! Some part of gradle doesn't make sense to me maybe until I met the day I need to use it? I am confuse as to how to utilize gradle in my project. I am in dire need of automation as of the moment.


We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.