Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

android - Java help for implementation of Firebase authorisation

I believe I have successfully setup Firebase, but I am having issue with the Java end in Android Studio (AS). I had been following a YouTube tutorial as I am quite new to AS and Firebase, I want to have three sign in options: Facebook, Google and Email. AS cannot resolve symbol for "FirebaseAuth", "getCurrentUser" or "AuthUI". Any help is greatly appreciated!

Here is my Java MainActivity:

package com.uni.smartprogression;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.firebase.ui.auth.AuthUI;

public class MainActivity extends AppCompatActivity {
private static final int RC_SIGN_IN = 0;
private FireBaseAuth auth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    auth = FirebaseAuth.getInstance();
    //User already signed in
    if (auth.getCurrentUser() != null) {
        //User already logged in
        Log.d("AUTH", auth.getCurrentUser().getEmail());
    }
    else {
        startActivityForResult(AuthUI.getInstance()
                        .createSignInIntentBuiler()
                        .setProviders(
                                AuthUI.FACEBOOK_PROVIDER,
                                AuthUI.EMAIL_PROVIDER,
                                AuthUI.GOOGLE_PROVIDER )
                        .build(),
                RC_SIGN_IN);
    }
}

@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN){
        if (resultCode == RESULT_OK){
            //User logged in
            Log.d("AUTH", auth.getCurrentUser().getEmail());
        }
        else {
            //User not authenticated
            Log.d("AUTH", "NOT AUTHENTICATED");
        }
    }
}
}

Here is my app build gradle:

plugins {
id 'com.android.application'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
    applicationId "com.uni.smartprogression"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation platform('com.google.firebase:firebase-bom:26.2.0')
implementation ('com.google.firebase:firebase-auth:26.2.0')
implementation 'com.google.firebase:firebase-database:26.2.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
 // implementation platform'com.google.firebase:firebase-storage:26.2.0'
}

apply plugin: 'com.google.gms.google-services'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...