Android的工作室:库不承认Android的API [英] Android Studio: Library not recognizing the Android API

查看:290
本文介绍了Android的工作室:库不承认Android的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充库到我的项目。我把文件从GitHub在我的目录下我的项目的默认文件夹的模块

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.

当我第一次添加的图书馆,它不是在我的项目,直到承认我改变了文件夹结构从 httpzoid / src目录/ httpzoid / src目录/主/ JAVA

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.

在这一点上我能够从库中导入类。唯一的问题是,Android的组件,如 android.content.Context 不被认可的库,因此,它基本上是行不通的。

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.

推荐答案

该项目没有一个Ant或摇篮建立文件,所以需要创建一个。

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

首先,你将需要删除local.properties因为它引用了本地开发商SDK目录。然后创建一个与下面的内容项目目录命名的build.gradle文件。

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'
}

然后在命令行进入项目的根目录,然后运行gradle这个建。这将在项目文件Httpzoid.aar建设/ libs目录。这个文件复制到您的主项目的libs文件夹中。

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.

您现在就可以将其添加为一个依赖通过修改项目的build.gradle文件并添加以下内容:

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')
}

顺便说一句,你有没有考虑使用改造或的离子中作为替代REST客户端?这两个优良库也有类似的回调机制,双方都在积极更新(用于HttpZoid上一次更新是在2013年7月22日)。此外,他们都在Maven的中央。

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.

这篇关于Android的工作室:库不承认Android的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆