致命异常:java.lang.NoClassDefFoundError:android.support.v7.appcompat.R$layout [英] FATAL EXCEPTION: java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout

查看:33
本文介绍了致命异常:java.lang.NoClassDefFoundError:android.support.v7.appcompat.R$layout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从 eclipse 迁移到 studio.我关注了一个博客,将项目从 Eclipse 导出到工作室.该应用程序在棒棒糖中运行良好,并在棒棒糖前设备中引发以下错误.

I just migrated from eclipse to studio. I followed one blog to export project from eclipse to studio. The app working fine in lollipop and throwing the following error in pre lollipop devices.

仅在工作室中出现此错误.不在日食中.

Getting this error only in studio. not in eclipse.

FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout
            at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:324)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
            at com.hsp.inventory.SplashActivity.onCreate(SplashActivity.java:53)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
          //
          ......
          //

我的gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven {
            url "http://dl.bintray.com/journeyapps/maven"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.google.code.gson:gson:2.3'
   // compile "com.android.support:support-v4:18.0.+"

    compile project(':sliderLibrary')
    compile project(':camera')
    compile project(':volley')

    // Zxing library compile

    compile 'com.journeyapps:zxing-android-embedded:2.3.0@aar'
    compile 'com.journeyapps:zxing-android-legacy:2.3.0@aar'
    compile 'com.journeyapps:zxing-android-integration:2.3.0@aar'
    compile 'com.google.zxing:core:3.2.0'

}


android {

    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    defaultConfig {
        applicationId "com.hsp.inventory"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets', 'src/main/assets', 'src/main/assets/fonts']
        }

        instrumentTest.setRoot('tests')


        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

如果您想查看我的清单和 act_splash.xml,请告诉我.我会在这里更新.

Please let me know if you want to take a look at my manifest and act_splash.xml. I will update here.

有什么想法吗?

推荐答案

我遇到了同样的问题并修复了它.这是 Dex 限制的问题.因为达到了 dex 限制,它会创建两个 dex 文件.Lollipop 知道如何阅读,除非您在 Application 类中指定,否则 Lollipop 之前不知道.

I faced the same issue and fixed it. It is issue with Dex limit. Because the dex limit is reached, it creates two dex files. Lollipop knows how to read, pre-Lollipop has no idea unless you specify it in the Application class.

请确保以下内容到位:

在 build.gradle 中

in build.gradle

dependencies {
    compile 'com.android.support:multidex:1.0.0'
}
defaultConfig {          
    multiDexEnabled true
}

重要支持前棒棒糖:

在 Manifest 中,在应用程序标签下,

In Manifest, under the application tag,

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

或者如果您使用了自己的 Application 类,使您的 Application 覆盖以

Or if you have used your own Application class, make your Application override attachBaseContext starting with

 import android.support.multidex.MultiDexApplication;
 import android.support.multidex.MultiDex;

 public class MyApplication extends MultiDexApplication {
 // ......

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

参考:https://developer.android.com/tools/building/multidex.html#mdex-gradle

这篇关于致命异常:java.lang.NoClassDefFoundError:android.support.v7.appcompat.R$layout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆