1

I've encountered a weird behavior of my App, during development when I run the App on actual device it works perfectly as the result below

app-behavior-during-dev

but after I release the same App and run on the device, the App crashes many times and becomes dead

enter image description here

as you can see, when visited __Crash Reporting_ option in Firebase console I got this stacktrace which says

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)

why is the issue

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

UPDATE

the line number 226 of MainActivity is

@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());
        }

    }

and MultiDex class is

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);
    }
}

in AndroidManifest.xml

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

and whole 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'

ocouring after release and how can I solve this,

AL.
  • 36,815
  • 10
  • 142
  • 281
Arshad Ali
  • 3,082
  • 12
  • 56
  • 99
  • __-ve vote__ why? any thing is missing please comment and notify, I'll give every required details... – Arshad Ali Mar 14 '17 at 20:33
  • Please post some code. In particular, we need the line of code which causes the crash (`MainActivity.java:226`) and the surrounding method. Also post the `dependencies` section from `build.gradle`. – Code-Apprentice Mar 14 '17 at 20:35
  • OK just a minute.. – Arshad Ali Mar 14 '17 at 20:36
  • Please see update and the line on which I've commented __//Line number 226__ – Arshad Ali Mar 14 '17 at 20:44
  • Quick question, have you enabled multi-dex in your app? – Adil Soomro Mar 14 '17 at 20:45
  • Yes I'll update the question – Arshad Ali Mar 14 '17 at 20:46
  • @AdilSoomro see my latest Update – Arshad Ali Mar 14 '17 at 20:51
  • It seems you've problem with multi-dex, see here how you should enable it. [How to enable multi-dexi](http://stackoverflow.com/a/27284064/593709) – Adil Soomro Mar 14 '17 at 20:54
  • 1
    If your app runs fine on debug but create error when on release, the most common problem is that your custom class get obfuscated by ProGuard. If above solution didn't work for you. You might be interested in [this post](http://stackoverflow.com/a/26274623/4112725) – koceeng Mar 14 '17 at 23:59
  • I don't know if this will help, but including `com.google.android.gms:play-services:x.x.x` is not good practice. It pulls in ALL the Google Play APIs and may be the reason you need MultiDex. Instead, only include the APIs you need, as described in the section of the [setup instructions](https://developers.google.com/android/guides/setup) titled _Selectively compiling APIs into your executable_. – Bob Snyder Mar 15 '17 at 04:34
  • You might get some clues by comparing your debug and release APKs using the [APK Analyzer](https://developer.android.com/studio/build/apk-analyzer.html). – Bob Snyder Mar 15 '17 at 04:43
  • 1
    You have `glide`, so why do you need Picasso? – OneCricketeer Mar 15 '17 at 06:12

2 Answers2

1

It seems to me you forgot to add Picasso proguard rule. As stated here:

If you are using ProGuard you might need to add the following option:

-dontwarn com.squareup.okhttp.**

Add above mentioned line in proguard-rules.pro.

azizbekian
  • 60,783
  • 13
  • 169
  • 249
0

You will need to change your minimum sdk version to minSdkVersion 21 and remove the multiDexEnabled true in your project app-level build.gradle file.

Moz
  • 109
  • 2
  • 10