将支持库添加到 Android Studio 项目 [英] Add support library to Android Studio project

查看:40
本文介绍了将支持库添加到 Android Studio 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了新的 Android Studio,我正在寻找一种导入 Android 支持库的方法.

I just installed the new Android Studio and I'm looking for a way to import the support library for Android.

那个选项在哪里?在 Eclipse 中,只需单击两次即可.我用谷歌搜索但一无所获.肯定是太新了.

Where is the option for that? In Eclipse that are just two clicks. I googled for it but found nothing. Surely it is too new.

推荐答案

我有一段时间不再从事 Android 项目了.虽然下面提供了一些关于如何配置 android studio 项目的线索,但我不能保证它可以完美运行.

I no longer work on Android project for a while. Although the below provides some clue to how an android studio project can be configured, but I can't guarantee it works flawlessly.

原则上,IntelliJ 尊重构建文件,并会尝试使用它来配置 IDE 项目.反之则不然,IDE 更改通常不会影响构建文件.

In principle, IntelliJ respects the build file and will try to use it to configure the IDE project. It's not true in the other way round, IDE changes normally will not affect the build file.

由于大多数 Android 项目都是由 Gradle 构建的,了解这个工具总是一个好主意.

Since most Android projects are built by Gradle, it's always a good idea to understand this tool.

我建议参考@skyfishjy 的回答,因为它似乎比这个更新.

I'd suggest referring to @skyfishjy's answer, as it seems to be more updated than this one.

以下内容未更新

android studio虽然是基于IntelliJ IDEA的,但同时也依赖gradle来构建你的apk.从 0.2.3 开始,这两个在从 GUI 配置方面表现不佳.因此,除了使用 GUI 设置依赖项外,还需要您手动编辑 build.gradle 文件.

Although android studio is based on IntelliJ IDEA, at the same time it relies on gradle to build your apk. As of 0.2.3, these two doesn't play nicely in term of configuring from GUI. As a result, in addition to use the GUI to setup dependencies, it will also require you to edit the build.gradle file manually.

假设您有一个测试项目 > 测试结构.您要查找的 build.gradle 文件位于 TestProject/Test/build.gradle

Assuming you have a Test Project > Test structure. The build.gradle file you're looking for is located at TestProject/Test/build.gradle

查找依赖项部分,并确保您有

Look for the dependencies section, and make sure you have

编译'com.android.support:support-v4:13.0.+'

compile 'com.android.support:support-v4:13.0.+'

下面是一个例子.

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

repositories {
    mavenCentral()
}

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

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

您还可以从 maven 存储库中添加 3rd 方库

You can also add 3rd party libraries from the maven repository

编译组:'com.google.code.gson',名称:'gson',版本:'2.2.4'

compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'

上面的代码片段将为您添加 gson 2.2.4.

The above snippet will add gson 2.2.4 for you.

在我的实验中,似乎添加 gradle 也会为您设置正确的 IntelliJ 依赖项.

In my experiment, it seems that adding the gradle will also setup correct IntelliJ dependencies for you.

这篇关于将支持库添加到 Android Studio 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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