Firebase奇怪的错误java.lang.ClassNotFoundException:不是在开发期间,而是在apk发布之后

时间:2017-03-14 20:25:37

标签: android firebase firebase-crash-reporting

我在我的应用程序中遇到了一种奇怪的行为,在开发过程中,当我在实际设备上运行应用程序时,它完美地运行,结果如下所示

app-behavior-during-dev

但在我发布相同的应用程序并在设备上运行后,应用程序崩溃了很多次并且已经死了

enter image description here

正如您所看到的,当访问Firebase控制台中的__Crash Reporting_选项时,我得到了这个表示

的堆栈跟踪

enter image description here

====

Exception java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/picasso/Picasso;
org.team.asl.connectin.activity.MainActivity$4.onDataChange (MainActivity.java:226)
com.google.android.gms.internal.zzbmz.zza ()
com.google.android.gms.internal.zzbnz.zzYj ()
com.google.android.gms.internal.zzboc$1.run ()
android.os.Handler.handleCallback (Handler.java:815)
android.os.Handler.dispatchMessage (Handler.java:104)
android.os.Looper.loop (Looper.java:194)
android.app.ActivityThread.main (ActivityThread.java:5631)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:959)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:754)
arrow_drop_down
Caused by java.lang.ClassNotFoundException: Didn't find class "com.squareup.picasso.Picasso" on path: DexPathList[[zip file "/data/app/org.team.asl.connectin-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)
java.lang.ClassLoader.loadClass (ClassLoader.java:511)
java.lang.ClassLoader.loadClass (ClassLoader.java:469)
org.team.asl.connectin.activity.MainActivity$4.onDataChange (MainActivity.java:226)
com.google.android.gms.internal.zzbmz.zza ()
com.google.android.gms.internal.zzbnz.zzYj ()
com.google.android.gms.internal.zzboc$1.run ()
android.os.Handler.handleCallback (Handler.java:815)
android.os.Handler.dispatchMessage (Handler.java:104)
android.os.Looper.loop (Looper.java:194)
android.app.ActivityThread.main (ActivityThread.java:5631)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:959)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:754)

为什么是问题

Exception java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/picasso/Picasso;
    org.team.asl.connectin.activity.MainActivity$4.onDataChange (MainActivity.java:226)

更新

MainActivity的第226行是

@Override
    public void onStart() {
        super.onStart();

        try{
            // Add value event listener to the post
            // [START user_value_event_listener]
            ValueEventListener userListener = new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    // Get User object and use the values to update the UI
                    mCurrentUser = dataSnapshot.getValue(User.class);
                    // [START_EXCLUDE]

                  Picasso.with(MainActivity.this) // Line number 226
                            .load(mCurrentUser.getAvatarUrl())
                            .into(mUserAvatarImageView);
                    mUserNameTextView.setText(mCurrentUser.getUserName());
                    mUserEmailTextView.setText(mCurrentUser.getEmail());

                    // [END_EXCLUDE]
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    // Getting User failed, log a message
                    FirebaseCrash.log(databaseError.toException().getMessage());

                }
            };


            mCurrentUserDatabaseReference.addValueEventListener(userListener);
            // [END user_value_event_listener]

            // Keep copy of post listener so we can remove it when app stops
            mUserListener = userListener;                

        } catch (Exception e){

            FirebaseCrash.log("Message is " + e.getMessage());
        }

    }

和MultiDex类是

public class EnableMultiDex extends MultiDexApplication {
    private static EnableMultiDex enableMultiDex;
    public static Context context;

    public EnableMultiDex(){
        enableMultiDex=this;
    }

    public static EnableMultiDex getEnableMultiDexApp() {
        return enableMultiDex;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    }
}
AndroidManifest.xml中的

    <application
            android:name=".EnableMultiDex"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
..............

和整个build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "org.team.asl.connectin"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "0.0.1.2 Beta"
        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:support-v4:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'com.android.support:cardview-v7:25.2.0'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-storage:10.0.1'
    compile 'com.google.firebase:firebase-config:10.0.1'
    compile 'com.google.firebase:firebase-crash:10.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-common:10.0.1'
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'com.google.android.gms:play-services:10.0.1'

    compile 'com.android.support:multidex:1.0.1'

    // FirebaseUI Auth only
    compile 'com.firebaseui:firebase-ui-auth:1.0.1'
    compile 'com.firebaseui:firebase-ui-database:1.0.1'
    /*compile 'com.afollestad.material-dialogs:core:0.9.3.0'*/
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'me.kareluo.ui:popmenu:1.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
    compile 'com.github.jd-alexander:LikeButton:0.2.0'
    compile 'com.dynamitechetan.flowinggradient:flowinggradient:1.1'
    compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.1'
    compile 'com.daimajia.numberprogressbar:library:1.4@aar'
    compile 'com.labo.kaji:relativepopupwindow:0.2.1'
    compile 'com.webianks.library:popup-bubble:1.0.3'
    compile 'com.zaaach:toprightmenu:1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:palette-v7:25.2.0'
    compile 'com.github.jrvansuita:MaterialAbout:+'
    compile 'com.github.daniel-stoneuk:material-about-library:1.7.1'
    compile "com.mikepenz:iconics-core:2.8.2@aar"
    compile 'com.mikepenz:google-material-typeface:2.2.0.3.original@aar'
    compile 'com.mikepenz:community-material-typeface:1.7.22.1@aar'
    compile 'com.github.paolorotolo:appintro:3.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'

}

apply plugin: 'com.google.gms.google-services'

发布之后,我怎么能解决这个问题,

1 个答案:

答案 0 :(得分:1)

在我看来,你忘了添加Picasso proguard规则。如上所述here

  

如果您使用的是ProGuard,则可能需要添加以下选项:

     

-dontwarn com.squareup.okhttp.**

proguard-rules.pro中添加上述行。