Gradle同步项目以使用更新的库。

huangapple go评论128阅读模式
英文:

Gradle sync project for newer libraries

问题

我对Gradle和Android开发都不太熟悉。
如何让Gradle同步我的项目以使用更新的库?

我想要使用setFragmentResultListener,该函数在1.3.0-alpha04版本中可用,但目前使用的是1.2.0版本。

以下是我的build.gradle文件:

apply plugin: 'com.android.application'

plugins {
    id 'java-library'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.hasgrok.communicator2"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dependenciesInfo {
        includeInApk true
        includeInBundle true
    }
}

dependencies {
    def core_version = "1.3.1"
    implementation "androidx.core:core:${core_version}"
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

是的,我知道如何使用Gradle文件同步我的项目。我不知道如何获取我要找的库版本。

英文:

I am new to Gradle and Android development.
How do I get Gradle to sync my project to use newer libraries?

Gradle同步项目以使用更新的库。

I want to use setFragmentResultListener, which is available as of 1.3.0-alpha04, and its using 1.2.0.

My build.gradle file

apply plugin: 'com.android.application'

plugins {
    id 'java-library'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.hasgrok.communicator2"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dependenciesInfo {
        includeInApk true
        includeInBundle true
    }
}

dependencies {
    def core_version = "1.3.1"
    implementation "androidx.core:core:${core_version}"
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Yes, I know how to sync my project with Gradle files. I don't know how to get the library versions I'm looking for.

答案1

得分: 1

有时候你会收到一个 lint 警告(高亮显示),告诉你有一个更新版本可用,你可以使用它建议的快速修复来进行更新。你还可以使用Project Structure窗口(在File菜单下),Suggestions部分会显示已知的更新。

在这种情况下,它可能没有建议更新给你,因为你当前使用的是稳定版本(1.2.0),并且没有更新可用于该版本。1.3.0-alpha04 是一个不稳定的 alpha 版本,被视为另一个单独的分支。如果你手动更改并开始使用 alpha 版本,它将建议你使用 alpha 更新。

(如果你愿意,你可以这样做,只需将依赖文本更改为 alpha 版本的名称 - 但你可能还需要更改其他依赖项,并且预计会出现问题,因为这就是 alpha 版本的用途!)


哦,我刚刚看到你是 Android 开发的新手。我强烈建议不要使用任何非稳定的库,可以避免很多麻烦。会有其他方法来实现你想要使用新方法的目的!

英文:

You'll sometimes get a lint warning (highlighted) telling you there's a newer version available, and you can use the quick-fix it suggests to update. You can also use the Project Structure window (under the File menu) and the Suggestions section will show you updates it knows about.

In this case, it's probably not suggesting the update to you, because you're currently on a stable release (1.2.0), and there's no update to that. 1.3.0-alpha04 is an unstable alpha release, which is treated as another, separate track. If you manually change it and start using an alpha version, it will suggest alpha updates to you instead

(you can do that if you want, just change the dependency text to exactly the name of the alpha release - but you might need to change other dependencies too, and expect things to break because that's what alphas are for!)


oh I just saw you're new to Android development. I would absolutely recommend not using any non-stable libraries, save yourself the headaches. There'll be another way to do whatever you want to use that new method for!

答案2

得分: 0

前往 文件 > 与Gradle文件同步项目

英文:

Goto File > Sync Project with Gradle Files

Gradle同步项目以使用更新的库。

huangapple
  • 本文由 发表于 2020年8月25日 06:44:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63569628.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定