美文网首页Android
Android Studio gradle dynamic de

Android Studio gradle dynamic de

作者: JaedenKil | 来源:发表于2021-03-10 15:43 被阅读0次

I maintain a public repository A, and apply the dependency in this repository in another project B.

In Project A:
Just released the latest version 1.0.7.

In project B:
module level build.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation 'com.xxx.jk:public-permission-handler:1.+'
}

Checked log in project B, the applied version is 1.0.7.

Then there is an update in project A, a new version 1.0.8 is released.

Scenarios:

  1. In project B, still apply 'com.xxx.jk:public-permission-handler:1.+',
    checked log, the applied version is 1.0.7.

  2. In project B, apply 'com.xxx.jk:public-permission-handler:1.0.8', checked log, the applied version is 1.0.8.

So the issue is, although there is a newer release 1.0.8, gradle won't dynamically fetch the latest version.

Solution:

Solution 1: Force re-fetch the dependencies within code:
resolutionStrategy.cacheDynamicVersionsFor 1, 'minutes'

android {
}

configurations.all {
    resolutionStrategy.cacheDynamicVersionsFor 1, 'minutes'
}

dependencies {
}

Solution 2: Force re-fetch the dependencies within gradle command line:

./gradlew cDAT --refresh-dependencies

Refer to gradle dependency dynamic version:

Controlling dependency caching programmatically

You can fine-tune certain aspects of caching programmatically using the ResolutionStrategy for a configuration. The programmatic approach is useful if you would like to change the settings permanently.

By default, Gradle caches dynamic versions for 24 hours. To change how long Gradle will cache the resolved version for a dynamic version, use:

相关文章

网友评论

    本文标题:Android Studio gradle dynamic de

    本文链接:https://www.haomeiwen.com/subject/sfmwqltx.html