英文:
Signin buttons not getting rendered properly in my Android layout
问题
I created a signin page containing two buttons, one for Google signin and another for passwordless signin:
<com.firebase.ui.auth.ui.phone.CountryListSpinner
    android:id="@+id/signInButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
    android:text="@string/fui_sign_in_with_google"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp" />
<com.firebase.ui.auth.ui.phone.CountryListSpinner
    android:id="@+id/emailSignInButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/signInButton"
    android:layout_centerHorizontal="true"
    style="@style/FirebaseUI.Button.AccountChooser.EmailButton"
    android:text="@string/fui_sign_in_with_email"
    tools:ignore="UnusedIds" />
However, when the layout is rendered, the buttons look like this:

instead of this:

Also, when I press either button, I get an error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.IBinder android.view.View.getApplicationWindowToken()' on a null object reference
I confirmed the button views are not null:
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    crashlytics = FirebaseCrashlytics.getInstance();
    context = getApplicationContext();
    try {
        setContentView(R.layout.activity_login);
    } catch (RuntimeException ex) {
        Toast.makeText(this, getString(R.string.install_from_google_play), Toast.LENGTH_LONG).show();
        crashlytics.log("Crash on setContentView() in LoginActivity.java: " + ex.getLocalizedMessage());
        return;
    }
    Trace myTrace = FirebasePerformance.getInstance().newTrace("test_trace");
    myTrace.start();
    settings = getSharedPreferences(OPENCOMMENTS_SETTINGS, Context.MODE_PRIVATE);
    editor = settings.edit();
    // Views
    findViewById(R.id.signInButton).setOnClickListener(this);
    findViewById(R.id.emailSignInButton).setOnClickListener(this);
}
Anyone have an idea what's going on here? I'm running Android Studio Electric Eeel (2022.1.1 Canary 7) on a Linux computer and my project gradle file is the following:
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.0-alpha07'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
        classpath 'com.google.firebase:perf-plugin:1.4.2'
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}
英文:
I created a signin page containing two buttons, one for Google signin and another for passwordless signin:
    <com.firebase.ui.auth.ui.phone.CountryListSpinner
        android:id="@+id/signInButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
        android:text="@string/fui_sign_in_with_google"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp" />
    <com.firebase.ui.auth.ui.phone.CountryListSpinner
        android:id="@+id/emailSignInButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/signInButton"
        android:layout_centerHorizontal="true"
        style="@style/FirebaseUI.Button.AccountChooser.EmailButton"
        android:text="@string/fui_sign_in_with_email"
        tools:ignore="UnusedIds" />
However, when the layout is rendered, the buttons look like this:

instead of this:

Also, when I press either button, I get an error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.IBinder android.view.View.getApplicationWindowToken()' on a null object reference
I confirmed the button views are not null:
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    crashlytics = FirebaseCrashlytics.getInstance();
    context = getApplicationContext();
    try {
        setContentView(R.layout.activity_login);
    } catch (RuntimeException ex) {
        Toast.makeText(this, getString(R.string.install_from_google_play), Toast.LENGTH_LONG).show();
        crashlytics.log("Crash on setContentView() in LoginActivity.java: " + ex.getLocalizedMessage());
        return;
    }
    Trace myTrace = FirebasePerformance.getInstance().newTrace("test_trace");
    myTrace.start();
    settings = getSharedPreferences(OPENCOMMENTS_SETTINGS, Context.MODE_PRIVATE);
    editor = settings.edit();
    // Views
    findViewById(R.id.signInButton).setOnClickListener(this);
    findViewById(R.id.emailSignInButton).setOnClickListener(this);
Anyone have an idea what's going on here? I'm running Android Studio Electric Eeel (2022.1.1 Canary 7) on a Linux computer and my project gradle file is the following:
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.0-alpha07'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
        classpath 'com.google.firebase:perf-plugin:1.4.2'
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}
答案1
得分: 0
这是由com.firebaseui:firebase-ui-auth:8.0.2中的一个错误引起的。一旦我回退到4.3.2版本,问题就解决了。
英文:
This was caused by a bug in com.firebaseui:firebase-ui-auth:8.0.2. Once I reverted to 4.3.2, the problem went away.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论