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

Advertisements

I’m Back!

Its been a few months since I last posted mainly due to work commitments. During this time however I have also been working on a solo project called WeightMate an app currently available on Android. This post is just a welcome back and intro to my new project.

https://play.google.com/store/apps/details?id=com.babymax.weightmate

motivation_screen_grab

Focussing on good UX Design the aim was to create an application that would stand out in the Weight Tracker category as a “nice looking application” that hopefully people will be attracted to use. It also serves a purpose as an experiment to see if first impressions count when downloading apps. WIll users download an app with less functionality because it looks and feels better ? Will they be more patient because the app looks better ? Many questions I aim to find some answers to with this application.

Most importantly it serves as my dive back into android development after over a year hiatus. I love the design and development process and focussed on how best to do this. Being a developer we are classically tagged as not being able to design but thats not true sometimes we just don’t have the correct tools or knowledge of the correct tools (Il cover in another post). So I spoke to colleagues and friends about how they approach UX design in mobile apps. I looked around the market seen what other apps did and worked backwards from the negative comments to come up with a vision/concept of how I wanted it to look visually I then ran this by friends and family iterating over their feedback to come up with my final design.

From the development perspective I wanted to try something new I had recently read The Lean Startup and once of the concepts mentioned is the Build,Measure,Learn  cycle and MVP(Minimum Viable Product ) which I will discuss in a future post also.

motivation_device_grab

I have quite a few posts I want to cover in the next few days so I figure if I commit to them here I will have to write them

  • Lean Agile Principles
  • Lean Startup
  • Android Studio – Librarys
  • UX Tools for Developers
  • Development Best Practice