从android手机上的android studio运行后,应用只会打开和关闭

从android手机上的android studio运行后,应用只会打开和关闭,第1张

概述从androidstudio上的androidstudio运行后,应用只会打开关闭.还显示以下警告:应用gradle文件必须依赖com.google.firebase:firebase-core,Firebase服务才能正常工作.我尝试从教程制作应用程序,该应用程序已成功编译,但是在Android手机上运行时只能打开和关闭.的build.gradle

从android studio上的androID studio运行后,应用只会打开和关闭.

还显示以下警告:

应用gradle文件必须依赖com.Google.firebase:firebase-core,Firebase服务才能正常工作.

我尝试从教程制作应用程序,该应用程序已成功编译,但是在Android手机上运行时只能打开和关闭.

的build.gradle

 apply plugin: 'com.androID.application'androID {compileSdkVersion 27defaultConfig {    applicationID "com.example.hp.chatapp"    minSdkVersion 16    targetSdkVersion 27versionCode 1versionname "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:27.1.1'implementation 'com.androID.support.constraint:constraint-layout:1.1.2'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'//add libraryimplementation 'com.androID.support:design:27.1.1'implementation 'com.firebaseui:firebase-ui-database:3.2.2'implementation 'com.Google.firebase:firebase-auth:10.2.1'implementation 'com.firebaseui:firebase-ui-auth:3.2.2'implementation "com.Google.androID.gms:play-services-gcm:10.2.1"}apply plugin: 'com.Google.gms.Google-services'

的build.gradle

buildscript {repositorIEs {    Google()    jcenter()}dependencIEs {    classpath 'com.androID.tools.build:gradle:3.1.3'    classpath 'com.Google.gms:Google-services:4.0.2'    // NOTE: Do not place your application dependencIEs here; they belong    // in the indivIDual module build.gradle files}

}

主要活动是

public class MainActivity extends AppCompatActivity {private static int SIGN_IN_REQUEST_CODE= 1;private Firebaselistadapter<ChatMessage> adapter;relativeLayout activity_main;floatingActionbutton fab;@OverrIDepublic boolean onoptionsItemSelected(MenuItem item) {    if(item.getItemID()==R.ID.menu_sign_out){        AuthUI.getInstance().signOut(this).addOnCompleteListener(new  OnCompleteListener<VoID>() {            @OverrIDe            public voID onComplete(@NonNull Task<VoID> task) {              Snackbar.make(activity_main,"You have been signed out.",Snackbar.LENGTH_SHORT).show();              finish();            }        });    }    return true;}@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {    getMenuInflater().inflate(R.menu.main_menu,menu);    return true;}@OverrIDeprotected voID onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);    if(requestCode==RESulT_OK){        Snackbar.make(activity_main,"Successfully signed in.Welcome !",Snackbar.LENGTH_SHORT).show();        displayChatMessage();    }    else {        Snackbar.make(activity_main,"We Couldn't sign you in.Please try again later",Snackbar.LENGTH_SHORT).show();        finish();    }}@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    activity_main=(relativeLayout)findVIEwByID(R.ID.activity_main);    fab=(floatingActionbutton)findVIEwByID(R.ID.fab);    fab.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw vIEw) {            EditText input= (EditText)findVIEwByID(R.ID.input);            FirebaseDatabase.getInstance().getReference().push().setValue(new ChatMessage(input.getText().toString(),FirebaseAuth.getInstance().getCurrentUser().getEmail()));            input.setText("");        }    });//check if not sign in then navigate signin pageif(FirebaseAuth.getInstance().getCurrentUser()==null){    startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(),SIGN_IN_REQUEST_CODE);  }  else {    Snackbar.make(activity_main,"Welcome "+FirebaseAuth.getInstance().getCurrentUser().getEmail(),Snackbar.LENGTH_SHORT).show();   }//load content    displayChatMessage();}private voID displayChatMessage() {    ListVIEw listofMessage=(ListVIEw)findVIEwByID(R.ID.List_of_message);    //Suppose you want to retrIEve "chats" in your Firebase DB:    query query =  FirebaseDatabase.getInstance().getReference().child("chats");//The error saID the constructor expected FirebaseListOptions - here you create them:    FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()            .setquery(query, ChatMessage.class)            .setLayout(androID.R.layout.simple_List_item_1)            .build();    //Finally you pass them to the constructor here:    adapter = new Firebaselistadapter<ChatMessage>(options){        @OverrIDe        protected voID populateVIEw(VIEw v, ChatMessage model, int position) {            // Get references to the vIEws of message.xml            TextVIEw messageText = (TextVIEw)v.findVIEwByID(R.ID.message_text);            TextVIEw messageTime = (TextVIEw)v.findVIEwByID(R.ID.message_time);            TextVIEw messageUser=(TextVIEw)findVIEwByID(R.ID.message_user);            messageText.setText(model.getMessageText());            messageUser.setText(model.getMessageUser());            messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",model.getMessageTime()));        }    };listofMessage.setAdapter(adapter);}}

EDITED

logcat记录错误

08-03 02:00:47.736 3199-3199/com.example.hp.chatapp E/HAL: PATH3 /odm/lib64/hw/gralloc.qcom.soPATH2 /vendor/lib64/hw/gralloc.qcom.soPATH1 /system/lib64/hw/gralloc.qcom.soPATH3 /odm/lib64/hw/gralloc.msm8953.so08-03 02:00:47.737 3199-3199/com.example.hp.chatapp E/HAL: PATH2 /vendor/lib64/hw/gralloc.msm8953.soPATH1 /system/lib64/hw/gralloc.msm8953.so

解决方法:

尝试在AndroID Studio中使用Firebase工具.选择要集成的服务,然后按照分步说明进行 *** 作.

总结

以上是内存溢出为你收集整理的从android手机上的android studio运行后,应用只会打开和关闭全部内容,希望文章能够帮你解决从android手机上的android studio运行后,应用只会打开和关闭所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1092920.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存