ANDROID ERROR:java.lang.NoSuchMethodError:com.google.common.base.Preconditions.checkState

时间:2017-03-17 21:23:57

标签: java android javac

请帮忙! 我已经试图解决这个问题2天,并尝试了几乎所有我能找到的东西,但没有运气。 该应用程序构建正常,但是当我生成项目时,我收到此错误。 在Windows 10 64位上运行Android Studio 2.3,jdk 1.8 已经尝试过使用Jack和番石榴版20.0 这是我的gradle.build:

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

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        // Realm
        classpath "io.realm:realm-gradle-plugin:3.0.0"
        //GCM
        classpath 'com.google.gms:google-services:3.0.0'
        // Retrolambda , https://github.com/evant/gradle-retrolambda/
        classpath 'me.tatarka:gradle-retrolambda:3.5.0'
        // https://github.com/JakeWharton/butterknife
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
应用程序目录中的

和gradle.build:

import groovy.json.JsonOutput
import groovy.json.JsonSlurper

def generateFireBaseJsonConfiguration(file) {
    def properties   = loadPropertiesFile(file)
    def templateFile = new File("google-services.json.template")
    def json         = new JsonSlurper().parseText(templateFile.text)

    // populate properties
    json.project_info.project_number                            = properties['FirebaseProjectInfoNumber']
    json.project_info.firebase_url                              = properties['FirebaseProjectInfoUrl']
    json.project_info.project_id                                = properties['FirebaseProjectInfoId']
    json.project_info.storage_bucket                            = properties['FirebaseProjectInfoBucket']
    json.client[0].client_info.mobilesdk_app_id                 =  properties['FirebaseClientInfoMobileSDKAppId']
    json.client[0].client_info.android_client_info.package_name = "org.openstack.android.summit"
    json.client[0].api_key[0].current_key                       = properties['FirebaseClientApiKeyCurrent']
    json.client[0].oauth_client[0].client_id                    = properties['FirebaseClientOAUTH2ClientClientId1']
    json.client[0].oauth_client[0].client_type                  = 3
    json.client[0].oauth_client[1].client_id                    = properties['FirebaseClientOAUTH2ClientClientId2']
    json.client[0].oauth_client[1].client_type                  = 3

    def jsonFile = new File("app/google-services.json")
    jsonFile.write(JsonOutput.toJson(json))
}

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven {
        url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
    }
    flatDir {
        dirs 'libs'
    }
}

def loadPropertiesFile(properties_file){
    Properties props = new Properties()
    println 'loading properties file : '+ properties_file;
    props.load(new FileInputStream(file(properties_file)));
    return props;
}

def getPropertyFromFile(properties_file, key){
    Properties props = loadPropertiesFile(properties_file);
    return props[key]
}

def expandManifest(flavor, properties_file) {

    println 'expanding manifest for: ' + flavor
    Properties props = loadPropertiesFile(properties_file);

    return [
            googleMapApiKey: props['googleMapApiKey'],
            fabricApiKey: props['fabricApiKey'],
            parseApplicationId: props['parseApplicationId'],
            parseClientKey: props['parseClientKey'],
            ServiceClientId: props['ServiceClientId'],
            ServiceClientSecret: props['ServiceClientSecret'],
            NativeClientId: props['NativeClientId'],
            NativeClientSecret: props['NativeClientSecret'],
            NativeClientReturnUrl: props['NativeClientReturnUrl'],
            ResourceServerBaseUrl: props['ResourceServerBaseUrl'],
            IdentityProviderBaseUrl: props['IdentityProviderBaseUrl'],
            WebSiteBaseUrl: props['WebSiteBaseUrl'],
            YouTubeAndroidPlayerAPIKey: props['YouTubeAndroidPlayerAPIKey'],
            BasicAuthUser: props['BasicAuthUser'],
            BasicAuthPass: props['BasicAuthPass'],
    ]
}

android {
    signingConfigs {
        config {
        }
    }
    dexOptions {
        javaMaxHeapSize "4g" //specify the heap size for the dex process
        preDexLibraries = false
    }
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    defaultConfig {
        applicationId "org.openstack.android.summit"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 72
        versionName "2.0"
        multiDexEnabled true
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        debug {
            // Settings for Crashlytics Beta Distribution
            ext.betaDistributionReleaseNotes = "Release Notes for this build."
            ext.betaDistributionEmails = getPropertyFromFile("../summit-app.debug.properties", "BetaDistributionEmails")
            ext.enableCrashlytics = false
        }
        release {
            minifyEnabled true
            //debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
        development {
            generateFireBaseJsonConfiguration("../summit-app.debug.properties")
            ext.betaDistributionEmails = getPropertyFromFile("../summit-app.debug.properties", "BetaDistributionEmails")
            manifestPlaceholders = expandManifest("beta", "../summit-app.debug.properties")
        }
        production {
            generateFireBaseJsonConfiguration("../summit-app.properties")
            manifestPlaceholders = expandManifest("production", "../summit-app.properties")
        }
        beta {
            generateFireBaseJsonConfiguration("../summit-app.debug.properties")
            manifestPlaceholders = expandManifest("beta", "../summit-app.debug.properties")
        }
    }
    packagingOptions {
        pickFirst 'META-INF/license.txt'
        pickFirst 'META-INF/LICENSE.txt'
        pickFirst 'META-INF/NOTICE.txt'
        // to avoid error file included twice
        exclude 'META-INF/rxjava.properties'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    variantFilter { variant ->
        def names = variant.flavors*.name

        if (names.contains("development") && variant.buildType.name == "release") {
            variant.ignore = true
        }
        if (names.contains("production") && variant.buildType.name == "debug") {
            variant.ignore = true
        }
        if (names.contains("beta") && variant.buildType.name == "debug") {
            variant.ignore = true
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'jp.wasabeef:recyclerview-animators:2.2.5'
    compile 'com.android.support:design:25.2.0'
    compile 'joda-time:joda-time:2.9.4'
    compile 'com.google.code.gson:gson:2.7'

    // Dagger 2 and Compiler
    // https://github.com/google/dagger
    compile 'com.google.dagger:dagger:2.8'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.8'

    // Google's OAuth library for OpenID Connect
    // See https://code.google.com/p/google-oauth-java-client/wiki/Setup
    compile('com.google.oauth-client:google-oauth-client:1.22.0') {
        exclude group: 'xpp3', module: 'xpp3'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
        exclude group: 'junit', module: 'junit'
        exclude group: 'com.google.android', module: 'android'
    }
    compile 'com.google.api-client:google-api-client-android:1.21.0'
    // Google's JSON parsing, could be replaced with Jackson
    compile 'com.google.api-client:google-api-client-gson:1.21.0'
    compile 'org.modelmapper:modelmapper:0.7.5'
    compile('com.github.claudioredi:Ranger:da908aa') {
        exclude module: 'joda-time'
    }
    // progress indicator
    compile 'cc.cloudist.acplibrary:library:1.2.1'
    // pop up alerts
    compile 'com.github.claudioredi:sweet-alert-dialog:9c1be1a'
    // image library
    compile 'com.facebook.fresco:fresco:0.11.0'
    // simulate list with a linear layout
    compile 'com.github.frankiesardo:linearlistview:1.0.1@aar'
    // page indicator
    compile 'com.githang:viewpagerindicator:2.4.2@aar'
    // Tags
    compile 'com.github.kaedea:Android-Cloud-TagView-Plus:5a49f4f'
    // google maps
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    // to get rid of UNEXPECTED TOP-LEVEL EXCEPTION: due oo many method references: (max is 65536)
    // https://github.com/BoltsFramework/Bolts-Android
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.parse.bolts:bolts-applinks:1.4.0'
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    // material design spiner
    compile('com.weiwangcn.betterspinner:library-material:1.1.0') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    compile('com.crashlytics.sdk.android:crashlytics:2.6.1@aar') {
        transitive = true;
    }
    testCompile 'org.mockito:mockito-core:2.0.86-beta'
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:3.1'
    testCompile 'org.powermock:powermock-module-junit4:1.6.5'
    testCompile 'org.powermock:powermock-module-junit4-rule:1.6.5'
    testCompile 'org.powermock:powermock-api-mockito:1.6.5'
    testCompile 'org.powermock:powermock-classloading-xstream:1.6.5'

    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support:support-annotations:23.4.0'

    if (file('libs/safe_storage.aar').exists()) {
        println('adding dependency safe_storage.aar ...')
        productionCompile "org.openstack.android.summit.safestorage:safe_storage@aar"
    }
    if (file('libs/safe_storage-testing.aar').exists()) {
        println('adding dependency safe_storage-testing.aar ...')
        betaCompile "org.openstack.android.summit.safestorage:safe_storage-testing@aar"
    }
    if (file('libs/safe_storage_debug.aar').exists()) {
        println('adding dependency safe_storage_debug.aar ...')
        developmentCompile "org.openstack.android.summit.safestorage:safe_storage_debug@aar"
    }
    // http://facebook.github.io/stetho and https://github.com/uPhyca/stetho-realm
    compile 'com.facebook.stetho:stetho:1.4.2'
    compile 'com.uphyca:stetho_realm:2.0.0'
    // retrofit (REST API)
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.okhttp3:okhttp:3.5.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.5.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    // Espresso Dependencies
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2', {
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'recyclerview-v7'
        exclude module: 'design'
    })

    configurations.all {
        resolutionStrategy {
            force 'com.android.support:support-annotations:23.0.1'
        }
    }

    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'

    // RXJAVA
    // HACK to get rid of an error related to realm https://github.com/realm/realm-java/issues/1963
    // this is needed bc REALM dependency
    compile('io.reactivex:rxjava:1.1.7') {
        exclude module: 'rx.internal.operators'
    }
    // RXJAVA 2.x
    compile 'io.reactivex.rxjava2:rxjava:2.0.5'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}

apply plugin: 'realm-android'

apply plugin: 'com.google.gms.google-services'

apply plugin: 'com.jakewharton.butterknife'

最后这是控制台日志:

...
:app:incrementalDevelopmentDebugJavaCompilationSafeguard
:app:javaPreCompileDevelopmentDebug
:app:compileDevelopmentDebugJavaWithJavac
...
C:\android_projects\summit-app-android\app\src\main\java\org\openstack\android\summit\OpenStackSummitApplication.java:17: error: cannot find symbol
import org.openstack.android.summit.dagger.components.DaggerApplicationComponent;
                                                     ^
  symbol:   class DaggerApplicationComponent
  location: package org.openstack.android.summit.dagger.components
warning: unknown enum constant Scope.LIBRARY_GROUP
...

* What went wrong:
Execution failed for task ':app:compileDevelopmentDebugJavaWithJavac'.
> java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V

1 个答案:

答案 0 :(得分:0)

感谢Rahul,我想出了如何解决这个问题。正如他提到的那样,问题是我包含了不同版本的番石榴。所以首先我在Android Studio终端中运行它:

gradlew -q dependencies app:dependencies --configuration compile

其中“app”是您的项目。这向我展示了所有依赖项的列表,并看到了包含的不同版本的番石榴。 然后我从包含的项目中排除了每个重复版本的番石榴,如下所示:

testCompile ('org.robolectric:robolectric:3.1') {
        exclude module: 'guava'
    }

希望这有助于某人:)