I'm trying to implement Firebase in my Android app but I can not get it to work. I tell you the steps that I have followed
build.grade
classpath 'com.google.gms:google-services:4.1.0' // google-services plugin
app / build.grade
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.4'
}
//Esta linea esta fuera de las dependencies
apply plugin: 'com.google.gms.google-services'
Once this is done I have made a sync now and it has not given me any problem. But at the time of making a record I get an error and it tells me that the user could not be registered and I do not know how to do it because I have already tried doing so and following the steps of the firebase from the android studio itself but the lines that I added the assistant that to the gradle does not compile. I leave here the class code .java
public class MainActivity extends AppCompatActivity implements
View.OnClickListener {
//defining view objects
private EditText TextEmail;
private EditText TextPassword;
private Button btnRegistrar;
private ProgressDialog progressDialog;
//Declaramos un objeto firebaseAuth
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//inicializamos el objeto firebaseAuth
firebaseAuth = FirebaseAuth.getInstance();
//Referenciamos los views
TextEmail = (EditText) findViewById(R.id.TxtEmail);
TextPassword = (EditText) findViewById(R.id.TxtPassword);
btnRegistrar = (Button) findViewById(R.id.botonRegistrar);
progressDialog = new ProgressDialog(this);
//attaching listener to button
btnRegistrar.setOnClickListener(this);
}
private void registrarUsuario(){
//Obtenemos el email y la contraseña desde las cajas de texto
String email = TextEmail.getText().toString().trim();
String password = TextPassword.getText().toString().trim();
//Verificamos que las cajas de texto no esten vacías
if(TextUtils.isEmpty(email)){
Toast.makeText(this,"Se debe ingresar un email",Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this,"Falta ingresar la contraseña",Toast.LENGTH_LONG).show();
return;
}
progressDialog.setMessage("Realizando registro en linea...");
progressDialog.show();
//creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
//checking if success
if(task.isSuccessful()){
Toast.makeText(MainActivity.this,"Se ha registrado el usuario con el email: "+ TextEmail.getText(),Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this,"No se pudo registrar el usuario ",Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
});
}
@Override
public void onClick(View view) {
//Invocamos al método:
registrarUsuario();
}
I also add the files of the gradle in case I got it there at the time of introducing the services but I do not know why I followed the steps that come in the goolge documentation.
build.grade
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:4.1.0' // google-services plugin
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app / build.grade
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.josemanuu.intento2"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.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'
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'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.4'
}
apply plugin: 'com.google.gms.google-services'
Thanks for your help:)