Home > OS >  I think my Android app is crashing due to Firebase configuration issues
I think my Android app is crashing due to Firebase configuration issues

Time:07-29

I made a login and a registration acitivty with Firebase. When I start the app I get lot of exceptions. I think it is not due to the syntax but due to the configuration.

Registration

class RegistrationActivity : AppCompatActivity() {

    private  lateinit var auth: FirebaseAuth

    //Email und Passwort Eingabefelder
    val regEmail: EditText = findViewById(R.id.registration_email)
    val regPassword: EditText = findViewById(R.id.registration_password)

    override fun onCreate(savedInstanceState: Bundle?) {


        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_registration)

        auth = FirebaseAuth.getInstance()

        //Button der gedrückt wird zum Registrieren nach dem man seine Daten eingegeben hat
        val registration_button: Button = findViewById(R.id.registration_button)
        registration_button.setOnClickListener {
            //WENN Button gedrückt DANN rufe FUNKTION auf
            createUser()
        }


        //Zurück zum login
        val login_texView: TextView = findViewById(R.id.loginLink_textView)
        login_texView.setOnClickListener {
            val intent_registration_activiy = Intent(this, RegistrationActivity::class.java)
            startActivity(intent_registration_activiy)
        }
    }

    /**
     * Function: createUser
     * Eingegebene Email und Passwort werden in Strings umgewandelt
     * Danach wird überprüft ob die Email und Passwort Felder leer sind
     * IF Leer DANN Error und Focus
     * SONST:
     * User wird erstellt mit eingegebener email und passwort
     * Es wird danach überprüft ob die Registrierung erfolgreich war oder nicht
     * WENN erfolgreich: Toast, Weiterleitung zum Login
     * SONST: Toast
     *
     */
    private fun createUser(){
        val email: String = regEmail.text.toString()
        val password: String = regPassword.text.toString()

        if(TextUtils.isEmpty(email)){
            regEmail.setError("E-mail kann nicht leer sein")
            regEmail.requestFocus()
        } else if(TextUtils.isEmpty(password)){
            regPassword.setError("Passwort kann nicht leer sein")
            regPassword.requestFocus()
        } else{
            auth.createUserWithEmailAndPassword(email, password).addOnCompleteListener { task ->
                if (task.isSuccessful){
                    val successfull_toast = Toast.makeText(this, "Registrierung erfolgreich", Toast.LENGTH_LONG)
                    successfull_toast.show()
                    val intent_logIn_activity = Intent(this, LoginActivity::class.java)
                    startActivity(intent_logIn_activity)
                } else {
                    val unsuccsessfull_toast = Toast.makeText(this, "Ein Fehler ist aufgetreten "   task.exception?.message, Toast.LENGTH_LONG)

                }
            }
        }
    }
} 

Login

class LoginActivity : AppCompatActivity() {

    private lateinit var auth: FirebaseAuth

    val logEmail: EditText = findViewById(R.id.userLogInEmail)                  //email zum einloggen
    val logPassword: EditText = findViewById(R.id.userLogInPassword)            //passwort zum einloggen
    val logButton: Button = findViewById(R.id.logIn_button)                     //Button zum einloggen
    val regLink: TextView = findViewById(R.id.registration_textView)            //Zur Registration Activity

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

        auth = FirebaseAuth.getInstance()

        //Login Button OnClick
        logButton.setOnClickListener {
            loginUser()
        }
        //Klicke und komme zur Registrations Activity
        regLink.setOnClickListener {
            val intent_regActivity = Intent(this, RegistrationActivity::class.java)
            startActivity(intent_regActivity)
        }
    }

    private fun loginUser(){
        val email: String = logEmail.text.toString()
        val password: String = logPassword.text.toString()

        if (TextUtils.isEmpty(email)){
            logEmail.setError("Email kann nicht leer sein")
            logEmail.requestFocus()
        } else if (TextUtils.isEmpty(password)){
            logPassword.setError("Passwort kann nicht leer sein")
            logPassword.requestFocus()
        } else {
            auth.signInWithEmailAndPassword(email, password).addOnCompleteListener { task ->
                if(task.isSuccessful){
                    val successfull_toast = Toast.makeText(this, "Login erfolgreich", Toast.LENGTH_LONG)
                    successfull_toast.show()
                    val intent_mainActivity = Intent(this, MainActivity::class.java)
                    startActivity(intent_mainActivity)
                } else {
                    val unsuccessfull_toast = Toast.makeText(this, "Login nicht möglich "   task.exception?.message, Toast.LENGTH_LONG)
                    unsuccessfull_toast.show()
                }
            }
        }
    }
}

Main

class MainActivity : AppCompatActivity() {
    private lateinit var auth: FirebaseAuth


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

        auth = FirebaseAuth.getInstance()
    }

    /**
     * Wenn die App startet wird überprüft ob der User angemeldet ist oder nicht bzw. einen Account hat
     * IF NOT gehe zur Login-Acitiviy
     */
    override fun onStart() {
        super.onStart()
        val user = auth.currentUser
        if(user == null){
            val intent = Intent(this, LoginActivity::class.java)
            startActivity(intent)
        }
    }
}

When I start the app I get these exceptions:

Caused by: com.android.builder.errors.EvalIssueException: Configuration `:app:debugRuntimeClasspath` contains AndroidX dependencies, but the `android.useAndroidX` property is not enabled, which may cause runtime issues.
Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
Caused by: java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.2.0-runtime (androidx.core:core:1.2.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)
Configuration `:app:debugRuntimeClasspath` contains AndroidX dependencies, but the `android.useAndroidX` property is not enabled, which may cause runtime issues.
Set `android.useAndroidX=true` in the `gradle.properties` file and retry.
The following AndroidX dependencies are detected:
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.collection:collection:1.1.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.annotation:annotation:1.1.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.concurrent:concurrent-futures:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.interpolator:interpolator:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.core:core:1.2.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.core:core:1.2.0 -> androidx.lifecycle:lifecycle-runtime:2.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.core:core:1.2.0 -> androidx.lifecycle:lifecycle-runtime:2.0.0 -> androidx.lifecycle:lifecycle-common:2.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.core:core:1.2.0 -> androidx.lifecycle:lifecycle-runtime:2.0.0 -> androidx.arch.core:core-common:2.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.browser:browser:1.4.0 -> androidx.core:core:1.2.0 -> androidx.versionedparcelable:versionedparcelable:1.1.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-utils:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-utils:1.0.0 -> androidx.documentfile:documentfile:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.loader:loader:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.loader:loader:1.0.0 -> androidx.lifecycle:lifecycle-livedata:2.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.loader:loader:1.0.0 -> androidx.lifecycle:lifecycle-livedata:2.0.0 -> androidx.arch.core:core-runtime:2.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.loader:loader:1.0.0 -> androidx.lifecycle:lifecycle-livedata:2.0.0 -> androidx.lifecycle:lifecycle-livedata-core:2.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.lifecycle:lifecycle-viewmodel:2.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-utils:1.0.0 -> androidx.print:print:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.customview:customview:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.viewpager:viewpager:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.coordinatorlayout:coordinatorlayout:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.drawerlayout:drawerlayout:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.slidingpanelayout:slidingpanelayout:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.swiperefreshlayout:swiperefreshlayout:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.asynclayoutinflater:asynclayoutinflater:1.0.0
:app:debugRuntimeClasspath -> com.google.firebase:firebase-auth:21.0.6 -> androidx.fragment:fragment:1.0.0 -> androidx.legacy:legacy-support-core-ui:1.0.0 -> androidx.cursoradapter:cursoradapter:1.0.0

How can I fix this issue ?

CodePudding user response:

Did you try what it's suggesting in the error message? It's pretty helpful!

Caused by: com.android.builder.errors.EvalIssueException:
 Configuration `:app:debugRuntimeClasspath` contains AndroidX dependencies,
 but the `android.useAndroidX` property is not enabled, which may cause runtime issues.

Your app is using AndroidX dependencies (i.e. the modern version of the Support Library and the Jetpack components) but you've not actually enabled the useAndroidX property

Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
Caused by: java.lang.RuntimeException: Duplicate class
 android.support.v4.app.INotificationSideChannel found in modules
 core-1.2.0-runtime (androidx.core:core:1.2.0)
 and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0)

You're using AndroidX libraries and the old Support library, and those conflict with each other - here the same class exists in both and that's causing a RuntimeException during your build, i.e. a crash.

There's no need for a modern app to use the Support Library anymore, and it's recommended you move to AndroidX since that's what's being developed and what your other dependencies use.

Configuration `:app:debugRuntimeClasspath` contains AndroidX dependencies,
 but the `android.useAndroidX` property is not enabled, which may cause runtime issues.
 Set `android.useAndroidX=true` in the `gradle.properties` file and retry.

And here it's telling you how to fix it - add that property in your gradle.properties file. You might also want to add android.enableJetifier=true to that file as the docs explain.

If you're using AndroidX, make sure you change all your support dependencies to the androidx equivalents in your module-level build.gradle file. You can migrate to AndroidX automatically using a command in Android Studio - I've never used it, but it's there. That link tells you more about the migration process and stuff you need to look out for

  • Related