Here's what has worked for me.
on the command line go to the root directory of the project
ensure that your JAVA_HOME environment variable points to the version of the java sdk you are going to use. On a Mac via the bash shell that would look something like this:
export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home'
(click here to find out how to find your Java Home)
- To clean type ./gradlew clean
- To build the library type ./gradlew aR (This may take a while)
You should now find the .aar file in mymodulename/build/outputs/aar
Thanks to geekgarage for clarification.