0

我最近更新了我的 App 依赖项,并尝试将 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.

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


摇篮文件

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"

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

谢谢和最好的问候, 伊格纳西奥

4

2 回答 2

3

您在 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
    }

并删除这个:

毕业模块:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
    }
    dependencies {
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navControllerVersion"
    }
}
于 2020-04-06T11:41:07.890 回答
0

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

将 kotlinpoet 更新到 1.4.4 解决了这个问题。

于 2020-05-21T11:54:04.353 回答