android 异常错误java.lang.ClassNotFoundException:不在开发期间,而是在apk发布后

nnsrf1az  于 2022-12-25  发布在  Android
关注(0)|答案(2)|浏览(174)

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

但在我发布同一个应用程序并在设备上运行后,该应用程序多次崩溃并死亡

如您所见,当访问Firebase控制台中的__崩溃报告_选项时,我得到了以下堆栈跟踪:

====

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)

更新

主活动的行号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);
    }
}

在Android清单. xml中

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

和整个建筑。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'

释放后发生的事情,我该如何解决这个问题,

oknrviil

oknrviil1#

在我看来,您似乎忘记添加Picasso proguard规则。如下所述:
如果使用ProGuard,可能需要添加以下选项:
第一个月
proguard-rules.pro中添加上述行。

tct7dpnv

tct7dpnv2#

您需要将最低SDK版本更改为minSdkVersion 21,并在项目应用级build.gradle文件中删除multiDexEnabled true

相关问题