You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android新手使用Firebase Authentication遇连接异常求助

Firebase Authentication Connection Exception on Button Click (Android)

I'm a beginner Android developer trying to implement Firebase Authentication by copying sample code. I've created a Firebase project and completed the server connection, but a connection exception is always triggered when I click the button.

Layout Code

<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:layout_marginTop="10dp" android:id="@+id/uyeEmail" /> 
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:ems="10" android:layout_marginTop="10dp" android:id="@+id/uyeParola" /> 
<Button android:text="Üye Ol!" android:layout_width="100dp" android:layout_height="50dp" android:layout_marginTop="50dp" android:id="@+id/yeniUyeButton" /> 
<Button android:text="Zaten üye misin?" android:layout_width="200dp" android:layout_height="wrap_content" android:id="@+id/uyeGirisButton" android:layout_marginBottom="10dp" />

Logic Code

auth = FirebaseAuth.getInstance(); 
uyeParola = (EditText)findViewById(R.id.uyeParola); 
uyeEmail = (EditText)findViewById(R.id.uyeEmail); 
uyeGirisButton = (Button)findViewById(R.id.uyeGirisButton); 
uyeGirisButton.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { } 
}); 
yeniUyeButton = (Button)findViewById(R.id.yeniUyeButton); 
yeniUyeButton.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
        String email = uyeEmail.getText().toString(); 
        String parola = uyeParola.getText().toString(); 
        if(TextUtils.isEmpty(email)){ 
            Toast.makeText(getApplicationContext(),"Lütfen emailinizi giriniz",Toast.LENGTH_SHORT).show(); 
            return; 
        } 
        if(TextUtils.isEmpty(parola)){ 
            Toast.makeText(getApplicationContext(),"Lütfen parolanızı giriniz",Toast.LENGTH_SHORT).show(); 
        } 
        if (parola.length()<6){ 
            Toast.makeText(getApplicationContext(),"Parola en az 6 haneli olmalıdır",Toast.LENGTH_SHORT).show(); 
        } 
        //FirebaseAuth ile email,parola parametrelerini kullanarak yeni bir kullanıcı oluşturuyoruz. 
        auth.createUserWithEmailAndPassword(email,parola) 
            .addOnCompleteListener(giris.this, new OnCompleteListener<AuthResult>() { 
                @Override 
                public void onComplete(@NonNull Task<AuthResult> task) { 
                    //İşlem başarısız olursa kullanıcıya bir Toast mesajıyla bildiriyoruz. 
                    if (!task.isSuccessful()) { 
                        Toast.makeText(giris.this, "Exception... Sorry :(", Toast.LENGTH_SHORT).show(); 
                    } 
                    //İşlem başarılı olduğu takdir de giriş yapılıp MainActivity e yönlendiriyoruz. 
                    else { 
                        startActivity(new Intent(giris.this, MainActivity.class)); 
                        finish(); 
                    } 
                } 
            }); 
    } 
});

Permission Configuration

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Hey Berkay, let's troubleshoot why you're hitting that connection exception with Firebase Auth. I've gone through your code and setup, here are the most common fixes to try:

1. Verify Firebase Project Setup

First, double-check that you've added the correct google-services.json file to your app module's root directory. Make sure it's the exact file downloaded from your Firebase project's console—mixing up files from different projects is a super common pitfall.

2. Enable Email/Password Sign-In in Firebase Console

Head over to your Firebase project's Authentication section, then go to the Sign-in method tab. Ensure the Email/Password option is toggled on. If this is disabled, Firebase will reject all user creation requests, which can look like a connection error.

3. Fix Network Configuration

Even though you've added the INTERNET permission, if your app targets SDK 28 or higher, you might need to enable cleartext traffic (since some Firebase endpoints use HTTP temporarily). Add this line to your <application> tag in AndroidManifest.xml:

android:usesCleartextTraffic="true"

Also, confirm your device/emulator has a stable internet connection and isn't blocked by a firewall or proxy that might block Firebase's servers.

4. Get Specific Error Details

Your current error message is too vague—let's update the code to show the actual exception:

if (!task.isSuccessful()) {
    String errorMsg = task.getException() != null ? task.getException().getMessage() : "Unknown error occurred";
    Toast.makeText(giris.this, "Error: " + errorMsg, Toast.LENGTH_LONG).show();
}

This will tell you exactly what's wrong—whether it's a network issue, invalid credentials, or a configuration problem.

5. Check Context and Initialization

Make sure FirebaseAuth.getInstance() is initialized inside your Activity's onCreate() method. Also, in the addOnCompleteListener, try replacing giris.this with getApplicationContext() to rule out any context-related issues.

6. Update Firebase Dependencies

Outdated dependencies can cause compatibility issues. Open your app's build.gradle file and ensure you're using the latest stable version of Firebase Auth:

implementation 'com.google.firebase:firebase-auth:22.3.1'

Also, confirm your com.google.gms:google-services plugin version is up to date in your project-level build.gradle.

Try these steps one by one, and once you get the specific error message from the updated Toast, that'll help narrow things down even more. Good luck!


内容的提问来源于stack exchange,提问作者Berkay Isıkoglu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:15:28