在build.gradle中声明依赖后,如何导入依赖? [英] How do I import dependencies after declaring them in build.gradle?

查看:1350
本文介绍了在build.gradle中声明依赖后,如何导入依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在android studio上工作,并开始探索Gradle的世界.因此,我在Android Studio中创建了一个项目,打开了build.gradle并添加了如下所示的依赖项:

I am just starting to work on android studio and beginning to explore the world of Gradle. So I created a project in Android Studio, opened up build.gradle and added dependencies like the below:

dependencies {
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile 'com.squareup.retrofit:retrofit:1.3.0'
    compile 'com.jakewharton.timber:timber:2.1.0'
}

此后,我注意到build.gradle上弹出一个提示:

After this I notice a tip popping up on build.gradle which says:

您可以将Gradle包装器配置为与源一起使用分发. 它将为IDE提供Gradle API/DSL文档"

You can configure Gradle wrapper to use distribution with sources. It will provide IDE with Gradle API/DSL documentation"

我忽略了这一点,在尝试构建项目后,我没有在外部库中找到木材或翻新产品.显然我缺少了一些东西.我相信在声明依赖项并单击构建后,将自动导入特定的库,但是是的,我错了.

I ignore this and I don't find either timber or retrofit in the external libraries after I try building the project. Obviously I was missing something. I believed that after declaring the dependencies and clicking build, the particular libraries will be auto imported but yes, I was wrong.

因此,我同意并应用在build.gradle上弹出的提示,然后刷新该项目,并在外部库"中发布所有依赖项.

So I agree and apply the tip which popped up on build.gradle and then the project got refreshed, post which all the dependencies were available in the "External Libraries".

所以问题是:

  • build.gradle中声明后如何确保所有依赖项都到位?
  • How do I ensure to have all the dependencies in place after declaring it in build.gradle?

我已阅读到可以通过单击导入模块来完成GUI方式的操作,但是我想了解是否还有其他方式

I have read that I can do this the GUI way by clicking on import modules but I want to find out if there are other ways

推荐答案

如果您未使用Android Studio 0.4.3,请升级至该版本-该版本中存在一些错误修复程序,这些错误修复程序会完全阻止新添加的依赖项在IDE中对您的项目可见(尽管实际上可以建立).如果您尚未运行0.4.3,则可能会解决您的问题.

If you're not using Android Studio 0.4.3, please upgrade to it -- there are bugfixes in that version that prevent newly-added dependencies from being completely visible to your project in the IDE (though it would actually build okay). If you're not already running 0.4.3, that will probably fix your problem.

关于将Gradle包装器配置为使用源的消息,该信息适用于让包装器下载Gradle本身的版本,其中包括Gradle的源代码.这样,当您从IDE中编辑 build.gradle 文件时,IDE可以更聪明地突出显示语法.该提示的作用是从以下位置更改gradle/wrapper/gradle-wrapper.properties文件中的此URL:

As for the message about configuring the Gradle wrapper to use sources, that applies to having the wrapper download a version of Gradle itself that includes the source code to Gradle. Doing this allows the IDE to be smarter about syntax highlighting when you're editing build.gradle files from the IDE. What that tip does is it changes this URL in your gradle/wrapper/gradle-wrapper.properties file from this:

distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip

对此:

distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip

这篇关于在build.gradle中声明依赖后,如何导入依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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