android - 应用程序仅在 Lollipop 设备上崩溃

标签 android facebook performance android-layout gradle

应用程序在所有操作系统上都运行良好,但是当我添加 facebook SDK 时,它在 Lollipop 设备上给我以下错误消息。

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

Caused by: java.lang.ClassNotFoundException: Didn't find class "retrofit2.Retrofit$Builder" on path: DexPathList[[zip file "/data/app/com.myapp.app-3/base.apk", zip file

java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit2/Retrofit$Builder; Caused by: java.lang.ClassNotFoundException: Didn't find class "retrofit2.Retrofit$Builder" on path: DexPathList[[zip file "/data/app/com.myapp.app-3/base.apk", zip file "/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()
    }
}       

请指导我这次崩溃的原因是什么,以及为什么它只在 Lollipop 设备上崩溃而在 Marshmallow 和 Nougat 上运行良好。

编辑

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

最佳答案

您使用的库太多,因此您的方法已超过 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了解更多信息

关于android - 应用程序仅在 Lollipop 设备上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43116422/

相关文章:

java - 使用 facebook4j 在页面上发帖

Python - Pandas 根据用户操作终止 `read_sql`

programming-languages - 屏幕抓取效率

android - 使用 Android 日历

java - ChooserActivity 泄露了 IntentReceiver

java - 安卓java.security.cert.CertPathValidatorException : Trust anchor for certification path not found

ruby-on-rails - rails : Facebook Connect: Client Side/Server Side or Both?

facebook - 2018 年通过网站链接打开 Facebook 应用程序的正确方法?

performance - Cassandra 性能: split CF or not?

更改构建版本后 Android 自定义警报对话框显示错误