Android Studio – Importing Library Projects

So Recently I moved to using Android Studio as my primary development environment for Android of course. The switch was simple and Studio has some really nice productivity feature to help you write code quickly. However I did find that importing library projects a little tricky initially especially having little to no knowledge of Gradle and how it works. So I thought I would write up a short post describing how.

Steps to Import Android Library to your Project

  1. Create folder in top level called libraries (same level as target,.idea)
  2. copy the library project into this folder
  3. Open Project Structure (Right-Click on Top Level Project)
  4. Click + icon towards top left
  5. Import Module
  6. Import the module you copied into libraries
  7. Click on the library name (left hand nav bar)
  8. If the library you are using has any dependencies that your project uses you can remove these on dependency tab (i.e Support Libs)
  9. Click on your project in the left hand nav bar
  10. Select dependency tab and add the new library module to your project, Apply and close

Thats the basic setting to apply a module to your project running the project will probably result in Gradle errors at this stage, because Gradle cant build the project or even find it. Edit the following files

settings.gradle 

include ':libraries:library-name',':project_name'

project_name/project_name/build.gradle

add in

    compile project (':libraries:view-pager')

Finally

If building the code at this point still gives you gradle errors your library project probably cant be built because it doesnt have an appropriate build.gradle using this template build file should help you get the project building.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 16
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

Hopefully this short guide will help anyone that faced the same problems I had at the beginning

This Week – Nexus 7, Apps and new ADK

This week has been a busy week, I decided to start some Android Development again and I finally got my Nexus 7 tablet.  Let’s start with the Nexus.

Google’s Nexus 7 Tablet

I own an iPad that I won but other than that I have always owned Android devices and favored them over Apple’s due to the fact I can easily customize and develop applications for them but had to admit the iPad was probably the best tablet on the market albeit overpriced.

The Nexus 7 changes this, starting at £159.00 this tablet is perfect for EVERYONE and that really is the key. The new Android 4.1 Jellybean OS is quick and smooth, the UI is simpler and getting more and more intuitive to use to the extent that I now prefer it over Apples equivalent.  The display is bright and crisp, movies look stunning and apps look better than ever too.  So far I am very happy with my purchase the 7″ isnt too small as I had previously feared when I moved from the iPad, If anything the 7″ feels much more natural when traveling.

The Nexus 7 : Sleek

Apps for Nexus 7

I needed some new apps for my tablet so this forced me into the bowels of the play store where I found a few games that you may not have came across but are definitely worth a download. But first one app that came with the Nexus was Google Now and its really impressing me.

….
Google Now
I launched it and it told me the weather based on my current location, as you may expect this wasn’t a big deal but then I went to work and when I arrived Google now had taken the trouble to work out when the trains where coming to take me home,  how long my journey would take driving, traffic density you name it. It comes with the Nexus if you haven’t played with it please do its a great application.

Major Mayhem 

Adult Swim Games created this side scrolling shoot em up which is one of the best games I have played on the Android platform to date really very addictive give it a try. There are plenty of levels and even replayability with new guns and armor to be unlocked and old scores to be broken. I really like this game one of my favorites on the Android platform.

Dead Trigger 

Zombie Survival game come FPS, great graphics and looks great on the Nexus worth a try. Havent played too much of it yet, All I can say is that the graphics are really smooth and console quality and controls take some getting used to but really nice.