java.lang.NoClassDefFoundError:android.support.v4.view.LayoutInflaterCompat

时间:2015-06-09 15:50:08

标签: android android-studio android-support-library

我在4.4.2版本的三星备注2中遇到以下错误。我也尝试过HTC One X + 4.2.2。我认为它的前棒棒糖。导致它在Lollipop上工作正常。有什么猜测吗?

这是我的gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }

    defaultConfig {
        multiDexEnabled true
        applicationId "com.example.app"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':volley')
    compile project(':linkedin-sdk')
    compile project(':facebook')
    compile files('libs/ormlite-android-4.49-SNAPSHOT.jar')
    compile files('libs/ormlite-core-4.49-SNAPSHOT.jar')
    compile project(':library')
    compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
    compile 'com.crittercism:crittercism-android-agent:5.0.6'
    compile 'com.squareup.picasso:picasso:2.3.2'
    compile files('libs/json_simple-1.1.jar')
    compile 'com.android.support:design:22.2.0'
    compile project(':dropboxChooserSDK')
    compile 'com.google.android.gms:play-services:7.5.0'
    compile files('libs/google-api-client-1.20.0.jar')
    compile files('libs/google-api-client-android-1.20.0.jar')
    compile files('libs/google-api-services-drive-v2-rev173-1.20.0.jar')
    compile files('libs/google-http-client-1.20.0.jar')
    compile files('libs/google-http-client-android-1.20.0.jar')
    compile files('libs/google-http-client-gson-1.20.0.jar')
    compile files('libs/google-oauth-client-1.20.0.jar')
    compile files('libs/jsr305-1.3.9.jar')
    compile files('libs/gson-2.2.4.jar')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
}

我得到了例外。

 26927-26927/com.example.app E/dalvikvm﹕ Could not find class 'android.support.v7.internal.view.menu.MenuBuilder', referenced from method android.support.v7.app.AppCompatDelegateImplV7.initializePanelMenu
06-09 21:12:24.014  26927-26927/com.example.app E/dalvikvm﹕ Could not find class 'android.support.v7.internal.view.menu.MenuBuilder', referenced from method android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu
06-09 21:12:24.014  26927-26927/com.example.app E/dalvikvm﹕ Could not find class 'android.support.v7.internal.view.menu.MenuBuilder', referenced from method android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onPreparePanel
06-09 21:12:24.019  26927-26927/com.example.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.app, PID: 26927
    java.lang.NoClassDefFoundError: android.support.v4.view.LayoutInflaterCompat
            at android.support.v7.app.AppCompatDelegateImplV7.installViewFactory(AppCompatDelegateImplV7.java:812)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:57)
            at com.example.app.BaseActivity.onCreate(BaseActivity.java:37)
            at com.example.app.SplashScreenActivity.onCreate(SplashScreenActivity.java:29)
            at android.app.Activity.performCreate(Activity.java:5451)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
            at android.app.ActivityThread.access$900(ActivityThread.java:175)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:5)

我遇到同样的问题(应用会在所有设备中崩溃< = Android 4.4,但在Android> = 5.0时工作正常)并具有以下build.gradle设置:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "com.aams.going"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.google.apis:google-api-services-youtube:v3-rev141-1.20.0'
    compile 'com.google.api-client:google-api-client-android:1.20.0'
    compile 'com.google.api-client:google-api-client-gson:1.20.0'
    compile 'com.orhanobut:logger:1.4'
    compile 'com.github.rey5137:material:1.1.1'
    compile 'com.afollestad:material-dialogs:0.7.6.0'
}

问题

这是由multiDexEnabled true使用Google Play服务API和google-api引起的。

解决方案

我通过删除multiDexEnabled true并仅指定我的应用使用的特定Google Play服务API解决了这个问题。

  • 删除multiDexEnabled true
  • 使用compile 'com.google.android.gms:play-services-identity:7.5.0'代替compile 'com.google.android.gms:play-services:7.5.0'

这是我的最终作品build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "com.aams.going"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.google.android.gms:play-services-identity:7.5.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.google.apis:google-api-services-youtube:v3-rev141-1.20.0'
    compile 'com.google.api-client:google-api-client-android:1.20.0'
    compile 'com.google.api-client:google-api-client-gson:1.20.0'
    compile 'com.orhanobut:logger:1.4'
    compile 'com.github.rey5137:material:1.1.1'
    compile 'com.afollestad:material-dialogs:0.7.6.0'
}

答案 1 :(得分:1)

启用multidex可以在运行时执行java.lang.NoClassDefFoundError:然后,Acorde到https://developers.google.com/android/guides/setup:如果您的应用程序中的方法引用数量超过65K限制,您的应用程序可能无法编译。您可以通过仅指定应用使用的特定Google Play服务API而非全部API来编译应用时缓解此问题。

示例:

compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'
compile  'com.google.android.gms:play-services-base:8.1.0'
compile  'com.google.android.gms:play-services-games:8.1.0'

在链接中,您可以找到Apis列表。如果您不使用Google Play服务,请将相同的原则应用于您的依赖项。