Android Studio 缺少外部依赖项 [英] Android Studio missing external dependencies

查看:67
本文介绍了Android Studio 缺少外部依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图书馆项目.我想使用 Android 的新构建系统.目前我遇到了一个非常烦人的场景.

I have a library project. I want to use Android's new build system. Currently I'm encountering a quite annoying scenario.

我在 gradle.build 上定义了我的依赖项,但它们从未出现在 Android Studio 的外部库下.因此,所有对这些库的引用都被标记为错误.

I have my dependencies defined on gradle.build but they never appear under External Libraries in Android Studio. Hence all the references to those libraries are marked as errors.

当我在命令行上运行 gradle dependencies 时,它会显示完整的依赖关系树并成功编译.问题显然出在 Android Studio 上.

When I run gradle dependencies on the command line it shows the full dependencies tree and compiles successfully. The problem clearly is with Android Studio.

我尝试重新启动 IDE/OS,但没有任何效果.

I tried to restart the IDE/OS but nothing.

这是我的 gradle.build

This is my gradle.build

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

apply plugin: 'android-library'

apply plugin: 'idea'

repositories {
    mavenCentral()
}

dependencies {
    compile 'junit:junit:4.11'
    compile 'org.robolectric:robolectric:2.1:jar-with-dependencies'

    compile 'com.google.android:android:4.1.1.4'
    compile 'com.google.android:support-v4:r7'

    compile 'info.cukes:cucumber-java:1.1.3'
    compile 'info.cukes:cucumber-junit:1.1.3'
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        versionCode 1
        versionName "0.3-SNAPSHOT"
        minSdkVersion 15
        targetSdkVersion 17
    }
}

更新

此问题似乎已在最新的 Android Studio 版本 (0.2.5) 上得到解决

This issue seems to be fixed on latest Android Studio version (0.2.5)

推荐答案

遗憾的是,在当前版本的 Android Studio 中,IDE 并未与构建系统(gradle)完全集成.您必须在 gradle.build 中添加一次库以进行编译,并通过 GUI 添加一次以完成代码.

Unfortunately, in the current version of Android Studio, the IDE is not completely integrated with the build system (gradle). You have to add the library once in gradle.build for compilation, and once via the GUI for code completion.

右键单击您的项目,选择打开模块设置".确认警告.选择库"、+",然后添加您正在使用的库.您可以在出现的对话框中搜索 Maven 上的库.您应该为 jar 选择 libs 目录.最后,将该库添加到您的代码模块中.如果您的应用程序是 MyApp,则您可能拥有 MyApp 和 MyAppProject.您需要将其添加到 MyApp.(您也可以直接从模块"页面添加它.)

Right click on your project, select "Open Module Settings". Acknowledge the warning. Select "Libraries", "+", and add the library you are using. You can search for libraries on Maven in the dialog that appears. You should select your libs dir for the jar. Finally, add the library to your code's module. If your app is MyApp, you probably have MyApp and MyAppProject. You need to add it to MyApp. (You can probably also directly add it from the "Modules" page.)

要另外让 gradle 将 jar 添加到您的 apk,请对您的成绩文件进行以下更改.替换:

To additionally get gradle to add the jar to your apk, make the following changes to your grade file. Replace:

compile 'org.jsoup:jsoup:1.6.1'

和类似

compile files('libs/jsoup-1.6.1.jar')

现在应该可以了.

这篇关于Android Studio 缺少外部依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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