错误:任务“:app:transformClassesWithFirebasePerformancePluginForRelease”的执行失败

当我在发布模式下编译时,我找不到此错误的根源。我的印象是,这个错误在没有修改我的代码的情况下出现(我尝试使用github返回,但我仍然有这个错误)。

错误:任务“:app:transformClassesWithFirebasePerformancePluginForRelease”的执行失败。

java.io.IOException: 找不到指定的路径

带有调试标志的 Gradle

22:36:11.767 [错误] [FirebasePerformancePlugin] 无法检测 org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.class

My build.gradle

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

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven {
            url 'https://maven.google.com'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
        classpath 'com.google.firebase:firebase-plugins:1.1.0'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://www.idescout.com/maven/repo/'
        }
        maven {
            url 'https://maven.google.com'
        }
    }
}

My app/build.gradle

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

android {

    compileSdkVersion 26
    buildToolsVersion '26.0.0'
    defaultConfig {
        applicationId ""
        minSdkVersion 16
        targetSdkVersion 26
        multiDexEnabled true

        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
            signingConfig signingConfigs.Keys
        }
        debug {
            signingConfig signingConfigs.Keys
        }
    }
    dexOptions {
        jumboMode = true
    }

    packagingOptions {
        pickFirst 'META-INF/*'
    }
}

repositories {
    jcenter()
}
repositories {
    maven { url "http://repo1.maven.org/maven2" }
    maven { url 'https://jitpack.io' }
    maven { url 'https://maven.fabric.io/public' }
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile 'com.android.support:appcompat-v7:26.0.0-beta2'
    compile 'com.android.support:support-v13:26.0.0-beta2'
    compile 'com.android.support:support-v4:26.0.0-beta2'
    compile 'com.android.support:design:26.0.0-beta2'
    compile 'com.android.support:recyclerview-v7:26.0.0-beta2'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:cardview-v7:26.0.0-beta2'
    compile 'com.android.support:customtabs:26.0.0-beta2'

    //firebase
    compile 'com.google.firebase:firebase-ads:11.0.2'
    compile 'com.google.firebase:firebase-core:11.0.2'
    compile 'com.google.firebase:firebase-messaging:11.0.2'
    compile 'com.google.firebase:firebase-auth:11.0.2'
    compile 'com.google.firebase:firebase-database:11.0.2'
    compile 'com.google.firebase:firebase-config:11.0.2'
    compile 'com.google.firebase:firebase-storage:11.0.2'
    compile 'com.google.firebase:firebase-perf:11.0.2'
    compile 'com.firebaseui:firebase-ui-auth:1.2.0'

    //Fabric
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }


    compile 'com.android.support:support-vector-drawable:26.0.0-beta2'
    compile 'commons-io:commons-io:2.5'

    compile 'com.android.support:multidex:1.0.1'
    compile files('libs/aa-poi-ooxml-schemas-3.10-reduced-more-0.1.5.jar')
    compile files('libs/aa-poi-3.10-min-0.1.5.jar')
}

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

答案 1

将我的Android项目迁移到Gradle Kotlin DSL后,我突然也收到了Firebase Performance Plugin对项目的任何类(包括第三方依赖项)的错误。生成最终以 .错误是Can't instrumentOutOfMemoryError

Can't instrument: ...
java.lang.IllegalArgumentException
        at org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79)
        at com.google.firebase.perf.plugin.instrumentation.InstrumentationVisitor.<init>(InstrumentationVisitor.java:55)
        ...

查看ASM的ClassVisitor的源代码,我看到当传递未处理的api版本时,它会在构造函数中抛出。perf 插件需要 7.0 版 ASM。但是,在检查项目依赖项时,我发现使用了ASM的6.0版本。显然,其他一些依赖项需要6.0。IllegalArgumentException./gradlew :app:dependencies

我试图用显式覆盖ASM依赖项

configurations.all {
    resolutionStrategy.eachDependency {
        if (requested.group == "org.ow2.asm") {
            useVersion("7.0")
            because("Version required by Firebase Performance Plugin")
        }
    }
}

在我现在看到的输出中,使用了7.0,但我仍然收到此错误:(./gradlew :app:dependencies

更新:从 降级到为我解决了问题。com.google.firebase:firebase-plugins1.2.01.1.5

更新 2:从版本 2.0.0 开始,其用法已弃用。现在,建议的解决方案是显式使用性能监视插件。迁移到新插件后,问题现在为我解决了。firebase-plugins

更新 3:我必须撤回我以前的发言。使用性能监视器插件确实在我的本地计算机上修复了构建,但在我的Jenkins构建服务器上没有。此外,将上面提到的块移动到Antimonit注释的块中并没有修复构建,尽管我可以看到ASM 7.0的输出用于构建。configurations.allbuildscript./gradlew buildEnvironment


答案 2

原因:当在应用级文件而不是项目级文件中定义了类路径依赖关系时,(在运行时)获取 ASM v6 dep,即使在其 POM 文件中声明了 ASM v7 dep。这会触发 中的 IllegalArgumentException,因为它们依赖于 ASM v7,但它工作正常,因为它依赖于 ASM v6perf-pluginbuild.gradlebuild.gradleperf-pluginperf-pluginv1.2.0v1.2.1v1.1.5

这里有很多帖子解释了为什么顶级构建脚本的类路径与项目的其余部分不同:


溶液:这是渐变行为。对此的快速解决方案是仅在根项目中定义依赖项(在公共文档中已经提到过)。perf-pluginbuild.gradle


详细说明:

没有错误

root-project build.gradle

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

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.firebase:perf-plugin:1.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

app-level build.gradle

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


. . .

dependencies {
    implementation 'com.google.firebase:firebase-perf:17.0.2'
}

错误

root-project build.gradle

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

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

app-level build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.google.firebase:perf-plugin:1.2.1'
    }
}

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


. . .

dependencies {
    implementation 'com.google.firebase:firebase-perf:17.0.2'
}

两种情况下的命令比较表明,在没有 Bug 的情况下,所有 对 的引用都转换为但在 Bug 情况下没有发生这种情况:$ ./gradlew clean :buildEnvironmentorg.ow2.asm:asm:6.0org.ow2.asm:asm:7.0

没有错误

> Task :buildEnvironment

------------------------------------------------------------
Root project
------------------------------------------------------------

.  .  .

    +--- com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta04
|    |    +--- org.ow2.asm:asm:6.0 -> 7.0
|    |    +--- org.ow2.asm:asm-util:6.0 (*)
|    |    +--- org.ow2.asm:asm-commons:6.0 (*)
|    |    +--- org.jdom:jdom2:2.0.6
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.31 (*)
|    |    \--- com.android.tools.build.jetifier:jetifier-core:1.0.0-beta04 (*)
|    +--- com.google.protobuf:protobuf-java:3.4.0
|    \--- com.google.protobuf:protobuf-java-util:3.4.0 (*)
\--- com.google.firebase:perf-plugin:1.2.1
     \--- org.ow2.asm:asm:7.0

错误

> Task :buildEnvironment

------------------------------------------------------------
Root project
------------------------------------------------------------

.  .  .

     +--- com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta04
     |    +--- org.ow2.asm:asm:6.0
     |    +--- org.ow2.asm:asm-util:6.0 (*)
     |    +--- org.ow2.asm:asm-commons:6.0 (*)
     |    +--- org.jdom:jdom2:2.0.6
     |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.31 (*)
     |    \--- com.android.tools.build.jetifier:jetifier-core:1.0.0-beta04 (*)
     +--- com.google.protobuf:protobuf-java:3.4.0
     \--- com.google.protobuf:protobuf-java-util:3.4.0 (*)

推荐