java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / internal / zzbp

时间:2019-02-01 03:53:32

标签: android firebase google-cloud-firestore

我不明白这里出了什么问题。我一直在寻找修复程序,但找不到。有人知道怎么了吗?

  

E / Android运行时:致命异常:主要       流程:com.eldercare.fajri.eldercare,PID:30948       java.lang.NoClassDefFoundError:无法解决以下问题:Lcom / google / android / gms / common / internal / zzbp;           位于com.google.firebase.firestore.FirebaseFirestore.zze(未知来源)           在com.google.firebase.firestore.FirebaseFirestore.getInstance(未知   资源)           在com.eldercare.fajri.eldercare.boundary.HomeActivity.onCreate(HomeActivity.java:71)           在android.app.Activity.performCreate(Activity.java:6736)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1124)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2730)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2842)           在android.app.ActivityThread.-wrap12(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1560)           在android.os.Handler.dispatchMessage(Handler.java:110)           在android.os.Looper.loop(Looper.java:203)           在android.app.ActivityThread.main(ActivityThread.java:6328)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1076)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:937)        原因:java.lang.ClassNotFoundException:在路径上找不到类“ com.google.android.gms.common.internal.zzbp”。   DexPathList [[zip文件   “ /data/app/com.eldercare.fajri.eldercare-1/base.apk"],nativeLibraryDirectories=[/data/app/com.eldercare.fajri.eldercare-1/lib/arm64,   / system / lib64,/ vendor / lib64,/ system / vendor / lib64]]           在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)           在java.lang.ClassLoader.loadClass(ClassLoader.java:380)           在java.lang.ClassLoader.loadClass(ClassLoader.java:312)           位于com.google.firebase.firestore.FirebaseFirestore.zze(未知来源)           在com.google.firebase.firestore.FirebaseFirestore.getInstance(未知   资源)           在com.eldercare.fajri.eldercare.boundary.HomeActivity.onCreate(HomeActivity.java:71)           在android.app.Activity.performCreate(Activity.java:6736)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1124)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2730)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2842)           在android.app.ActivityThread.-wrap12(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1560)           在android.os.Handler.dispatchMessage(Handler.java:110)           在android.os.Looper.loop(Looper.java:203)           在android.app.ActivityThread.main(ActivityThread.java:6328)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1076)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:937)

这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.eldercare.fajri.eldercare"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.RDescActivity.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    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:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-vector-drawable:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-firestore:11.4.2'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.github.d-max:spots-dialog:0.7@aar'
    implementation 'com.rengwuxian.materialedittext:library:2.1.4'

    implementation "com.google.android.gms:play-services-base:15.0.1"

    implementation "com.google.android.gms:play-services-gcm:15.0.1"

    implementation 'com.github.wdullaer:MaterialDateTimePicker:v3.0.0'

    implementation 'com.github.ganfra:material-spinner:1.1.1'

    implementation 'gr.pantrif:easy-android-splash-screen:0.0.1'

    androidTestImplementation 'org.testng:testng:6.9.6'
}
apply plugin: 'com.google.gms.google-services'

这是我的project.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:3.2.1'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{

            url "http://maven.google.com"
        }
        maven{
            url "https://jitpack.io"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

HomeActivity:

package com.eldercare.fajri.eldercare.boundary;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;

import com.eldercare.fajri.eldercare.control.ListItemReminderAdapter;
import com.eldercare.fajri.eldercare.control.Reminder;
import com.eldercare.fajri.eldercare.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QuerySnapshot;
import com.rengwuxian.materialedittext.MaterialEditText;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import dmax.dialog.SpotsDialog;

public class HomeActivity extends AppCompatActivity {

    List<Reminder> reminderList = new ArrayList<>();

    FirebaseFirestore db;

    RecyclerView listItem;

    Reminder reminder;

    RecyclerView.LayoutManager layoutManager;

    public static Activity ha;
    FloatingActionButton fab;
    AppCompatButton next,prev;

    public String date;
    public TextView thedate;
    public MaterialEditText title,description,time;
    public boolean isUpdate = false;
    public boolean menu=false;
    public String idUpdate;

    ListItemReminderAdapter adapter;
    SpotsDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        ha = this;

        db = FirebaseFirestore.getInstance();

        thedate = (TextView)findViewById(R.id.thedate);

        dialog = new SpotsDialog(this);
        title = (MaterialEditText)findViewById(R.id.title);
        description = (MaterialEditText)findViewById(R.id.description);
        time = (MaterialEditText)findViewById(R.id.time);

        final Calendar now;
        now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH);
        int day = now.get(Calendar.DAY_OF_MONTH);

        final String today = (day +"-"+(month+1)+"-"+ year);
        date = today;
        thedate.setText(today);
        if(thedate.getText().equals(today)){
            thedate.setText("Today");
        }

        prev = (AppCompatButton)findViewById(R.id.prev);
        prev.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                now.add(Calendar.DAY_OF_MONTH,-1);
                int day = now.get(Calendar.DAY_OF_MONTH);

                int month=now.get(Calendar.MONTH);
                if(day<1) {
                    now.add(Calendar.MONTH,-1);
                }

                int year = now.get(Calendar.YEAR);
                if ((month+1)<1){
                    now.add(Calendar.YEAR,-1);
                }

                date = (day +"-"+(month+1)+"-"+ year);
                thedate.setText(day +"-"+(month+1)+"-"+ year);
                if(thedate.getText().equals(today)){
                    thedate.setText("Today");
                }
                loadData();

            }
        });

        next = (AppCompatButton)findViewById(R.id.next);
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int dlong,mlong;
                dlong = now.getActualMaximum(Calendar.DAY_OF_MONTH);
                mlong = now.getActualMaximum(Calendar.MONTH);

                now.add(Calendar.DAY_OF_MONTH,+1);
                int day = now.get(Calendar.DAY_OF_MONTH);

                int month=now.get(Calendar.MONTH);
                if(day>dlong) {
                    now.add(Calendar.MONTH,+1);
                }

                int year = now.get(Calendar.YEAR);
                if (month>mlong){
                    now.add(Calendar.YEAR,+1);
                }

                date = (day +"-"+(month+1)+"-"+ year);
                thedate.setText(day +"-"+(month+1)+"-"+ year);
                if(thedate.getText().equals(today)){
                    thedate.setText("Today");
                }
                loadData();
            }
        });

        thedate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int year = now.get(Calendar.YEAR);
                int month = now.get(Calendar.MONTH);
                int day = now.get(Calendar.DAY_OF_MONTH);

                DatePickerDialog mDatePicker = new DatePickerDialog(HomeActivity.this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                        date = (dayOfMonth +"-"+(month+1)+"-"+ year);
                        thedate.setText(dayOfMonth+"-"+(month+1)+"-"+year);
                        if(thedate.getText().equals(today)){
                            thedate.setText("Today");
                        }
                        now.set(year,month,dayOfMonth);
                        loadData();
                    }
                },year, month, day);
                mDatePicker.show();
            }
        });

        fab = (FloatingActionButton)findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HomeActivity.this,ReminderActivity.class);
                intent.putExtra("isUpdate","false");
                startActivity(intent);
            }
        });

        listItem = (RecyclerView)findViewById(R.id.Reminder);
        listItem.setHasFixedSize(true);

        layoutManager = new LinearLayoutManager(this);
        listItem.setLayoutManager(layoutManager);

        loadData();

    }

    public void loadData() {
        dialog.show();
        CollectionReference cr = db.collection("Reminder").document(date).collection("remind");

        if(reminderList.size() > 0)
            reminderList.clear();
        cr.get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                            for (DocumentSnapshot doc:task.getResult())
                            {
                                 reminder = new Reminder(doc.getString("id"),
                                        doc.getString("Title"),
                                        doc.getString("description"),
                                        doc.getString("date"),
                                        doc.getString("time"),
                                        doc.getString("done"));
                                reminderList.add(reminder);
                            }


                        adapter = new ListItemReminderAdapter(HomeActivity.this, reminderList);
                        listItem.setAdapter(adapter);
                        dialog.dismiss();
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Toast.makeText(HomeActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
    }
}

3 个答案:

答案 0 :(得分:1)

如果应用支持低于20 [minSdkVersion 19]的android版本,则这些库需要Multidex。

Enable Mutidex

尝试一下,它将起作用。

答案 1 :(得分:1)

这可能是因为您尚未启用多义处理。您需要在gradle中添加以下依赖项。

implementation 'com.android.support:multidex:1.0.3'

然后在multiDexEnabled true内设置defaultConfig,以启用多义化。

答案 2 :(得分:1)

要解决此问题,请更改以下实现:

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-firestore:11.4.2'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.android.gms:play-services-gcm:15.0.1"

implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-firestore:18.0.0'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.android.gms:play-services-gcm:16.0.0"

在顶级build.gradle文件中,请确保具有最新版本的Google服务插件:

classpath 'com.google.gms:google-services:4.2.0'

而不是4.0.1。还有

classpath 'com.android.tools.build:gradle:3.3.0'

而不是现在的3.2.1