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

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

问题描述

我刚刚从迁移到Eclipse的工作室。我跟随了博客从Eclipse导出的项目工作室。该应用程序工作正常的棒棒糖和pre棒棒糖设备抛出下面的错误。

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)
          //
          ......
          //

我的摇篮文件

My gradle file

// 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文件。棒棒糖知道如何阅读,preLollipop不知道,除非你告诉它的应用程序类。

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, preLollipop has no idea unless you tell it in application class.

请确保以下是到位:

在build.gradle

in build.gradle

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

重要的支持pre-棒棒糖:

IMPORTANT to support pre-Lollipop:

在清单中,应用程序标签下,

In Manifest, under the application tag,

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

如果你写的应用程序类, 让你的应用程序重写 attachBaseContext 开始

If you have written Application class, Have 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);
    }
}

参考:<一href="https://developer.android.com/tools/building/multidex.html#mdex-gradle">https://developer.android.com/tools/building/multidex.html#mdex-gradle

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

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