Firestore crashing app with new dependencies - android

Yesterday I updated the dependencies of Firestore with 17.1.1 and Google Services with 4.1.0. Now while launching the app it crashes.
Note:
If I change Google Services to 4.0.2, the Firestore initializes properly and the app works as expected.
classpath 'com.google.gms:google-services:4.0.2'
Update:
Changing to 4.2.0 works.
Logs:
Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
... I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
Error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{\...\/\...\.ui.MessageActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process \...\. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process \...\. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##16.0.2:240)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore##17.1.1:68)
at \...\.ServiceLocator.provideFirestore(ServiceLocator.java:18)
at \...\.ServiceLocator.provideMessageRepository(ServiceLocator.java:28)
at \...\.ServiceLocator.provideMessageViewModelFactory(ServiceLocator.java:33)
at \...\.ui.MessageActivity.onCreate(MessageActivity.java:112)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
gradle Project:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
gradle app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "..."
minSdkVersion 22
targetSdkVersion 28
versionCode 8
versionName "1.0.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
// ...
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
// ...
// Firestore
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-firestore:17.1.1'
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.firebase:firebase-ads:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
// Crash Reports
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
}
apply plugin: 'com.google.gms.google-services'

There is no need to use FirebaseApp.initializeApp(context). Using only the dependencies is enough. So you shouldn't ever have to call it manually if you performed the standard integration, as it will be invoked automatically a startup via a ContentProvider that will initialize before any other Activity or Service. You can read Doug's post regarding on how to initialize Firebase on Android.
The problem in your code is that your are using for your project the alpha13 version for your gradle. To solve this, please change the following line of code:
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
to
classpath 'com.android.tools.build:gradle:3.2.0'
Will solve this issue.

This is a confirmed bug in the play-services plugin 4.1.0 according to https://issuetracker.google.com/issues/112716914. The answer is to use an earlier version, e.g. 4.0.2.
Edit: Version 4.2.0 is released where the bug is fixed.

Switching to 4.2.0 Solves the issue.

Related

android Kochava SDK integration crashes the app with google sdk

I just integrated Kochava SDK to my app recently. While I installing or running apk first time its crashed, but its working fine while running second time! However I also checked by generating signed(released) apk and then installing manually on device then its continuously crashing!
Here is my Project gradle file:
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.fabric.io/public'
}
maven {url "http://kochava.bintray.com/maven"}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "https://jcenter.bintray.com" }
jcenter()
google()
maven {
url 'https://maven.google.com/'
}
maven {
url "http://dl.bintray.com/glomadrian/maven"
}
maven { url "https://jitpack.io" }
maven {url "http://kochava.bintray.com/maven"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And Module gradle file is:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
dataBinding {
enabled = true
}
defaultConfig {
applicationId "xyz.xyz.myapplication"
minSdkVersion 19
targetSdkVersion 28
versionCode 31
versionName "4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary true
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
ignoreAssetsPattern "!*ffprobe"
ignoreAssetsPattern "!*ffmpeg"
ignoreAssetsPattern "!arm"
ignoreAssetsPattern "!x86"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
android.buildTypes.each { type ->
type.buildConfigField 'String', 'Base_URL', WEBServiceBaseURL
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//Android necessary...
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Support libs...
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'commons-io:commons-io:2.6'
//Facebook ads
implementation 'com.google.ads.mediation:facebook:5.6.0.0'
implementation 'com.facebook.android:audience-network-sdk:5.6.0'
implementation 'com.facebook.android:facebook-android-sdk:4.41.0'
//Firebase
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.firebase:firebase-ads:18.3.0'
implementation 'com.google.firebase:firebase-config:19.0.3'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-messaging:20.0.1'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.android.play:core:1.6.4'
//FFMPEG
implementation 'com.writingminds:FFmpegAndroid:0.3.2'
//Image crop
implementation 'com.naver.android.helloyako:imagecropview:1.2.2'
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
//Exo Player
implementation 'com.google.android.exoplayer:exoplayer:2.10.5'
//Progress bar
implementation 'com.dinuscxj:circleprogressbar:1.3.0'
//Range seekbar
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
//Glide...
implementation 'com.github.bumptech.glide:glide:4.9.0'
//GPUImage...
implementation 'jp.co.cyberagent.android:gpuimage:2.0.3'
//Fetch a downloader library...
implementation "androidx.tonyodev.fetch2:xfetch2:3.1.4"
implementation "androidx.tonyodev.fetch2okhttp:xfetch2okhttp:3.1.4"
//Downloader for Android 19...
implementation 'com.mindorks.android:prdownloader:0.6.0'
//Lottie...
implementation 'com.airbnb.android:lottie:3.2.0'
//Volley for Anfroid 4!
implementation 'com.android.volley:volley:1.1.1'
//Introduction for any screen...
implementation 'com.github.paolorotolo:appintro:4.0.0'
//ViewPagerEffects...
implementation 'com.eftimoff:android-viewpager-transformers:1.0.1#aar'
//Kochava...
implementation 'com.kochava.base:tracker:3.6.3'
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'com.android.installreferrer:installreferrer:1.1'
//AVLoader...
implementation 'com.wang.avi:library:2.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':jiaozivideoplayer')
}
apply plugin: 'com.google.gms.google-services'
I also implemented Application class as per suggestion and rule:
public class MyApplication extends MultiDexApplication {
#Override
public void onCreate() {
super.onCreate();
MultiDex.install(this);
final Fabric fabric = new Fabric.Builder(this)
.kits(new Crashlytics())
.debuggable(true)
.build();
Fabric.with(fabric);
AudienceNetworkAds.initialize(this);
AudienceNetworkAds.isInAdsProcess(this);
MobileAds.initialize(this, getString(R.string.app_id));
if (Build.VERSION.SDK_INT < 21) {
PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
.setReadTimeout(30_000)
.setConnectTimeout(30_000)
.build();
PRDownloader.initialize(getApplicationContext(), config);
}
Tracker.configure(new Tracker.Configuration(getApplicationContext())
.setAppGuid("koboo-8bod4gz3")
.setLogLevel(Tracker.LOG_LEVEL_INFO)
);
}
}
Above code is OK for Kochava integration. But another thing is that, here I also need all those google and firebase sdk! So, may be its problem is in between google sdk and Kochava sdk! But I need can't remove google sdk or crashlytics and also I need to integrate Kochava for tracking my application in Ad campaign in "Tik Tok" as per its suggestion!
Well if I don't initialize Tracker.configure(....); in application class then app run fine and not crashing but then Kochava not working!
So, after initialize Tracker.configure(...); Kochava sdk it will be generate error:
2019-12-03 15:33:14.254 E/AndroidRuntime: FATAL EXCEPTION: main
Process: xyz.xyz.myapplication, PID: 6113
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/aidl/BaseStub;
at com.android.installreferrer.api.InstallReferrerClientImpl.startConnection(InstallReferrerClientImpl.java:133)
at com.kochava.base.c$a.run(Unknown Source:15)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.aidl.BaseStub" on path: DexPathList[[zip file "/data/app/videostatusmaker.videostatus.boo-Ptd9gTEkM8rXlvGCnCByPg==/base.apk"],nativeLibraryDirectories=[/data/app/videostatusmaker.videostatus.boo-Ptd9gTEkM8rXlvGCnCByPg==/lib/x86, /data/app/videostatusmaker.videostatus.boo-Ptd9gTEkM8rXlvGCnCByPg==/base.apk!/lib/x86, /system/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.android.installreferrer.api.InstallReferrerClientImpl.startConnection(InstallReferrerClientImpl.java:133) 
at com.kochava.base.c$a.run(Unknown Source:15) 
at android.os.Handler.handleCallback(Handler.java:883) 
at android.os.Handler.dispatchMessage(Handler.java:100) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7356) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
May be there is some problem in Kochava library or something I missing in integration?! Please tell me what is the problem? Or it is not suitable with google sdk?
Here is the link for Android Kochava SDK integration.
Well if you have more than one module in your app then put all Kochava dependencies in all of those module :
implementation 'com.kochava.base:tracker:3.6.3'
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'com.android.installreferrer:installreferrer:1.0'
These all must be in all module level gradle files. This is not mentioned is in documentation but you can try it. Because I tried your code in my application and I also have Google ads and other Google's libraries and also have three modules in my app. But added these libraries in all modules than its work perfectly!
I don't know if you have more than one module in your app but if there is than this will helpful.
EDIT
It has been fixed by google, on the same version...
It should work now, if it's still crashing it's probably linked to the previous version being cached, the following should fix it:
implementation('com.android.installreferrer:installreferrer:1.1') { changing .= true}
More information here: https://github.com/adjust/android_sdk/issues/402
Try with com.android.installreferrer:installreferrer:1.0 instead of 1.1
Looks like IGetInstallReferrerService expects com.google.android.aidl.BaseStub in the 1.1 implementation, which does not come with installreferrer
mVck is correct and as far as we can tell, it's likely on Google's end and looks to be specific to version 1.1 of their library. This is our theory because it appears others on SO are experiencing similar issues with other vendor SDKs.
We've reached out to our Google reps to confirm, but in the meantime, please
stay on version 1.0 of Google's library as indicated above. Once we receive confirmation we'll be sure and update our support documentation. Thanks!
I just ran into the same thing and what fixed it for me was to delete the install referrer dependency from my gradle cache and then re-sync with gradle. I think it was something to do with the cached aar. It's bizarre though because it was fine earlier this week and the aar didn't change as far as I'm aware. Regardless, deleting it and re-syncing did the trick for me.
I was having trouble downgrading to 1.0 after attempting to fix this issue with the 1.1.1 fix. In my case the installreferrer was adding the permission READ_PHONE_STATE to my application. Gradle was attempting to resolve 1.1 even after I backed down the version to 1.0 in my app.gradle.
In order to fix this I now force installreferrer to use version 1.0.
dependencies {
configurations.all {
resolutionStrategy.force 'com.android.installreferrer:installreferrer:1.0'
}
implementation 'com.android.installreferrer:installreferrer:1.0'
}

Default FirebaseApp is not initialized in this process. - Android Studio Error

I'm having trouble using Firebase authentication in conjunction with FirebaseUI. When I run my application the following problem appears: "Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp (Context) first."
In my app / build.gradle I have the dependencies:
    
implementation 'com.google.firebase: firebase-core: 16.0.1'
     implementation 'com.google.firebase: firebase-auth: 16.0.1'
     implementation 'com.google.firebase: firebase-database: 16.0.1'
     implementation 'com.firebaseui: firebase-ui-auth: 4.1.0'
and the "apply plugin: 'com.google.gms.google-services" at the end.
in my module / build.gradle I have dependency:
        
classpath 'com.google.gms: google-services: 4.1.0'
classpath 'com.android.tools.build:gradle:3.3.0-alpha07'
I have already exported my googleservices.json to the "app" folder. I was left with no options and the problem continues. Any suggestions?
Logcat:
--------- beginning of crash
08-31 19:40:12.718 2865-2865/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.luccas.buscaperto, PID: 2865
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.luccas.buscaperto/br.com.luccas.buscaperto.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process br.com.luccas.buscaperto. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process br.com.luccas.buscaperto. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
at br.com.luccas.buscaperto.MainActivity.instantiateUser(MainActivity.java:89)
at br.com.luccas.buscaperto.MainActivity.onCreate(MainActivity.java:64)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
my top level gradle:
buildscript {
ext {
release = [
versionName: "6.1.0-rc01",
versionCode: 6100
]
setup = [
compileSdk: 28,
buildTools: "28.0.2",
minSdk : 14,
targetSdk : 28
]
versions = [
androidX: '1.0.0-rc01'
]
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha07'
classpath 'com.google.gms:google-services:4.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
my app level gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "br.com.luccas.buscaperto"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.2'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.legacy:legacy-support-v4:${versions.androidX}"
implementation "androidx.appcompat:appcompat:${versions.androidX}"
implementation "androidx.constraintlayout:constraintlayout:${versions.androidX}"
implementation "androidx.recyclerview:recyclerview:${versions.androidX}"
implementation "androidx.annotation:annotation:${versions.androidX}"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.mikepenz:materialdrawer:6.1.0-rc01'
implementation "com.google.android.material:material:${versions.androidX}"
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
apply plugin: 'com.google.gms.google-services'
Please upgrade your project level gms dependencies, I upgraded to 4.2.0 and it worked
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
I had same issue and the issue was with google-services.json that was not in proper format and some how, google-services.json had following in the file
COMMENT start
clone the project and in firefox create a database and give the package name as .....
Try to do like so:
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0
And change this:
classpath 'com.android.tools.build:gradle:3.3.0-alpha07'
to
classpath 'com.android.tools.build:gradle:3.1.4'
you need to update your google_services.json file. Download it from firebase and replace with the existing one. In json file there is a configuration which automatically merged the content provider which intitalizes your Firebase for the app with your manifest by default on building with gradle. But your current json file is missing that configuration. So you need to replace or you need to call static FirebaseApp(Context) method to solve this problem.Read Here
Add this in your app launcher onCreate method as
...... onCreate(.....)
{
FirebaseApp.initializeApp(this);
..........
}
It works by downgradind to:
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
I had same issue in my app,
but according to https://issuetracker.google.com/issues/112716914 this issue tracker
I have updated to version classpath 'com.google.gms:google-services:4.2.0' and issue got resolved.
Edit your dependencies in build.gradle Project level:
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
Oncreate method add this:
FirebaseApp.initializeApp(this);

App crashes on first install through Play Store [duplicate]

since I've updated to Android Studio 3.1, my project is not running anymore. I have searched for a solution all over the internet with no positive results.
Here's the error I get in the Logcat:
--------- beginning of crash
04-13 13:33:55.466 12720-12720/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: woopy.domain.com.woopy, PID: 12720
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2)
at android.app.ActivityThread.installProvider(ActivityThread.java:6239)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/woopy.domain.com.woopy-KqNv1gE1ZomaesHCq33DJw==/base.apk"],nativeLibraryDirectories=[/data/app/woopy.domain.com.woopy-KqNv1gE1ZomaesHCq33DJw==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2) 
at android.app.ActivityThread.installProvider(ActivityThread.java:6239) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722) 
at android.app.ActivityThread.-wrap1(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
04-13 13:33:55.567 12720-12727/? I/zygote: Debugger is no longer active
Here's my build.gradle (Module:app) file:
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "woopy.domain.com.woopy"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
aaptOptions {
cruncherEnabled = false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
implementation 'com.parse:parse-android:+'
implementation 'com.parse.bolts:bolts-android:1.+'
//noinspection GradleCompatible
implementation 'com.google.android.gms:play-services-maps:+'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services:+'
implementation 'com.google.android.gms:play-services-ads:+'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.facebook.android:facebook-android-sdk:4.+'
implementation 'com.parse:parsefacebookutils-v4-android:1.10.3#aar'
implementation 'com.commit451:PhotoView:1.2.4'
}
And here's my build.gradle (Project: appname):
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The Build is successful, but the app crashes at startup.
EDIT:
It doesn't build successful anymore now, it throws this absolutely weird error in the Build message console:
AGPBI: {"kind":"error","text":"Program type already present: com.google.android.gms.location.places.zza","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'
.
Try adding this dependency to your gradle file:
implementation 'com.android.support:multidex:1.0.3'
Also you should use the same versions for the support and play services libraries. And you should avoid using "+" for latest version. Change this part:
implementation 'com.google.android.gms:play-services-maps:+'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services:+'
implementation 'com.google.android.gms:play-services-ads:+'
into this:
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.gms:play-services-ads:12.0.1'
EDIT: You may also add this part to your app level gradle file and try again. I did not see anyone tried this but it may work.
allprojects {
repositories {
//...
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "12.0.1"
}
}
}
}
}
2ND UPDATE: Just seen this, the dependency below, covers all the others, then it may cause a duplication issue. Remove the other dependencies and leave this one:
implementation 'com.google.android.gms:play-services:12.0.1'
I had the same issue and I solved it.Update all your com.google.android.gms:play-services dependencies to 15.0.0. It should look like this:
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.android.gms:play-services:15.0.0'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
Once you do that, it should fix the issue with finding the NoClassDefFoundError error (at least it did for me).
That worked for me I added subprojects block as below to my project gradle file
allprojects {
repositories {
//...
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "+"
}
if (details.requested.group == 'com.google.firebase'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "+"
}
}
}
}
}
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.android.gms:play-services:15.0.0'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
This helped me.
You may be using different verions of libraries.
Important point is you may be using an external library which is using a different play services version (may be older) . Please check care fully all external libraries updates and match them all
I solved it by removing
implementation "com.google.android.gms:play-services:$play_service_version"
and keeping only important dependencies.
In my case I had
implementation "com.google.android.gms:play-services:$play_service_version"
implementation "com.google.android.gms:play-services-location:$play_service"
And I removed
implementation "com.google.android.gms:play-services:$play_service_version"
and kept
implementation "com.google.android.gms:play-services-location:$play_service"
Here play_service_version & play_service are versions
I had exactly the same problem. I tried quite a few things, but here's what actually helped.
I added this to my project:
implementation 'com.google.android.gms:play-services-base:16.0.1'.
The error went away.
Then I removed it. Everything was still fine. Cleaned the project - still no error.
Don't ask me for logic behind this, it just worked for me, that's all I know.
#cubycode I am also running into the same issue and I tried all solutions listed here.
I received the same error even with the 'zzbq;' at the end
In app build.gradle I had to update my com.google.firebase:firebase-core to 16.0.1 to match the same line in the react-native-firebase build.gradle
Example:
app/build.gradle
implementation 'com.google.firebase:firebase-core:16.0.1'
react-native-firebase/android/build.gradle
compileOnly "com.google.firebase:firebase-core:16.0.1"
Step 1:
This kind of error throw the some logs. Read it carefully to find out which dependency cause this issue
Step 2:
Update that dependency to latest version.
For ex: In my case it throw the error in material design dependency. I just update that dependency to latest version - problem solved
My error log - Didn't find class "com.google.android.material.tabs........"

Android 3.1.1 - Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;

since I've updated to Android Studio 3.1, my project is not running anymore. I have searched for a solution all over the internet with no positive results.
Here's the error I get in the Logcat:
--------- beginning of crash
04-13 13:33:55.466 12720-12720/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: woopy.domain.com.woopy, PID: 12720
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2)
at android.app.ActivityThread.installProvider(ActivityThread.java:6239)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.zzbq" on path: DexPathList[[zip file "/data/app/woopy.domain.com.woopy-KqNv1gE1ZomaesHCq33DJw==/base.apk"],nativeLibraryDirectories=[/data/app/woopy.domain.com.woopy-KqNv1gE1ZomaesHCq33DJw==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2) 
at android.app.ActivityThread.installProvider(ActivityThread.java:6239) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5805) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5722) 
at android.app.ActivityThread.-wrap1(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
04-13 13:33:55.567 12720-12727/? I/zygote: Debugger is no longer active
Here's my build.gradle (Module:app) file:
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "woopy.domain.com.woopy"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
aaptOptions {
cruncherEnabled = false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
implementation 'com.parse:parse-android:+'
implementation 'com.parse.bolts:bolts-android:1.+'
//noinspection GradleCompatible
implementation 'com.google.android.gms:play-services-maps:+'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services:+'
implementation 'com.google.android.gms:play-services-ads:+'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.facebook.android:facebook-android-sdk:4.+'
implementation 'com.parse:parsefacebookutils-v4-android:1.10.3#aar'
implementation 'com.commit451:PhotoView:1.2.4'
}
And here's my build.gradle (Project: appname):
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The Build is successful, but the app crashes at startup.
EDIT:
It doesn't build successful anymore now, it throws this absolutely weird error in the Build message console:
AGPBI: {"kind":"error","text":"Program type already present: com.google.android.gms.location.places.zza","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'
.
Try adding this dependency to your gradle file:
implementation 'com.android.support:multidex:1.0.3'
Also you should use the same versions for the support and play services libraries. And you should avoid using "+" for latest version. Change this part:
implementation 'com.google.android.gms:play-services-maps:+'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services:+'
implementation 'com.google.android.gms:play-services-ads:+'
into this:
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.gms:play-services-ads:12.0.1'
EDIT: You may also add this part to your app level gradle file and try again. I did not see anyone tried this but it may work.
allprojects {
repositories {
//...
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "12.0.1"
}
}
}
}
}
2ND UPDATE: Just seen this, the dependency below, covers all the others, then it may cause a duplication issue. Remove the other dependencies and leave this one:
implementation 'com.google.android.gms:play-services:12.0.1'
I had the same issue and I solved it.Update all your com.google.android.gms:play-services dependencies to 15.0.0. It should look like this:
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.android.gms:play-services:15.0.0'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
Once you do that, it should fix the issue with finding the NoClassDefFoundError error (at least it did for me).
That worked for me I added subprojects block as below to my project gradle file
allprojects {
repositories {
//...
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "+"
}
if (details.requested.group == 'com.google.firebase'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "+"
}
}
}
}
}
implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.android.gms:play-services:15.0.0'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
This helped me.
You may be using different verions of libraries.
Important point is you may be using an external library which is using a different play services version (may be older) . Please check care fully all external libraries updates and match them all
I solved it by removing
implementation "com.google.android.gms:play-services:$play_service_version"
and keeping only important dependencies.
In my case I had
implementation "com.google.android.gms:play-services:$play_service_version"
implementation "com.google.android.gms:play-services-location:$play_service"
And I removed
implementation "com.google.android.gms:play-services:$play_service_version"
and kept
implementation "com.google.android.gms:play-services-location:$play_service"
Here play_service_version & play_service are versions
I had exactly the same problem. I tried quite a few things, but here's what actually helped.
I added this to my project:
implementation 'com.google.android.gms:play-services-base:16.0.1'.
The error went away.
Then I removed it. Everything was still fine. Cleaned the project - still no error.
Don't ask me for logic behind this, it just worked for me, that's all I know.
#cubycode I am also running into the same issue and I tried all solutions listed here.
I received the same error even with the 'zzbq;' at the end
In app build.gradle I had to update my com.google.firebase:firebase-core to 16.0.1 to match the same line in the react-native-firebase build.gradle
Example:
app/build.gradle
implementation 'com.google.firebase:firebase-core:16.0.1'
react-native-firebase/android/build.gradle
compileOnly "com.google.firebase:firebase-core:16.0.1"
Step 1:
This kind of error throw the some logs. Read it carefully to find out which dependency cause this issue
Step 2:
Update that dependency to latest version.
For ex: In my case it throw the error in material design dependency. I just update that dependency to latest version - problem solved
My error log - Didn't find class "com.google.android.material.tabs........"

Firebase getInstance always throwing No virtual method Exception

I am integrating Firebase realtime database inside my app, I followed the adding instructions, but it's always throwing exception
No virtual method
FATAL EXCEPTION: main
Process: appsTest.test, PID: 17680
java.lang.NoSuchMethodError: No virtual method zzcnu()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/appsTest.test-2/base.apk:classes15.dex)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at appsTest.test.inAppViews.newsFeedScreen.NewsFeedFragment.<init>(NewsFeedFragment.java:31)
at appsTest.test.inAppViews.BaseActivity.onClickOnTab(BaseActivity.java:144)
at appsTest.test.inAppViews.BaseActivity.onTabSelected(BaseActivity.java:258)
at com.ashokvarma.bottomnavigation.BottomNavigationBar.sendListenerCall(BottomNavigationBar.java:578)
at com.ashokvarma.bottomnavigation.BottomNavigationBar.selectTabInternal(BottomNavigationBar.java:558)
at com.ashokvarma.bottomnavigation.BottomNavigationBar.access$000(BottomNavigationBar.java:44)
at com.ashokvarma.bottomnavigation.BottomNavigationBar$1.onClick(BottomNavigationBar.java:502)
at android.view.View.performClick(View.java:6213)
at android.view.View$PerformClick.run(View.java:23645)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Project gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
App module gradle:
compile "com.google.firebase:firebase-messaging:+"
compile "com.google.firebase:firebase-core:9.6.1"
compile 'com.google.firebase:firebase-database:9.6.1'
apply plugin: 'com.google.gms.google-services' // this code at the end of gradle file
Initializing FireBase Database inside fragment at the OnCreate method:
DatabaseReference mRootRefernce = FirebaseDatabase.getInstance().getReference(); // at this line the exception happened
DatabaseReference reference = mRootRefernce.child("feed");
it's fixed by the following:
use the same version for Google play services (3.1.0)
update all libraries that depend on older version of Google play services, and it's in my case OneSignal library to the latest version
Try to use the latest version of firebase.
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.firebase:firebase-core:11.2.0'
google services:
classpath 'com.google.gms:google-services:3.1.0'
in app/build.gradle do you have below in the end?
apply plugin: 'com.google.gms.google-services'

Categories

Resources