我按照教程创建了一个登录/注册,并将其与gradle
连接起来。它不允许我为我的代码添加图像,所以如果有效的话我会粘贴它...
我添加了XML
我为 buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.saiyarram.perfectit"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
ex
clude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.firebase:firebase-core:11.6.2'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.google.firebase:firebase-database:11.6.2'
compile 'com.google.firebase:firebase-crash:11.6.2'
compile 'com.google.firebase:firebase-auth:11.6.2'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
package com.example.saiyarram.perfectit;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button
LogInButton;
private Button RegisterButton;
private EditText UserNameEditText;
private EditText PasswordEditText;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
LogInButton = (Button) findViewById(R.id.LogInButton);
RegisterButton = (Button) findViewById(R.id.RegisterButton);
UserNameEditText = (EditText) findViewById(R.id.UserNameEditText);
PasswordEditText = (EditText) findViewById(R.id.PasswordEditText);
LogInButton.setOnClickListener(this);
RegisterButton.setOnClickListener(this);
}
@Override
public void onClick(View view){
if(view == LogInButton){
//will login the user
}
if(view == RegisterButton){
RegisterUser();
}
}
private void RegisterUser(){
String Email = UserNameEditText.getText().toString().trim();
String Password = PasswordEditText.getText().toString().trim();
if(TextUtils.isEmpty(Email)){
Toast.makeText(this, "Please Enter An Email!", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(Password)){
Toast.makeText(this, "Please Enter A Password!", Toast.LENGTH_SHORT).show();
return;
}
firebaseAuth.createUserWithEmailAndPassword(Email,Password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Registered Successfully", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this,"Could not register",Toast.LENGTH_SHORT).show() ;
}
}
});
System.out.println("Stuck here1");
}
}
添加了互联网选项
当我运行应用程序时运行正常,当我输入用户名和密码并单击注册按钮时,它会显示
&#34;无法发布...&#34;
{{1}}