Firebase-perf conflicting with let plugin

点点圈 提交于 2019-12-11 06:42:57

问题


We were recently asked to implement "Firebase Performance Monitoring" on an Android app, but it's been causing us lots of different problems. The app used to work just fine, but upon adding "firebase-perf", it compiles, but then on runtime we found out the Let plugin stopped working, every permission defined with the @AskPermission annotation is simply ignored.

Looking through the gradle build output, I stumbled upon this stack-trace:

java.lang.IllegalStateException: Expecting .,<, or ;, but found firebaseperf while unpacking <K:Ljava/lang/Object;>Lcom/google/android/gms/internal/firebase-perf/zzw<TK;>;
    at org.aspectj.util.GenericSignatureParser.parseClassTypeSignature(GenericSignatureParser.java:204)
    at org.aspectj.util.GenericSignatureParser.parseAsClassSignature(GenericSignatureParser.java:56)
    at org.aspectj.weaver.UnresolvedType.forGenericTypeSignature(UnresolvedType.java:274)
    at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:482)
    at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:456)
    at org.aspectj.weaver.bcel.BcelWeaver.addAspectsFromJarFile(BcelWeaver.java:263)
    at org.aspectj.weaver.bcel.BcelWeaver.addLibraryJarFile(BcelWeaver.java:236)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.initBcelWorld(AjBuildManager.java:874)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:249)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:185)
    at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
    at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
    at org.aspectj.tools.ajc.Main.run(Main.java:371)
    at org.aspectj.tools.ajc.Main$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at com.canelmas.let.LetPlugin$_apply_closure2_closure3.doCall(LetPlugin.groovy:66)
    ...

I've seen some similar cases here and there but couldn't find a solution yet. The way I see it, it looks like a conflict between differing versions of aspectjs, defined in different classpaths.

This is the relevant part of out project-level gradle file:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath group: 'org.tmatesoft.svnkit', name: 'svnkit', version: '1.7.11'
        classpath('com.canelmas.let:let-plugin:0.1.11')
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
    }
}

And these are the firebase dependencies we have defined in the app-level gradle:

dependencies {
    compile 'com.google.firebase:firebase-core:16.0.7'
    compile 'com.google.firebase:firebase-perf:16.2.3'
}

Does anyone have an idea of a possible fix?

EDIT: There was someone in another thread, who claimed to have solved the problem with the code below, but I have no idea how to actually use it. Could anyone more Gradle-savvy be able to explain where is this declaration supposed to go and what I'm supposed to do with it?

I tried placing it many different places of my gradle file but I'm getting this error: "No such property: classpath for class: org.gradle.api.tasks.compile.JavaCompile"

def filtered_class_filetree = javaCompile.classpath.asFileTree.filter {
    !it.canonicalPath.contains("firebase-perf")
}

回答1:


If multiple libraries are compiling different versions of aspectj (or any other dependency), you can always force (or ignore) the ones you want like below:

implementation('com.google.firebase:firebase-core:16.0.7', { // this will remove aspectj dependencies from firebase
    exclude group: 'org.aspectj', module: 'aspectjrt'
    exclude group: 'com.android.support', module: 'aspectjtools'
  })

You can also force aspect's version like below (beside your dependencies, in the module):

configurations.all {
    resolutionStrategy.force 'org.aspectj:aspectjrt:x.x.x'
}

To answer your last question:

I tried placing it many different places of my gradle file but I'm getting this error: "No such property: classpath for class: org.gradle.api.tasks.compile.JavaCompile"

You can access java compiler (and classpath) using applicationVariants in android block inside your module:

  // inside your android module 
  android {
       //...
       applicationVariants.all {
       variant ->
         variant.javaCompiler.classpath = variant.javaCompiler.classpath.filter {
           !it.canonicalPath.contains("firebase-perf")
         }
     }
  }


来源:https://stackoverflow.com/questions/54888254/firebase-perf-conflicting-with-let-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!