问题描述
我刚刚开始在 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 文档"
我忽略了这一点,在我尝试构建项目后,我在外部库中没有找到木材或改造.显然我错过了一些东西.我相信在声明依赖项并单击构建后,特定的库将被自动导入,但是是的,我错了.
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 在您从 IDE 编辑 build.gradle 文件时更智能地突出显示语法.该提示的作用是从以下位置更改 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 中声明依赖项后如何导入依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!