This is basically a quick brain-dump post. I have previously attempted to get into Android application development, but with only 8-10 hours of “free” time per month, it was difficult to get traction with an app before the goog machine overhauled everything. This happened repeatedly. I had some great ideas for a mobile app over the weekend, and thought I’d give it another go and guess what? Everything is overhauled: Android Studio is the next big thing, ant builds are out and gradle builds are in. I decided to force myself to overcome my annoyances and try out Android Studio.
Android Studio is beautiful and operationally stable, although very buggy. I’ve found four bugs in less than two days. The biggest bug and usability issue, however, is in creating an Android Library project and adding a reference to it in another project.
Here are the steps I took to reference another project. These steps may not be accurate, but I don’t care. I figured they may help save someone some time.
Create an Android library project using Android Studio.
There’s a bug in Android Studio 0.1.3 which apparently does not mark android library projects as library projects, so navigate to MyLibProject/MyLib and change the android plugin reference to:
apply plugin: 'android-library'
- Create a main application project, in my case MyApplication2
- Add library as git submodule or nested directory under MyApplication2
- Edit settings.gradle in the main project to:
include ':MyLibProject:MyLib’, ':MyApplication2'
- Edit MyApplication2/build.gradle to compile the lib project in the dependencies task:
- Navigate to your library subdirectory and execute:
gradle clean && gradle assemble
- Press CTRL+ALT+SHIFT+S to open the Project Structure dialog
- Create a new module, change module name and point content root to MyLibProject
- Change Package name to the package name of your lib and press Finish
- Click MyApplication2 (not MyApplication2Project) in the Project Structure dialog and select the Dependencies tab.
- Click the green plus icon and select Library|Java
- Select MyLibProject/MyLib/build/bundle/release folder, choose Project Library, and hit ok
- Save. The library should now be usable.
These instructions may seem a bit hurried, but it should get the job done. I’ve run through numerous attempts at different options, and these are the only ones that seem to have stuck.
I might also mention, I’ve created an ANDROID_HOME environment variable to load in my shell which points to the sdk directory under the android-studio installation. I’ve also downloaded gradle-1.6 to ~/bin, and symlinked gradle to ~/bin/gradle which adds gradle to my path.