我的应用发布版本中的错误和崩溃
Bugs and Crashes on my App Release Version
我的应用程序发布版本有很大问题。 (https://play.google.com/store/apps/details?id=com.conta.ftof
如果可以,请尝试下载它以帮助我)
在调试版本中,一切正常,但在发布版本中,只要我使用 phone 号码验证 firebase 或只是验证并单击回收器视图按钮,应用程序就会崩溃......我最近添加了 sha 键 -1和 sha-256 到 firebase 项目,我添加了新的 json 文件,因为身份验证不起作用,现在身份验证工作得很好但是一旦你通过身份验证,正如我已经说过的,应用程序就会崩溃.不知道是不是我1周前在contactactivity里加的google广告...奇怪的是debug版本功能齐全...我把代码留给你...
enter image description here
美眉LogCat
--------- beginning of crash
2020-10-16 19:11:58.221 22176-22176/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.conta.ftof, PID: 22176
c.e.c.m.d: No properties to serialize found on class c.b.a.d
at c.e.c.m.x.z0.o.a$a.<init>(:11)
at c.e.c.m.x.z0.o.a.e(Unknown Source:12)
at c.e.c.m.x.z0.o.a.b(:4)
at c.c.a.b.b.a(:5)
at c.c.a.a.a.a(:3)
at com.firebase.ui.database.FirebaseRecyclerAdapter.p(:2)
at androidx.recyclerview.widget.RecyclerView$g.q(Unknown Source:0)
at androidx.recyclerview.widget.RecyclerView$v.k(:80)
at androidx.recyclerview.widget.LinearLayoutManager$c.c(:3)
at androidx.recyclerview.widget.LinearLayoutManager.t1(Unknown Source:0)
at androidx.recyclerview.widget.LinearLayoutManager.e1(:2)
at androidx.recyclerview.widget.LinearLayoutManager.s0(:22)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(Unknown Source:38)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(Unknown Source:37)
at androidx.recyclerview.widget.RecyclerView.onLayout(Unknown Source:5)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:902)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3037)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2545)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1636)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7946)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)
at android.view.Choreographer.doCallbacks(Choreographer.java:893)
at android.view.Choreographer.doFrame(Choreographer.java:812)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
2020-10-16 19:11:58.227 1272-2391/? E/ActivityManager: The same pid with last one, do not add dropbox and clear mLastCrashedPid. mLastAppCrashedPid==22176
联系人活动:
//[...import some libraries...]
public class ContactsActivity extends AppCompatActivity {
BottomNavigationView navView;
RecyclerView myContactsList;
ImageView findPeopleBtn;
private DatabaseReference contactsRef, usersRef;
private FirebaseAuth mAuth;
private String currentUserId;
private String userName = "", profileImage="";
private String calledBy = "";
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts);
//ads
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
//ads
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3400243939195187/7974459299");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAuth = FirebaseAuth.getInstance();
currentUserId = mAuth.getCurrentUser().getUid();
contactsRef = FirebaseDatabase.getInstance().getReference().child("Contacts");
usersRef = FirebaseDatabase.getInstance().getReference().child("Users");
navView = findViewById(R.id.nav_view);
navView.setOnNavigationItemSelectedListener(navigationItemSelectedListener);
findPeopleBtn = findViewById(R.id.find_people_btn);
myContactsList = findViewById(R.id.contact_list);
myContactsList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
findPeopleBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent findpeopleIntent = new Intent(ContactsActivity.this, FindPeopleActivity.class);
startActivity(findpeopleIntent);
}
});
}
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.navigation_home:
Intent mainIntent = new Intent(ContactsActivity.this, ContactsActivity.class);
startActivity(mainIntent);
break;
case R.id.navigation_settings:
Intent settingsIntent = new Intent(ContactsActivity.this,SettingsActivity.class);
startActivity(settingsIntent);
break;
case R.id.navigation_notifications:
Intent notificationsIntent = new Intent(ContactsActivity.this,NotificationsActivity.class);
startActivity(notificationsIntent);
break;
case R.id.navigation_logout:
FirebaseAuth.getInstance().signOut();
Intent logoutIntent = new Intent(ContactsActivity.this,RegistrationActivity.class);
startActivity(logoutIntent);
finish();
break;
case R.id.navigation_donate:
Intent donateIntent = new Intent(ContactsActivity.this,donate.class);
startActivity(donateIntent);
finish();
break;
}
return true;
}
};
@Override
protected void onStart() {
super.onStart();
checkForReceivingCall();
validateUser();
FirebaseRecyclerOptions<Contacts> options
= new FirebaseRecyclerOptions.Builder<Contacts>()
.setQuery(contactsRef.child(currentUserId), Contacts.class)
.build();
FirebaseRecyclerAdapter<Contacts, ContactsViewHolder> firebaseRecyclerAdapter
=new FirebaseRecyclerAdapter<Contacts, ContactsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final ContactsViewHolder holder, int i, @NonNull Contacts contacts) {
final String listUserId = getRef(i).getKey();
usersRef.child(listUserId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
userName = dataSnapshot.child("name").getValue().toString();
profileImage = dataSnapshot.child("image").getValue().toString();
holder.userNameTxt.setText(userName);
Picasso.get().load(profileImage).into(holder.profileImageView);
holder.callBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent callingIntent = new Intent(ContactsActivity.this, CallingActivity.class);
callingIntent.putExtra("visit_user_id", listUserId);
startActivity(callingIntent);
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@NonNull
@Override
public ContactsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.contact_design,parent,false);
ContactsViewHolder viewHolder = new ContactsViewHolder(view);
return viewHolder;
}
};
myContactsList.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
public static class ContactsViewHolder extends RecyclerView.ViewHolder{
TextView userNameTxt;
Button callBtn;
ImageView profileImageView;
public ContactsViewHolder(@NonNull View itemView) {
super(itemView);
userNameTxt = itemView.findViewById(R.id.name_contact);
callBtn = itemView.findViewById(R.id.call_btn);
profileImageView = itemView.findViewById(R.id.image_contact);
}
}
private void validateUser() {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
reference.child("Users").child(currentUserId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Intent settingIntent = new Intent(ContactsActivity.this, SettingsActivity.class);
startActivity(settingIntent);
finish();
}
});
}
private void checkForReceivingCall() {
usersRef.child(currentUserId)
.child("Ringing")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild("ringing")){
calledBy = dataSnapshot.child("ringing").getValue().toString();
Intent callingIntent = new Intent(ContactsActivity.this, CallingActivity.class);
callingIntent.putExtra("visit_user_id", calledBy);
startActivity(callingIntent);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
构建 gradle :app
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
defaultConfig {
applicationId "com.conta.ftof"
minSdkVersion 21
targetSdkVersion 29
versionCode 3
versionName "1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-database:19.3.0'
implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
implementation 'com.hbb20:ccp:2.1.9'
implementation 'pub.devrel:easypermissions:0.4.0'
implementation 'com.android.support:percent:29.0.0'
implementation 'com.google.android.gms:play-services-ads:19.4.0'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.opentok.android:opentok-android-sdk:2.15.3'
implementation 'pub.devrel:easypermissions:0.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:17.4.3'
}
构建gradle项目
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com'}
maven { url 'https://tokbox.bintray.com/maven'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
通话活动
package com.conta.ftof;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseNetworkException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.hbb20.CountryCodePicker;
import java.util.concurrent.TimeUnit;
public class RegistrationActivity extends AppCompatActivity {
private CountryCodePicker ccp;
private EditText phoneText;
private EditText codeText;
private Button continueAndNextBtn;
private String checker = "", phoneNumber = "";
private RelativeLayout relativeLayout;
private static final String TAG = "RegistrationActivity";
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private FirebaseAuth mAuth;
private String mVerificationid;
private PhoneAuthProvider.ForceResendingToken mResendToken;
private ProgressDialog loadingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
mAuth = FirebaseAuth.getInstance();
loadingBar = new ProgressDialog(this );
phoneText = findViewById(R.id.phoneText);
codeText = findViewById(R.id.codeText);
continueAndNextBtn = findViewById(R.id.continueNextButton);
relativeLayout = findViewById(R.id.PhoneAuth);
ccp = (CountryCodePicker) findViewById(R.id.ccp); //trova il country code (in it è +39) dall'id del telefono android
ccp.registerCarrierNumberEditText(phoneText);
continueAndNextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { //View v = View view
if(continueAndNextBtn.getText().equals("Submit") || checker.equals("Codice Inviato")){
String verificationCode = codeText.getText().toString();
if (verificationCode.equals("")){
Toast.makeText(RegistrationActivity.this, "Perfavore scrivi il tuo codice di verifica", Toast.LENGTH_SHORT).show();
}
else{
loadingBar.setTitle("Codice Di Verifica....");
loadingBar.setMessage("Perfavore, attendi la verifica....");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationid, verificationCode);
signInWithPhoneAuthCredential(credential);
}
}
else{
phoneNumber = ccp.getFullNumberWithPlus();
if(!phoneNumber.equals("")){
loadingBar.setTitle("Verifica del numero....");
loadingBar.setMessage("Perfavore, attendi la verifica....");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber,
60,
TimeUnit.SECONDS,
RegistrationActivity.this,
mCallbacks);
}
else{
Toast.makeText(RegistrationActivity.this, "Perfavore, controlla il tuo numero di telefono...", Toast.LENGTH_SHORT).show();
}
}
} //da tenere d'occhio
});
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(RegistrationActivity.this, "Numero inserito non valido...", Toast.LENGTH_SHORT).show();
}
else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(RegistrationActivity.this, "Troppe richieste per questo numero di telefono, riprova tra 24h", Toast.LENGTH_SHORT).show();
}
else if (e instanceof FirebaseNetworkException){
Toast.makeText(RegistrationActivity.this, "Errore di rete...", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(RegistrationActivity.this, "Errore sconosciuto", Toast.LENGTH_SHORT).show();
}
Log.e(TAG, "err : " + e);
loadingBar.dismiss();
// Toast.makeText(RegistrationActivity.this, "Numero inserito non valido...", Toast.LENGTH_SHORT).show();
relativeLayout.setVisibility(View.VISIBLE);
continueAndNextBtn.setText("Continue"); //Continue
codeText.setVisibility(View.GONE);
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
mVerificationid = s; //Id
mResendToken = forceResendingToken;
relativeLayout.setVisibility(View.GONE);
checker = "Codice Inviato";
continueAndNextBtn.setText("Invia");
codeText.setVisibility(View.VISIBLE);
loadingBar.dismiss();
Toast.makeText(RegistrationActivity.this, "Il codice è stato mandato.....", Toast.LENGTH_SHORT).show();
}
};
}
@Override
protected void onStart() {
super.onStart();
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if(firebaseUser != null){
Intent homeIntent = new Intent(RegistrationActivity.this, ContactsActivity.class);
startActivity(homeIntent);
finish();
}
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
loadingBar.dismiss();
sendUserToMainActivity();
Toast.makeText(RegistrationActivity.this, "Congratulazioni...", Toast.LENGTH_SHORT).show();
} else {
// Sign in failed, display a message and update the UI
loadingBar.dismiss();
String e = task.getException().toString();
Toast.makeText(RegistrationActivity.this, "Errore "+e, Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendUserToMainActivity(){
Intent intent = new Intent(RegistrationActivity.this, ContactsActivity.class);
startActivity(intent);
finish();
}
}
如果您是初学者,那么我建议您在 build.gradle 中禁用 minifyEnabled
。基本上 proguard
混淆了代码,你可能不会在 proguard
规则
中转义你的模型文件
android {
...
buildTypes {
release {
minifyEnabled false // disable proguard
...
}
}
}
[更新]:这是在 progaurd 中转义文件的方法
在您的 proguard-android-optimize.txt
文件中执行以下操作
如果您的所有模型都在同一文件夹中,则:
-keep public class com.myapp.models.** {
public protected private *;
}
否则您可以使用以下方式跳过文件:
-keep public class com.myapp.models.MyModel {
public protected private *;
}
我的应用程序发布版本有很大问题。 (https://play.google.com/store/apps/details?id=com.conta.ftof 如果可以,请尝试下载它以帮助我) 在调试版本中,一切正常,但在发布版本中,只要我使用 phone 号码验证 firebase 或只是验证并单击回收器视图按钮,应用程序就会崩溃......我最近添加了 sha 键 -1和 sha-256 到 firebase 项目,我添加了新的 json 文件,因为身份验证不起作用,现在身份验证工作得很好但是一旦你通过身份验证,正如我已经说过的,应用程序就会崩溃.不知道是不是我1周前在contactactivity里加的google广告...奇怪的是debug版本功能齐全...我把代码留给你...
enter image description here
美眉LogCat
--------- beginning of crash
2020-10-16 19:11:58.221 22176-22176/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.conta.ftof, PID: 22176
c.e.c.m.d: No properties to serialize found on class c.b.a.d
at c.e.c.m.x.z0.o.a$a.<init>(:11)
at c.e.c.m.x.z0.o.a.e(Unknown Source:12)
at c.e.c.m.x.z0.o.a.b(:4)
at c.c.a.b.b.a(:5)
at c.c.a.a.a.a(:3)
at com.firebase.ui.database.FirebaseRecyclerAdapter.p(:2)
at androidx.recyclerview.widget.RecyclerView$g.q(Unknown Source:0)
at androidx.recyclerview.widget.RecyclerView$v.k(:80)
at androidx.recyclerview.widget.LinearLayoutManager$c.c(:3)
at androidx.recyclerview.widget.LinearLayoutManager.t1(Unknown Source:0)
at androidx.recyclerview.widget.LinearLayoutManager.e1(:2)
at androidx.recyclerview.widget.LinearLayoutManager.s0(:22)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(Unknown Source:38)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(Unknown Source:37)
at androidx.recyclerview.widget.RecyclerView.onLayout(Unknown Source:5)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:902)
at android.view.View.layout(View.java:20948)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3037)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2545)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1636)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7946)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)
at android.view.Choreographer.doCallbacks(Choreographer.java:893)
at android.view.Choreographer.doFrame(Choreographer.java:812)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
2020-10-16 19:11:58.227 1272-2391/? E/ActivityManager: The same pid with last one, do not add dropbox and clear mLastCrashedPid. mLastAppCrashedPid==22176
联系人活动:
//[...import some libraries...]
public class ContactsActivity extends AppCompatActivity {
BottomNavigationView navView;
RecyclerView myContactsList;
ImageView findPeopleBtn;
private DatabaseReference contactsRef, usersRef;
private FirebaseAuth mAuth;
private String currentUserId;
private String userName = "", profileImage="";
private String calledBy = "";
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts);
//ads
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
//ads
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3400243939195187/7974459299");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAuth = FirebaseAuth.getInstance();
currentUserId = mAuth.getCurrentUser().getUid();
contactsRef = FirebaseDatabase.getInstance().getReference().child("Contacts");
usersRef = FirebaseDatabase.getInstance().getReference().child("Users");
navView = findViewById(R.id.nav_view);
navView.setOnNavigationItemSelectedListener(navigationItemSelectedListener);
findPeopleBtn = findViewById(R.id.find_people_btn);
myContactsList = findViewById(R.id.contact_list);
myContactsList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
findPeopleBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent findpeopleIntent = new Intent(ContactsActivity.this, FindPeopleActivity.class);
startActivity(findpeopleIntent);
}
});
}
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.navigation_home:
Intent mainIntent = new Intent(ContactsActivity.this, ContactsActivity.class);
startActivity(mainIntent);
break;
case R.id.navigation_settings:
Intent settingsIntent = new Intent(ContactsActivity.this,SettingsActivity.class);
startActivity(settingsIntent);
break;
case R.id.navigation_notifications:
Intent notificationsIntent = new Intent(ContactsActivity.this,NotificationsActivity.class);
startActivity(notificationsIntent);
break;
case R.id.navigation_logout:
FirebaseAuth.getInstance().signOut();
Intent logoutIntent = new Intent(ContactsActivity.this,RegistrationActivity.class);
startActivity(logoutIntent);
finish();
break;
case R.id.navigation_donate:
Intent donateIntent = new Intent(ContactsActivity.this,donate.class);
startActivity(donateIntent);
finish();
break;
}
return true;
}
};
@Override
protected void onStart() {
super.onStart();
checkForReceivingCall();
validateUser();
FirebaseRecyclerOptions<Contacts> options
= new FirebaseRecyclerOptions.Builder<Contacts>()
.setQuery(contactsRef.child(currentUserId), Contacts.class)
.build();
FirebaseRecyclerAdapter<Contacts, ContactsViewHolder> firebaseRecyclerAdapter
=new FirebaseRecyclerAdapter<Contacts, ContactsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final ContactsViewHolder holder, int i, @NonNull Contacts contacts) {
final String listUserId = getRef(i).getKey();
usersRef.child(listUserId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
userName = dataSnapshot.child("name").getValue().toString();
profileImage = dataSnapshot.child("image").getValue().toString();
holder.userNameTxt.setText(userName);
Picasso.get().load(profileImage).into(holder.profileImageView);
holder.callBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent callingIntent = new Intent(ContactsActivity.this, CallingActivity.class);
callingIntent.putExtra("visit_user_id", listUserId);
startActivity(callingIntent);
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@NonNull
@Override
public ContactsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.contact_design,parent,false);
ContactsViewHolder viewHolder = new ContactsViewHolder(view);
return viewHolder;
}
};
myContactsList.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
public static class ContactsViewHolder extends RecyclerView.ViewHolder{
TextView userNameTxt;
Button callBtn;
ImageView profileImageView;
public ContactsViewHolder(@NonNull View itemView) {
super(itemView);
userNameTxt = itemView.findViewById(R.id.name_contact);
callBtn = itemView.findViewById(R.id.call_btn);
profileImageView = itemView.findViewById(R.id.image_contact);
}
}
private void validateUser() {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
reference.child("Users").child(currentUserId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Intent settingIntent = new Intent(ContactsActivity.this, SettingsActivity.class);
startActivity(settingIntent);
finish();
}
});
}
private void checkForReceivingCall() {
usersRef.child(currentUserId)
.child("Ringing")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild("ringing")){
calledBy = dataSnapshot.child("ringing").getValue().toString();
Intent callingIntent = new Intent(ContactsActivity.this, CallingActivity.class);
callingIntent.putExtra("visit_user_id", calledBy);
startActivity(callingIntent);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
构建 gradle :app
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
defaultConfig {
applicationId "com.conta.ftof"
minSdkVersion 21
targetSdkVersion 29
versionCode 3
versionName "1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-database:19.3.0'
implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'
implementation 'com.hbb20:ccp:2.1.9'
implementation 'pub.devrel:easypermissions:0.4.0'
implementation 'com.android.support:percent:29.0.0'
implementation 'com.google.android.gms:play-services-ads:19.4.0'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.opentok.android:opentok-android-sdk:2.15.3'
implementation 'pub.devrel:easypermissions:0.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:17.4.3'
}
构建gradle项目
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com'}
maven { url 'https://tokbox.bintray.com/maven'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
通话活动
package com.conta.ftof;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseNetworkException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.hbb20.CountryCodePicker;
import java.util.concurrent.TimeUnit;
public class RegistrationActivity extends AppCompatActivity {
private CountryCodePicker ccp;
private EditText phoneText;
private EditText codeText;
private Button continueAndNextBtn;
private String checker = "", phoneNumber = "";
private RelativeLayout relativeLayout;
private static final String TAG = "RegistrationActivity";
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private FirebaseAuth mAuth;
private String mVerificationid;
private PhoneAuthProvider.ForceResendingToken mResendToken;
private ProgressDialog loadingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
mAuth = FirebaseAuth.getInstance();
loadingBar = new ProgressDialog(this );
phoneText = findViewById(R.id.phoneText);
codeText = findViewById(R.id.codeText);
continueAndNextBtn = findViewById(R.id.continueNextButton);
relativeLayout = findViewById(R.id.PhoneAuth);
ccp = (CountryCodePicker) findViewById(R.id.ccp); //trova il country code (in it è +39) dall'id del telefono android
ccp.registerCarrierNumberEditText(phoneText);
continueAndNextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { //View v = View view
if(continueAndNextBtn.getText().equals("Submit") || checker.equals("Codice Inviato")){
String verificationCode = codeText.getText().toString();
if (verificationCode.equals("")){
Toast.makeText(RegistrationActivity.this, "Perfavore scrivi il tuo codice di verifica", Toast.LENGTH_SHORT).show();
}
else{
loadingBar.setTitle("Codice Di Verifica....");
loadingBar.setMessage("Perfavore, attendi la verifica....");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationid, verificationCode);
signInWithPhoneAuthCredential(credential);
}
}
else{
phoneNumber = ccp.getFullNumberWithPlus();
if(!phoneNumber.equals("")){
loadingBar.setTitle("Verifica del numero....");
loadingBar.setMessage("Perfavore, attendi la verifica....");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber,
60,
TimeUnit.SECONDS,
RegistrationActivity.this,
mCallbacks);
}
else{
Toast.makeText(RegistrationActivity.this, "Perfavore, controlla il tuo numero di telefono...", Toast.LENGTH_SHORT).show();
}
}
} //da tenere d'occhio
});
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(RegistrationActivity.this, "Numero inserito non valido...", Toast.LENGTH_SHORT).show();
}
else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(RegistrationActivity.this, "Troppe richieste per questo numero di telefono, riprova tra 24h", Toast.LENGTH_SHORT).show();
}
else if (e instanceof FirebaseNetworkException){
Toast.makeText(RegistrationActivity.this, "Errore di rete...", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(RegistrationActivity.this, "Errore sconosciuto", Toast.LENGTH_SHORT).show();
}
Log.e(TAG, "err : " + e);
loadingBar.dismiss();
// Toast.makeText(RegistrationActivity.this, "Numero inserito non valido...", Toast.LENGTH_SHORT).show();
relativeLayout.setVisibility(View.VISIBLE);
continueAndNextBtn.setText("Continue"); //Continue
codeText.setVisibility(View.GONE);
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
mVerificationid = s; //Id
mResendToken = forceResendingToken;
relativeLayout.setVisibility(View.GONE);
checker = "Codice Inviato";
continueAndNextBtn.setText("Invia");
codeText.setVisibility(View.VISIBLE);
loadingBar.dismiss();
Toast.makeText(RegistrationActivity.this, "Il codice è stato mandato.....", Toast.LENGTH_SHORT).show();
}
};
}
@Override
protected void onStart() {
super.onStart();
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if(firebaseUser != null){
Intent homeIntent = new Intent(RegistrationActivity.this, ContactsActivity.class);
startActivity(homeIntent);
finish();
}
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
loadingBar.dismiss();
sendUserToMainActivity();
Toast.makeText(RegistrationActivity.this, "Congratulazioni...", Toast.LENGTH_SHORT).show();
} else {
// Sign in failed, display a message and update the UI
loadingBar.dismiss();
String e = task.getException().toString();
Toast.makeText(RegistrationActivity.this, "Errore "+e, Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendUserToMainActivity(){
Intent intent = new Intent(RegistrationActivity.this, ContactsActivity.class);
startActivity(intent);
finish();
}
}
如果您是初学者,那么我建议您在 build.gradle 中禁用 minifyEnabled
。基本上 proguard
混淆了代码,你可能不会在 proguard
规则
android {
...
buildTypes {
release {
minifyEnabled false // disable proguard
...
}
}
}
[更新]:这是在 progaurd 中转义文件的方法
在您的 proguard-android-optimize.txt
文件中执行以下操作
如果您的所有模型都在同一文件夹中,则:
-keep public class com.myapp.models.** {
public protected private *;
}
否则您可以使用以下方式跳过文件:
-keep public class com.myapp.models.MyModel {
public protected private *;
}