FATAL EXCEPTION: java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout

后端 未结 5 1127
别那么骄傲
别那么骄傲 2020-12-08 05:28

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 pr

相关标签:
5条回答
  • 2020-12-08 05:54

    Your logcat returns

    java.lang.NoClassDefFoundError: android.support.v7.appcompat

    So update your support repository (Version 23) And ** For API 23:**

    compile 'com.android.support:appcompat-v7:23.0.0'
    
    0 讨论(0)
  • 2020-12-08 05:54

    In the android documentation for v7 appcompat is a note:

    Note: This library depends on the v4 Support Library. If you are using Ant or Eclipse, make sure you include the v4 Support Library as part of this library's classpath.

    I think thats your problem since you have comment out the line in your gradle:

       // compile "com.android.support:support-v4:18.0.+"
    

    Add the line again and try to compile the project.

    Also i see no com.android.support:appcompat-v7:21.0.0 line in your gradle

    0 讨论(0)
  • 2020-12-08 05:55

    As I can see the gradle file you have posted here is top level gradle file,which contains stuff that should not be there. Replace your top level gradle file contents like below :

    // 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()
        }
    }
    
    0 讨论(0)
  • 2020-12-08 06:06

    May be a long shot, but ensure your images are under /res/drawable and not /res/drawable-v24 See this answer: Binary XML file line #0: Error inflating class ImageView

    0 讨论(0)
  • 2020-12-08 06:09

    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.

    Please make sure following is in place:

    in build.gradle

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

    IMPORTANT to support pre-Lollipop:

    In Manifest, under the application tag,

    <application
            ...
            android:name="android.support.multidex.MultiDexApplication">
            ...
    </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);
        }
    }
    

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

    0 讨论(0)
提交回复
热议问题