首页 文章

应用程序仅在棒棒糖设备上崩溃

提问于
浏览
9

应用程序在所有操作系统上运行正常,但是当我添加facebook SDK时,它会在棒棒糖设备上给出以下错误消息 .

compile 'com.facebook.android:facebook-android-sdk:4.20.0'

引起:java.lang.ClassNotFoundException:在路径上找不到类“retrofit2.Retrofit $ Builder”:DexPathList [[zip file“/data/app/com.myapp.app-3/base.apk”,zip file java.lang.NoClassDefFoundError:解析失败:Lretrofit2 / Retrofit $ Builder;引起:java.lang.ClassNotFoundException:路径上没有找到类“retrofit2.Retrofit $ Builder”:DexPathList [[zip file“/data/app/com.myapp.app-3/base.apk”,zip文件“/ data / app / com.myapp.app-3 / split_lib_dependencies_apk.apk”,

这是我的gradle文件 .

compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {

    applicationId 'com.myapp.app'
    minSdkVersion 21
    targetSdkVersion 23
    versionCode 122
    versionName "1.2.5"
    multiDexEnabled true
    ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86"
    }

configurations.all {
    resolutionStrategy {
    force 'com.squareup.okhttp:okhttp:2.4.0'
    force 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    force 'com.squareup.okio:okio:1.11.0'
    force 'com.squareup.okhttp3:okhttp:3.6.0'
        force 'com.squareup.retrofit2:retrofit:2.2.0'
        force 'com.android.support:recyclerview-v7:25.0.0'
        force 'com.android.support:support-v4:25.0.0'
        force 'com.android.support:cardview-v7:25.0.0'
        force 'com.android.support:appcompat-v7:25.0.0'
        force 'com.android.support:design:25.0.0'
        force 'com.android.support:support-annotations:25.0.0'
        force 'com.google.android.gms:play-services-ads:9.0.1'
        force 'com.google.android.gms:play-services-location:9.0.1'
        force 'com.google.android.gms:play-services-auth-base:9.0.1'
        force 'com.google.android.gms:play-services-base:9.0.1'

        }



configurations.all {
    resolutionStrategy {
        failOnVersionConflict()
    }
}

请指导我这次坠机的原因是什么,以及为什么它只会撞上棒棒糖设备并在Marshmallow和Nougat上正常工作 .

EDIT

如果我不使用facebook sdk,一切似乎都很好,没有崩溃 . 也许Facebook sdk引起了这个问题,但我不知道为什么

4 回答

  • 0

    在我的案例中,这解决了我在应用程序类中遇到的问题

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    
  • 1

    您使用的库太多,因此您的方法已超过64k,因此您必须为项目启用 Multidex

    你的内心 build.gradle

    android {
        defaultConfig {
            ...
            minSdkVersion 15 
            targetSdkVersion 25
            multiDexEnabled true
        }
        ...
    }
    
    dependencies {
      compile 'com.android.support:multidex:1.0.1'
    }
    

    并在 AndroidManifest.xml

    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
    

    有关详细信息,请参阅This

  • 0

    你得到 ClassNotFoundException

    当Java虚拟机(JVM)尝试加载特定类并且在类路径中找不到指定的类时,抛出ClassNotFoundException .

    首先你应该设置 Multidex .

    Android应用程序(APK)文件包含Dalvik可执行文件(DEX)文件形式的可执行字节码文件,其中包含用于运行应用程序的编译代码 . Dalvik可执行规范将单个DEX文件中可引用的方法总数限制为65,536,包括Android框架方法,库方法和您自己的代码中的方法 . 超过此限制要求您配置应用程序构建过程以生成多个DEX文件,称为多索引配置 .

    你应该使用最新版本

    compileSdkVersion 25
        buildToolsVersion '25.0.2'
    
        defaultConfig {
    
            applicationId 'com.myapp.app'
            minSdkVersion 21
            targetSdkVersion 25 // Good approach using same version of compileSdkVersion 
            versionCode 122
            versionName "1.2.5"
            multiDexEnabled true
            ndk {
                abiFilters "armeabi", "armeabi-v7a", "x86"
            }
    
        configurations.all {
    
            resolutionStrategy {
            force 'com.squareup.okhttp:okhttp:3.7.0'
            force 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'
            force 'com.squareup.okio:okio:1.12.0'
            force 'com.squareup.okhttp3:okhttp:3.7.0'
            force 'com.squareup.retrofit2:retrofit:2.2.0'
            force 'com.android.support:recyclerview-v7:25.2.0'
            force 'com.android.support:support-v4:25.2.0'
            force 'com.android.support:cardview-v7:25.2.0'
            force 'com.android.support:appcompat-v7:25.2.0'
            force 'com.android.support:design:25.2.0'
            force 'com.android.support:support-annotations:25.2.0'
            force 'com.google.android.gms:play-services-ads:10.2.1'
            force 'com.google.android.gms:play-services-location:10.2.1'
            force 'com.google.android.gms:play-services-auth-base:10.2.1'
            force 'com.google.android.gms:play-services-base:10.2.1'
    
            }
    
         configurations.all {
         resolutionStrategy {
            failOnVersionConflict()
           }
        }
    

    之后 Clean-Rebuild-Run .

    FYI

    如果 4.20.0 崩溃,您可以使用以下版本 .

    compile 'com.facebook.android:facebook-android-sdk:4.16.0'
    
  • 5

    我能看到的主要问题是你在项目中添加了很多库,超出了方法限制 . Android应用程序有一定的方法限制 . 为了使您的代码更有效,我建议您删除所有不必要的库,例如为什么一起使用“Retrofit”和“OkHttp”?您可以完成其中任何一项所做的所有工作 . 但是如果你想使用所有这些库,那么你必须允许你的应用程序使用“Multidex” . 这是允许“Multidex”使用的方法 .

    https://developer.android.com/studio/build/multidex .

    但我不建议使用它 . 因为这会给你的应用带来负担,并且需要更多的空间在Phone的ram中选择是你的!

相关问题