проблемы с подключением к firebase - PullRequest
0 голосов
/ 04 февраля 2019

Я создал приложение с коротким заставкой для отображения изображения логотипа, а затем со страницей входа в систему после онлайн-уроков.Я подключил FireBase, где я сохранил один адрес электронной почты и пароль, который можно использовать.Однако недавно я добавил функциональность для правильной работы входа в систему, и теперь он застревает на заставке, говоря, что он недавно перестал работать.

Я понимаю, что я, вероятно, использовал неправильную версию чего-то, но не знаю, как найти, где я использовал неправильную версию, чтобы исправить ее

Все, что я пока хочу от этого приложения, этодля корректной работы заставки вы перейдете на страницу входа в систему и сможете использовать адрес электронной почты, который я настроил для использования.

эта ошибка отображается на этом экране, однако я не уверен, где у меня естьиспользовалась неправильная версия

Все библиотеки com.android.support должны использовать одну и ту же спецификацию версии (смешивание версий может привести к сбоям во время выполнения).Найдено версии 28.0.0, 26.1.0.Примеры включают com.android.support:animated-vector-drawable:28.0.0 и com.android.support:support-media-compat:26.1.0 less ... (Ctrl + F1) Информация о проверке: существует несколько комбинацийбиблиотеки или инструменты и библиотеки, которые несовместимы или могут привести к ошибкам.Одной из таких несовместимостей является компиляция с версией библиотек поддержки Android, которая не является последней версией (или, в частности, версией ниже, чем ваша targetSdkVersion).Идентификатор проблемы: GradleCompatible "

Вот логин

public class LoginActivity extends AppCompatActivity {
//variables
    private EditText loginEmailText;
    private EditText loginPassText;
    private Button loginBtn;
     private Button loginRegBtn;

     private FirebaseAuth nAuth;

     private ProgressBar loginProgress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        nAuth = FirebaseAuth.getInstance();

        loginEmailText = (EditText) findViewById(R.id.login_email);
        loginPassText = (EditText) findViewById(R.id.login_password);
        loginBtn = (Button) findViewById(R.id.login_btn);
        loginRegBtn = (Button) findViewById(R.id.login_reg_btn);
        loginProgress = (ProgressBar) findViewById(R.id.login_progress);


        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                loginProgress.setVisibility(View.VISIBLE);
                String loginEmail = loginEmailText.getText().toString();
                String loginPass = loginPassText.getText().toString();

                if (TextUtils.isEmpty(loginEmail) && !TextUtils.isEmpty(loginPass)) {
                    loginProgress.setVisibility(View.VISIBLE);

                    nAuth.signInWithEmailAndPassword(loginEmail, loginPass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {

                                sendToMain();
                            } else {
                                String errorMessage = task.getException().getMessage();
                                Toast.makeText(LoginActivity.this, "Error:" + errorMessage, Toast.LENGTH_SHORT).show();

                            }
                            loginProgress.setVisibility(View.INVISIBLE);
                        }
                    });


                }

            }
        });
    }



    @Override
    protected void onStart() {
        super.onStart();
//this is to see if user logged in or not
        FirebaseUser currentUser = nAuth.getCurrentUser();

        if(currentUser!=null){
            sendToMain();
        }


    }

    private void sendToMain() {
        Intent mainIntent = new Intent(LoginActivity.this,MainActivity.class);
        startActivity(mainIntent);
        finish();
    }
}

Вот логин xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    tools:context=".LoginActivity">

    <Button
        android:id="@+id/login_reg_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="@string/login_reg_btn_text"
        android:textAllCaps="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/login_btn" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="0dp"
        android:layout_height="452dp"
        android:contentDescription="@string/App_logo"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/logo"

        tools:layout_editor_absoluteX="0dp" />

    <EditText
        android:id="@+id/login_email"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:autofillHints=""
        android:ems="10"
        android:hint="@string/Email_hint"
        android:inputType="textEmailAddress"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView2" />

    <EditText
        android:id="@+id/login_password"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:ems="10"
        android:hint="@string/Pass_hint"
        android:importantForAutofill="no"
        android:inputType="textPassword"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/login_email" />

    <Button
        android:id="@+id/login_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="@string/Login_btn_text"
        android:textAllCaps="false"
        android:textColorLink="@color/colorPrimaryDark"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/login_password" />

    <ProgressBar
        android:id="@+id/login_progress"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>


Вот основной вид деятельности

package com.example.splashscreentest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent intent = new Intent(MainActivity.this, LoginActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onStart() {
        super.onStart();
        FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
        if (currentUser == null){
            Intent loginIntent = new Intent(MainActivity.this,LoginActivity.class);
            startActivity(loginIntent);
            finish();
        }
    }
}

вот основная деятельность xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="401dp"
        android:layout_height="36dp"
        android:text="TextView"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="285dp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="407dp"
        android:layout_height="47dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="Sign Up"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.666"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteY="442dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="407dp"
        android:layout_height="47dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="Login"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteY="381dp" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="401dp"
        android:layout_height="36dp"
        android:text="TextView"
        tools:layout_editor_absoluteX="2dp"
        tools:layout_editor_absoluteY="230dp" />
</android.support.constraint.ConstraintLayout>

вот заставка

package com.example.splashscreentest;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashScreen extends AppCompatActivity {



         static int SPLASH_TIME_OUT = 3000;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash_screen);

            new Handler().postDelayed(new Runnable() {


                @Override
                public void run() {
                    // This method will be executed once the timer is over
                    // Start your app main activity
                    Intent i = new Intent(SplashScreen.this, MainActivity.class);
                    startActivity(i);

                    // close this activity
                    finish();
                }
            }, SPLASH_TIME_OUT);
        }
    }

вот заставка xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/app_name"
        app:srcCompat="@drawable/logo" />





</RelativeLayout>



вот манифест андроида


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.splashscreentest">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
    </application>

</manifest>

это один из файлов Gradle с ошибкой #

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

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.splashscreentest"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Ответы [ 2 ]

0 голосов
/ 05 февраля 2019

Инструменты-Firebase-облачные сообщения, настройка Firebase Cloud Messaging, шаги будут работать гладко, если вы будете делать один за другим.

https://firebase.google.com/docs/android/setup#available_libraries

0 голосов
/ 04 февраля 2019

Скачали ли вы и json-файл Google-Services в папку вашего приложения?

Вам также нужно будет применить его к файлу gradle внизу, я не вижу его в вашем:

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

Как и то, что @ cricket_007 сказал, вам также необходимо добавить implementation 'com.google.firebase:firebase-auth:16.1.0' в файл Gradle.

...