在 Android Studio 中使用 Gradle 的优势之一是它有助于依赖项管理。因此,如果我在我的 build.gradle
文件中使用了特定版本的库,
那么一旦更高版本可用,我将如何强制它更新依赖版本?
我的build.gradle中的一些依赖被指定为
dependencies {
compile project(':facebookSDK')
compile files('libs/picasso-2.1.1.jar')
compile files('libs/crouton-1.8.1.jar')
}
最佳答案
One of the advantages of using Gradle in Android Studio is that it helps in dependency management.
不是您使用它的方式。
So if i have used a particular version of a library in my build.gradle file, then how will i force it to update the dependency version once the higher version is available?
在您的情况下,您将下载新的 JAR,将它们放在 libs/
中,然后更新您的 build.gradle
以匹配。
您的首选方法是删除这些 JAR 并将您的两个 compile files
语句替换为从 Maven Central 或其他 Artifact 存储库中提取依赖项的语句。您可以通过 Gradle, please 找到流行的开源库的正确声明。网站。
在您的情况下,您将使用:
compile 'com.squareup.picasso:picasso:2.3.3'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.5'
这些将要求您还拥有一个 repositories
闭包作为您的 dependencies
闭包的对等体:
repositories {
mavenCentral()
}
这可能已经存在。
这些 compile
语句仍然将您固定到这些库的特定版本,但是移动到新版本只是更新 compile
语句和 Gradle 的简单问题将降低对您下一个构建的新依赖。
如果需要,您可以用通配符替换部分版本号(例如,2.3.+
)。在这种情况下,这将导致 Gradle 自动更新到库的新补丁级别。一些开发人员不赞成这种方法,因为虽然它很方便,但它确实降低了您重现构建的能力(例如,您需要重新编译代码的一些旧分支,而现在您不知道是什么版本你当时使用的神器)。
关于android - Gradle 依赖更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24954382/