Home > Net >  What is Firestore component is not present and how to fix it
What is Firestore component is not present and how to fix it

Time:03-22

What is:

Unable to start activity ComponentInfo: java.lang.NullPointerException: Firestore component is not present

Recently i have converted code from java to Kotlin. Few days it worked well but from last 1 week i don't know why but whenever i run the application below error is coming.

Kotlin error -

java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException: Firestore component is not present

Below is my app gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'com.google.gms.google-services'
}

android {
    compileSdkVersion 31

    defaultConfig {
        configurations.all {
            resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
        }
        applicationId "in.xxx"
        minSdkVersion 26
        targetSdkVersion 31
        versionCode 2
        versionName "1.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    buildFeatures {
        viewBinding false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }
}

dependencies {

    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    implementation 'com.google.firebase:firebase-firestore-ktx'
    implementation 'com.google.firebase:firebase-storage-ktx'
    implementation 'com.google.firebase:firebase-auth-ktx'
    implementation 'com.google.firebase:firebase-messaging-ktx'
    implementation 'com.google.firebase:firebase-core'
    implementation 'com.github.OneTouchPro:One:3.4'   
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'

    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

Project Gradle:

buildscript {
    ext.kotlin_version = "1.6.10"
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

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

Kotlin File:

class MainActivity : AppCompatActivity() {

    private lateinit var mStorageRef: StorageReference
    private lateinit var oneSharedPref: OneSharedPref
    private lateinit var database: FirebaseFirestore
    private lateinit var mProgress: OneProgress
    private lateinit var postAdapter: PostAdapter
    private lateinit var categoryAdapter: CategoryAdapter

    private var startDate: Timestamp? = null
    private var dateValue: Int? = 0
    private var calendar: Calendar? = Calendar.getInstance()
    private var query: Query? = null
    private var splash: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)      

        FirebaseApp.initializeApp(this)
        database = Firebase.firestore
    }

Error is coming for this line

database = Firebase.firestore

CodePudding user response:

I got solution to my problem. Added Binding option in my scripts and moved project dependencies to gradle settings.

  • Related