Brennan Hoeting
Brennan Hoeting

Reputation: 1213

Android Studio: Library not recognizing the Android API

I am trying to add this library to my project. I put the files from GitHub in my libraries directory under my project's default module folder.

When I first added the library, it wasn't recognized in my project until I changed the the folder structure from httpzoid/src/ to httpzoid/src/main/java.

At this point I am able to import classes from the library. The only problem is, Android components such as android.content.Context aren't recognized by the library, so it basically doesn't work.

Upvotes: 0

Views: 1482

Answers (1)

Marco RS
Marco RS

Reputation: 8245

The project does not have a Ant or Gradle build file so need to create one.

First you will need to delete the local.properties since it references the developers local sdk directory. Then create a file named build.gradle in the projects directory with the following content.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

apply plugin: 'android-library'

android {

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }

    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile 'com.google.code.gson:gson:2.2.4'
}

Then in command line go to the projects root directory and run "gradle build". This will generate the file "Httpzoid.aar" in the projects build/libs directory. Copy this file into your main project's libs folder.

You'll now be able to add it as a dependency by modifying your project's build.gradle file and adding the following:

dependencies {
    repositories {
        flatDir {
            dirs 'libs'
        }
    }

    compile(name:'Httpzoid', ext:'aar')
}

As an aside, have you considered using Retrofit or Ion as an alternative REST client? These two excellent libraries have similar callback mechanisms and both are actively updated (Last update for HttpZoid was July 22, 2013). Also they are both on Maven Central.

Upvotes: 2

Related Questions