我试图将我的应用程序与firebase连接,但我不能 我使用的是Android Studio 2.2.3
我添加了依赖项 build gradle(项目)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
并构建gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "dev.fbase.com.firebaseexample"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-auth:10.0.0'
}
apply plugin: 'com.google.gms.google-services'
我的代码是
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private EditText editTextEmail,editTextPassword;
private Button btnRegister;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressDialog = new ProgressDialog(this);
editTextEmail = (EditText)findViewById(R.id.editTextEmail);
editTextPassword = (EditText)findViewById(R.id.editTextPassword);
btnRegister = (Button) findViewById(R.id.btnRegister);
firebaseAuth = FirebaseAuth.getInstance();
btnRegister.setOnClickListener(this);
}
public void register(){
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
Toast.makeText(this, ""+email+password, Toast.LENGTH_SHORT).show();
if (TextUtils.isEmpty(email)||TextUtils.isEmpty(password))
{
Toast.makeText(MainActivity.this,"fill all the fields",Toast.LENGTH_SHORT).show();
return;
}
progressDialog.setMessage("Registering..");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();
if(task.isSuccessful())
{
progressDialog.dismiss();
Toast.makeText(MainActivity.this,"Registration Success",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this,"Registration Failed",Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onClick(View v) {
if(v==btnRegister)
{
register();
}
}
}
xml布局了 两个文本字段(EditTexts)和 一键 我从教程视频中获得了这段代码 他们成功地执行了这个,但我尝试过显示异常
03-14 13:31:31.585 1054-1772 / system_process V / WindowManager:添加 窗口窗口{f249820 u0 PopupWindow:5e4fee9} at 3 of 8(之后 窗口{d1abaee u0 dev.fbase.com.firebaseexample / dev.fbase.com.firebaseexample.MainActivity}) 03-14 13:31:31.642 2331-2632 / dev.fbase.com.firebaseexample W / EGL_emulation:eglSurfaceAttrib未实现03-14 13:31:31.642 2331-2632 / dev.fbase.com.firebaseexample W / OpenGLRenderer:失败 在表面0xe242b580上设置EGL_SWAP_BEHAVIOR,错误= EGL_SUCCESS 03-14 13:32:00.808 1054-1225 / system_process W / AudioTrack: 客户03-14 13:32:00.846拒绝了AUDIO_OUTPUT_FLAG_FAST 1054-1502 / system_process V / WindowManager:不是基本应用程序:添加窗口 窗口{4bd695 u0 dev.fbase.com.firebaseexample / dev.fbase.com.firebaseexample.MainActivity} 3月8日03-14 13:32:00.852 2331-2619 / dev.fbase.com.firebaseexample W / DynamiteModule:本地模块描述符类 找不到com.google.firebase.auth。 03-14 13:32:00.852 2331-2619 / dev.fbase.com.firebaseexample W / GooglePlayServicesUtil: Google Play商店遗失了。 03-14 13:32:00.911 2331-2632 / dev.fbase.com.firebaseexample W / EGL_emulation: eglSurfaceAttrib未实施03-14 13:32:00.912 2331-2632 / dev.fbase.com.firebaseexample W / OpenGLRenderer:失败 在表面0xe242b720上设置EGL_SWAP_BEHAVIOR,错误= EGL_SUCCESS 03-14 13:32:01.335 2331-2632 / dev.fbase.com.firebaseexample W / EGL_emulation: eglSurfaceAttrib未实现03-14 13:32:01.335 2331-2632 / dev.fbase.com.firebaseexample W / OpenGLRenderer:失败 在表面0xe247da20上设置EGL_SWAP_BEHAVIOR,错误= EGL_SUCCESS 03-14 13:32:01.721 2331-2632 / dev.fbase.com.firebaseexample V / RenderScript: 0xeed9da00启动线程,CPU 4
答案 0 :(得分:2)
stacktrace表示设备中缺少Google Play商店。要使firebase正常运行,您需要拥有一台具有Google Play Services 10或更高版本的设备。 (来自https://firebase.google.com/docs/android/setup)。如果是模拟器,请确保创建包含Google API的模拟器。