I have migrated my project from eclipse to android studio successfully and a default build.gradle file has been generated. The project builds correctly and I can deploy to debug etc.
The real problem though is building release APK files (from the command line) for which I used to have a custom ant-build (called via command line, not out of eclipse).
My custom build.xml imported the standard sdk build.xml file from the SDK folder via:
<import file="${sdk.dir}/tools/ant/build.xml" />
So all I had to do in my build.xml was to override targets or hook into them via "depends".
An example for an override:
<target name="-set-release-mode" depends="-set-mode-check">
<!--Here I rename my output apk files to something like: myapp-versionFromAndroidManifest.apk -->
</target
And an example for adding dependency:
<target name="-pre-build" depends="clean">
<!-- my custom code where I copy resource files, process command line arguments
use xpath to extract things like the version from the AndroidManifest.xml and
write them into custom xml files etc... -->
</target
So overall the whole affair was really simple using ant. But now when it comes to migrating to gradle I am at a total loss, how to accomplish the same that I previously did in ant, specifically:
I googled a bunch of tutorials, also migration tutorials like (which unfortunately didn't address my issues):
http://keepsafe-engineering.tumblr.com/post/87818767721/migrating-android-app-from-ant-to-gradle
http://ryanharter.com/blog/2013/07/17/migrating-android-projects-to-gradle/
I also read this chapter from the gradle docs which didn't really help at all, because it does not answer question 1 or 2 or 3 for that matter:
http://www.gradle.org/docs/current/userguide/ant.html
The following gave some interesting pointers though:
http://toastdroid.com/2014/03/28/customizing-your-build-with-gradle/
I also tried simply copying the default build.xml from the sdk folder into my own build.xml and then simply importing that ant build file in gradle and executing the ant task that kicks of the build:
<target name="release"
depends="-set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"
description="Builds the application in release mode.">
</target>
but I started running into problems that suggested this is not an option anymore, since the default build.xml started throwing errors, that seemed related to the SDK version. And I had to mess around a lot with the original sdk build.xml because of the new android studio project structure, so files were not where they were expected etc...
gradlew tasks
at
the root of your project.init.dependsOn anotherTask
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With