質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

579閲覧

Kotlin を使った Firebaseのログインができない

soma62jp

総合スコア141

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2022/01/15 08:41

編集2022/01/16 03:16

Kotlinを使ってFirebaseでログイン処理をしようと思っています。

下記のコードを試しましたが、常にログインが失敗します。
FireBase側の設定では、メール認証を有効にしています。

同様の問題の知見のある方、ご教示のほどよろしくお願い致します。

エラーメッセージ
2022-01-16 11:20:38.271 3895-3895/com.example.myapplication D/Create: com.google.firebase.FirebaseApiNotAvailableException: API: InternalFirebaseAuth.FIREBASE_AUTH_API is not available on this device.

Kotlin

1package com.example.myapplication 2 3import android.os.Bundle 4import android.util.Log 5import androidx.appcompat.app.AppCompatActivity 6import android.widget.Button 7import android.widget.EditText 8import android.widget.Toast 9import com.google.firebase.FirebaseApp 10import com.google.firebase.auth.FirebaseAuth 11import com.google.firebase.database.DatabaseReference 12import com.google.firebase.database.FirebaseDatabase 13 14 15class MainActivity : AppCompatActivity() { 16 17 private lateinit var auth: FirebaseAuth 18 19 override fun onCreate(savedInstanceState: Bundle?) { 20 super.onCreate(savedInstanceState) 21 setContentView(R.layout.activity_main) 22 23 auth = FirebaseAuth.getInstance() 24 25 val buttonSignUp = findViewById<Button>(R.id.SignUpButton) 26 val buttonLogin = findViewById<Button>(R.id.LoginButton) 27 28 buttonSignUp.setOnClickListener { 29 30 val emailEditText = findViewById<EditText>(R.id.emailEditText) 31 val emailText = emailEditText.text.toString() 32 33 val passEditText = findViewById<EditText>(R.id.passEditText) 34 val passText = passEditText.text.toString() 35 36 37 auth.createUserWithEmailAndPassword(emailText, passText) 38 .addOnCompleteListener(this) { task -> 39 if (task.isSuccessful) { 40 Toast.makeText( 41 baseContext, "SignUp 成功", 42 Toast.LENGTH_SHORT 43 ).show() 44 } else { 45 Toast.makeText( 46 baseContext, "SignUp 失敗", 47 Toast.LENGTH_SHORT 48 ).show() 49 Log.d("Create",task.exception.toString()) 50 } 51 } 52 } 53 54 buttonLogin.setOnClickListener { 55 56 val emailEditText = findViewById<EditText>(R.id.emailEditText) 57 val emailText = emailEditText.text.toString() 58 59 val passEditText = findViewById<EditText>(R.id.passEditText) 60 val passText = passEditText.text.toString() 61 62 auth.signInWithEmailAndPassword(emailText, passText) 63 .addOnCompleteListener(this) { task -> 64 if (task.isSuccessful) { 65 Toast.makeText( 66 baseContext, "Login 成功", 67 Toast.LENGTH_SHORT 68 ).show() 69 } else { 70 Toast.makeText( 71 baseContext, "Login 失敗", 72 Toast.LENGTH_SHORT 73 ).show() 74 Log.d("Login",task.exception.toString()) 75 } 76 77 } 78 } 79 80 } 81}

mctivity_main.xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:tools="http://schemas.android.com/tools" 5 xmlns:app="http://schemas.android.com/apk/res-auto" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 tools:context=".MainActivity"> 9 10 <Button 11 android:text="string/signup" 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:id="@+id/SignUpButton" android:layout_marginTop="13dp" 15 app:layout_constraintTop_toBottomOf="@+id/guideline" app:layout_constraintStart_toStartOf="parent" 16 android:layout_marginStart="30dp"/> 17 <Button 18 android:text="string/login" 19 android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:id="@+id/LoginButton" android:layout_marginTop="13dp" 22 app:layout_constraintTop_toBottomOf="@+id/guideline" app:layout_constraintEnd_toEndOf="parent" 23 android:layout_marginEnd="30dp"/> 24 <TextView 25 android:text="e_mail" 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:id="@+id/emailLabel" app:layout_constraintTop_toTopOf="parent" 29 android:layout_marginTop="88dp" app:layout_constraintEnd_toStartOf="@+id/emailEditText" 30 android:layout_marginEnd="14dp" app:layout_constraintStart_toStartOf="parent" 31 android:layout_marginStart="40dp" android:labelFor="@+id/emailEditText"/> 32 <TextView 33 android:text="password" 34 android:layout_width="wrap_content" 35 android:layout_height="wrap_content" 36 android:id="@+id/passLabel" android:layout_marginTop="32dp" 37 app:layout_constraintTop_toBottomOf="@+id/emailLabel" app:layout_constraintStart_toStartOf="parent" 38 android:layout_marginStart="40dp" android:labelFor="@+id/passEditText"/> 39 <EditText 40 android:layout_width="wrap_content" 41 android:layout_height="wrap_content" 42 android:inputType="textEmailAddress" 43 android:ems="10" 44 android:id="@+id/emailEditText" 45 app:layout_constraintBottom_toBottomOf="@+id/emailLabel" 46 app:layout_constraintTop_toTopOf="@+id/emailLabel" app:layout_constraintEnd_toEndOf="parent" 47 android:layout_marginEnd="58dp" android:autofillHints=""/> 48 <EditText 49 android:layout_width="wrap_content" 50 android:layout_height="wrap_content" 51 android:inputType="textPassword" 52 android:ems="10" 53 android:id="@+id/passEditText" 54 app:layout_constraintTop_toTopOf="@+id/passLabel" app:layout_constraintBottom_toBottomOf="@+id/passLabel" 55 app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="58dp" android:autofillHints=""/> 56 <androidx.constraintlayout.widget.Guideline android:layout_width="wrap_content" android:layout_height="wrap_content" 57 android:id="@+id/guideline" app:layout_constraintGuide_begin="204dp" 58 android:orientation="horizontal"/> 59</androidx.constraintlayout.widget.ConstraintLayout>
plugins { id 'com.android.application' id 'kotlin-android' } android { compileSdk 31 defaultConfig { applicationId "com.example.myapplication" minSdk 23 targetSdk 31 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 } kotlinOptions { jvmTarget = '1.8' } } dependencies { implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'com.android.support:support-v4:28.0.0' // この行を追加 implementation 'com.android.support:support-media-compat:28.0.0' // この行を追加 implementation 'com.google.firebase:firebase-auth:16.0.1' // この行を追加 implementation 'com.google.firebase:firebase-database:16.0.1' // この行を追加 testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' } apply plugin: 'com.google.gms.google-services'

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2022/01/16 00:06

app/build.gradle の plugins に id 'com.google.gms.google-services' とか忘れてませんか?
soma62jp

2022/01/16 01:37

現象変わらずでした。
hoshi-takanori

2022/01/16 02:00

状況がよく分かりませんが、サインアップは成功しますか? (Android 上で「SignUp 成功」が表示されるだけでなく、Firebase Console 上でユーザーが作られてることもご確認ください。) また、ログインに失敗する際には、何かエラーメッセージは出てませんか? (task.getException() とかでエラーが取得できるのでは。また、 Logcat に何か出てないかもご確認ください。)
soma62jp

2022/01/16 02:25

エラーメッセージを表示させたところ、 InternalFirebaseAuth.FIREBASE_AUTH_API is not available on this device. というメッセージが出ました。
guest

回答1

0

自己解決

hoshi-takanoriさんのご指摘の通り、System image を選ぶ時に Google Play (Pixel2) に対応したものを使う必要がありました。

https://developer.android.com/studio/run/managing-avds?hl=ja https://tommy10344.hatenablog.com/entry/2018/10/25/160041

投稿2022/01/16 03:30

編集2022/01/16 03:39
soma62jp

総合スコア141

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問