Sunday, May 31, 2015

Android command line project creation and gradle

Here's another instance where Android's lousy documentation is just plain wrong AGAIN.  When you create a project using android project create as per their documentation you will see there is no gradle file.  I've tested this on my Ubuntu 15.04 running openjdk7.

It will then say to build or run your project run the non-existant ./gradlew file.  What you need to do is as per stackoverflow is to add a --gradle and a --gradle-version to the project create command that is nowhere mentioned in google's documentation.  Seriously Google, you don't have enough money or staff to run once through your docs to discover that when people RTFM they don't actually work.

Again one has to find the answers on stackoverflow.  I'd find the right place to report it, but someone already told you that you have the wrong packages listed for Ubuntu since years and you never bothered with it.

Part 1: change how you create the project:

$ android create project --path FrustratedDev2 --activity FrustratedDev2 --package com.somewhere.killme --target "android-21" --gradle --gradle-version '1.2.3'

Part 2: Play with config file it never mentioned that is created wrong by default:

$ vi gradle/wrapper/gradle-wrapper.properties

Change:

distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

to:

distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip

Part 3: Update proguard minify options that don't work android put there somehow:
$ vi build.gradle

Change:

runProguard false
proguardFile getDefaultProguardFile('proguard-android.txt')

To:

minifyEnabled false


And if everything is in order; now you can build a debug APK file:

$ ./gradlew assembleDebug

PS: Even though the docs say you need to run chmod +x gradlew; that's wrong too - you don't have to now ; it's created executable by default.

PS: Reported it to Google here on their bug report for documentation : Let's see how long it's ignored for.

No comments:

Post a Comment