3

I am facing an error caused by Firebase Api. Here is error log:

Firebase API initialization failure.   
java.lang.reflect.InvocationTargetException
Caused by: java.lang.IllegalAccessError: tried to access method android.support.v4.content.ContextCompat.<init>:(Ljava/lang/String;)V from class com.google.firebase.iid.zzg

And here is my gradle:

apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"

    dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'io.fabric.tools:gradle:1.+'
    classpath 'com.google.gms:google-services:3.0.0'

    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.google.android.gms:play-services-appindexing:9.0.0'
    compile 'com.google.android.gms:play-services-analytics:9.0.0'
}

What can it be the problem?

Emre Alparslan
  • 1,022
  • 1
  • 18
  • 30

2 Answers2

0

So it looks like the Firebase dependencies themselves depend on a specific version of the com.android.support libraries. I changed all of mine to 25.1.1 (found by Android Studio complaining about different versions) and that has fixed problem for me!

So for your build.gradle:

dependencies {
   ...
   compile 'com.android.support:appcompat-v7:25.1.1'
   compile 'com.android.support:design:25.1.1'
   compile 'com.android.support:support-v4:25.1.1'
   ...
}

Edit: This is what Android Studio is complains about when I added Firebase Android Studio complaining about versions

jamesthollowell
  • 1,550
  • 15
  • 21
0

After I added firebase dependency and updated gms library versions this error is fixed.

My build.gradle:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.google.android.gms:play-services:10.2.1'
    compile 'com.google.firebase:firebase-appindexing:10.2.1'
    compile 'com.google.android.gms:play-services-analytics:10.2.1'
}
apply plugin: 'com.google.gms.google-services'
Emre Alparslan
  • 1,022
  • 1
  • 18
  • 30