【问题标题】:Cannot compile with Firebase Performance. (Unable to find method...)无法使用 Firebase 性能进行编译。 (找不到方法...)
【发布时间】:2017-07-27 14:29:44
【问题描述】:

我正在尝试将 Firebase Performance Monitoring 添加到我的 Android Studio 项目中。按照有关如何将其添加到我的应用程序的步骤后,我无法编译我的应用程序。这是错误:

错误:(1, 0) 找不到方法 'com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object ;Ljava/lang/Object;)V'.
此意外错误的可能原因包括:

  • Gradle 的依赖缓存可能已损坏(这有时会在网络连接超时后发生。) 重新下载依赖和同步项目(需要网络)
  • Gradle 构建过程(守护程序)的状态可能已损坏。停止所有 Gradle 守护程序可能会解决此问题。 停止 Gradle 构建过程(需要重新启动)
  • 您的项目可能正在使用与项目中的其他插件或项目请求的 Gradle 版本不兼容的第三方插件。

在 Gradle 进程损坏的情况下,您也可以尝试关闭 IDE,然后杀死所有 Java 进程。

项目 build.gradle:

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

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha7'
        classpath 'com.google.gms:google-services:3.1.0'
        classpath 'com.google.firebase:firebase-plugins:1.1.0'

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

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

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

// Define versions in a single place
ext {
    // Sdk and tools
    minSdkVersion = 16
    targetSdkVersion = 26
    compileSdkVersion = 26
    buildToolsVersion = '26.0.0'

    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    // Version
    versionCode = 1;
    versionName = "0.0.1";

    ...

    // Firebase
    firebaseVersion = '11.0.2'

    ...
}

App build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "REMOVED"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        vectorDrawables.useSupportLibrary = true
        dataBinding.enabled = true
    }
    compileOptions {
        sourceCompatibility = rootProject.ext.sourceCompatibility
        targetCompatibility = rootProject.ext.targetCompatibility
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    ...
    
    // Firebase
    compile "com.google.firebase:firebase-core:$rootProject.firebaseVersion"
    compile "com.google.firebase:firebase-perf:$rootProject.firebaseVersion"

    ...
}

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

【问题讨论】:

  • 尝试清理并重建项目
  • @MartinDeSimone 刚刚尝试了干净的项目,它给出了同样的错误:Error:(1, 1) A problem occurred evaluating project ':app'. > com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
  • 但我的意思是没有图书馆
  • @MartinDeSimone 这行得通,但是就像我在问题中所说的那样,当我将 Firebase 性能添加到项目时会出错。

标签: android firebase gradle firebase-performance


【解决方案1】:

您的 buildscript 依赖项中可能有 firebase。

问题是我的 buildscript 依赖项中有 firebase,所以它看起来像这样:

buildscript {
    ext.kotlin_version = '1.1.3-2'
    apply from: 'dependencies.gradle'
    repositories {
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
        classpath ('com.google.firebase:firebase-plugins:1.1.0') //the firebase line
        ....
    }
}

用这个替换 firebase 类路径行:

classpath ('com.google.firebase:firebase-plugins:1.1.0') {
    exclude group: 'com.google.guava', module: 'guava-jdk5'
}

然后你必须清理项目,杀死 gradle 守护进程并重新启动 android studio。

Unable to find method (can't compile project) after gradle update

【讨论】:

  • 完成了,在我使用移动设备之前,这并不容易
猜你喜欢
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
  • 1970-01-01
  • 2017-12-05
  • 2012-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多