SafeArgs NavController Android gradle 插件更新到 2.2.0 错误

SafeArgs NavController Android gradle plugin update to 2.2.0 error

我最近正在更新我的应用程序依赖项,并且在尝试将 safeargs 导航组件 gradle 插件更新到 2.2.1 时(实际上也发生在 2.2.0 中),如下所示:

dependencies { 
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.1"
    ...
}

我在尝试编译项目时遇到以下错误:

Unable to find method 'com.squareup.kotlinpoet.ClassName.<init>(Ljava/lang/String;[Ljava/lang/String;)V'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

我尝试了所有这些解决方案,none 奏效了。


Gradle 文件

build.gradle(project)


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.71'
    ext.navControllerVersion = '2.1.0'
    ext.apolloVersion = '1.4.3'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.apollographql.apollo:apollo-gradle-plugin:$apolloVersion"
        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

//Plugin added to check if the project has the last dependencies. You can run a gradle task via terminal with:
// ./gradlew dependencyUpdates
plugins {
    id 'com.github.ben-manes.versions' version '0.28.0'
}
//This configuration is added for the ben-manes' plugin to ignore alpha, beta, rc, and so on updates
dependencyUpdates.resolutionStrategy {
    componentSelection { rules ->
        rules.all { ComponentSelection selection ->
            boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview'].any { qualifier ->
                selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
            }
            if (rejected) {
                selection.reject('Release candidate')
            }
        }
    }
}

apply from: 'dependencies.gradle'
apply plugin: 'com.github.ben-manes.versions'

def versionMajor = 0
def versionMinor = 0
def versionPatch = 0
def versionBuild = 7 // bump for dogfood builds, public betas, etc.

allprojects {
    repositories {
        google()
        jcenter()
    }

    ext {
        androidApplicationId = 'es.client.mobile.android.appname'
        androidVersionCode = versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
        androidVersionName = "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
build.gradle(:app)


apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

buildscript {
    repositories {
        google()
        jcenter()
        maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
    }
    dependencies {
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navControllerVersion"
    }
}

android {
    def globalConfiguration = rootProject.extensions.getByName("ext")

    compileSdkVersion globalConfiguration["androidCompileSdkVersion"]
    testOptions.unitTests.includeAndroidResources = true

    defaultConfig {
        minSdkVersion globalConfiguration["androidMinSdkVersion"]
        targetSdkVersion globalConfiguration["androidTargetSdkVersion"]

        applicationId globalConfiguration["androidApplicationId"]
        versionCode globalConfiguration["androidVersionCode"]
        versionName globalConfiguration["androidVersionName"]

        testInstrumentationRunner "es.client.mobile.android.appname.app.test.TestRunner"

        buildConfigField "String", "MC_APP_ID", MC_APP_ID
        buildConfigField "String", "MC_ACCESS_TOKEN", MC_ACCESS_TOKEN
        buildConfigField "String", "MC_SENDER_ID", MC_SENDER_ID
        buildConfigField "String", "MC_MID", MC_MID
        buildConfigField "String", "MC_SERVER_URL", MC_SERVER_URL
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }

    lintOptions {
        quiet true
        abortOnError false
        ignoreWarnings true
        disable 'GoogleAppIndexingWarning'  //For removing warning about deep linking in Manifest, because this app do not use deep links
    }

    signingConfigs {
        release {
            keyAlias '###'
            keyPassword '####'
            storeFile file('../extras/release/bundle/###.jks')
            storePassword '###'
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        release {
            signingConfig signingConfigs.release

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions 'version'
    productFlavors {
        dev {
            applicationIdSuffix ".dev"
            versionNameSuffix "-dev"
            dimension = 'version'
        }
        integDev {
            applicationIdSuffix ".ind"
            versionNameSuffix "-ind"
            dimension = 'version'
        }
        integPre {
            applicationIdSuffix ".inp"
            versionNameSuffix "-inp"
            dimension = 'version'
        }
        pro {
            applicationIdSuffix ".pro"
            versionNameSuffix "-pro"
            dimension = 'version'
        }
    }

    dataBinding {
        enabled = true
    }
}

androidExtensions {
    experimental = true
}

dependencies {
    def appDependencies = rootProject.ext.appDependencies
    def appTestDependencies = rootProject.ext.appTestDependencies
    def developmentDependencies = rootProject.ext.developmentDependencies

    implementation project(':model')
    implementation project(':domain')
    implementation project(':data')
    implementation project(':datasources')

    implementation appDependencies.kotlin
    implementation appDependencies.koin
    implementation appDependencies.koinCompile
    implementation appDependencies.koinArch
    implementation appDependencies.ktxCore
    implementation appDependencies.androidAnnotation
    implementation appDependencies.appcompat
    implementation appDependencies.recyclerView
    implementation appDependencies.constraintLayout
    implementation appDependencies.materialDesign
    implementation appDependencies.lifecycleExtensions
    implementation appDependencies.lifecycleCommonJava8
    implementation appDependencies.navigationFragment
    implementation appDependencies.navigationUi
    implementation appDependencies.roomRuntime
    implementation appDependencies.rxJava
    implementation appDependencies.rxAndroid
    implementation appDependencies.rxKotlin
    implementation appDependencies.glide
    implementation appDependencies.timber
    implementation appDependencies.googleMaps
    implementation appDependencies.googleMapsUtils
    implementation appDependencies.googleLocation
    implementation appDependencies.viewpager2
    implementation appDependencies.playServicesAuth
    implementation appDependencies.facebookSdk
    implementation appDependencies.firebaseAnalytics
    implementation appDependencies.firebaseCore
    implementation appDependencies.firebaseMessaging
    implementation appDependencies.marketingCloud
    implementation appDependencies.googleServices
    implementation appDependencies.zXing
    implementation appDependencies.zXingEmbedded

    // Unit test dependencies
    implementation 'androidx.appcompat:appcompat:1.1.0'
    testImplementation appTestDependencies.kotlinJUnit
    testImplementation appTestDependencies.mockitoKotlin
    testImplementation appTestDependencies.mockitoInline

    // Instrumentation test dependencies
    androidTestImplementation appTestDependencies.junit
    androidTestImplementation appTestDependencies.lifecycleTest
    androidTestImplementation(appTestDependencies.koinTest, {
        exclude group: 'org.jetbrains.kotlin'
        exclude group: 'org.mockito'
    })
    androidTestImplementation(appTestDependencies.mockitoKotlin, {
        exclude group: 'org.jetbrains.kotlin'
        exclude group: 'org.mockito'
    })
    androidTestImplementation appTestDependencies.mockitoAndroid
    androidTestImplementation appTestDependencies.androidJUnit
    androidTestImplementation(appTestDependencies.espressoCore) {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation(appTestDependencies.androidRunner) {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation(appTestDependencies.androidRules) {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation(appTestDependencies.espressoIntents) {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation(appTestDependencies.espressoContrib) {
        exclude module: 'appcompat'
        exclude module: 'appcompat-v7'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'support-annotations'
        exclude module: 'recyclerview-v7'
        exclude module: 'design'
    }

    //Development
    debugImplementation developmentDependencies.leakCanary
    debugImplementation developmentDependencies.flipper
    debugImplementation developmentDependencies.soloader
    debugImplementation developmentDependencies.flipperLeakcanary
}

apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin

编辑: 更多调试让我得出结论,这是由 kotlinpoet 库的依赖冲突引起的,因为如果我更改 safe-args 插件以使用 java 版本:

apply plugin: "androidx.navigation.safeargs"

它按预期工作。我的问题是,当我调用 ./gradlew app:dependencies 时,我没有对 kotlinpoet 有任何依赖,所以我不知道如何调试冲突。

谢谢并致以最诚挚的问候, 伊格纳西奥

您的 gradle 模块应用程序中有以下代码,而不是 gradle 项目中的代码。

试试这个:

gradle 项目:

repositories {
        google()
        jcenter()
        maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.apollographql.apollo:apollo-gradle-plugin:$apolloVersion"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navControllerVersion"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

并删除这个:

gradle模块:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
    }
    dependencies {
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navControllerVersion"
    }
}

在某些情况下,问题可能与旧版本的 kotlinpoet 与 SafeArgs 库中包含的 kotlinpoet 版本冲突有关。

将 kotlinpoet 更新到 1.4.4 可以解决问题。