NoClassDefFoundError: Failed resolution of: Landroid/support/v7/appcompat/R$styleable

前端 未结 5 747
谎友^
谎友^ 2020-12-03 16:57

Newbie trying to finish the My first App tutorial provided by Google. On the way to this fatal exception I did import a lot of random packages to get rid of \"cannot be reso

相关标签:
5条回答
  • 2020-12-03 17:34

    In my case I had a layout which was defined for 720p but not defined for default resolutions so it was crashing. Adding that layout file fixed this issue, logcat dont lie.

    0 讨论(0)
  • 2020-12-03 17:40

    I deleted 'build' folder in "yourAppName\app" folder

    and everything worked fine. If above solution didn't work, try this. build folder will be auto-generate when you build your project again.

    0 讨论(0)
  • 2020-12-03 17:50

    You are getting that error because of the following reasons:

    In your Gradle build file your app is targeting and compiling with the beta version of Android that is still in development with:

    compileSdkVersion 'android-L'
    buildToolsVersion '20'
    

    as well as

    minSdkVersion 20
    targetSdkVersion 20
    

    First thing to note is that this app will not run correctly (at this time) on any device without android-L flashed to it.

    The real crux of your issue is in DisplayMessageActivity, it extends via inheritance [ActionBarActivity]:(https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html) this is one of the support library classes for AppCompat.

    To fix this, change your min SDK to 10 (or 14 which is ice cream sandwich), your max SDK to 19 (Kit Kat) and un-comment the appcompat-v7 library in your dependencies.

    As a side note, when you declare widgets in their respective activities/fragments it's usually good practice to have their scope be outside of any methods:

    EditText editText;
    Button sendMessageButton;
    
    // Then in your onCreate() method
    editText = (EditText) findViewById(R.id.editText);
    sendMessageButton = (Button) findViewById(R.id.sendMessageButton);
    

    This helps reduce memory re-allocation and make your code a little more readable. Sometimes you may have to bend the rules a bit but this is the common practice.

    0 讨论(0)
  • 2020-12-03 17:50

    Just
         Build -> Clean Project
    and then
         Build -> Rebuild Project.
    That's all.

    0 讨论(0)
  • 2020-12-03 17:50

    In my case the issue occurred in Android Studio 4.0. I suppose there was something wrong with Gradle cache.

    Unfortunately, neither Invalidate Сaches / Restart, nor Build -> Clean Project & Build -> Rebuild Project didn't help me, so I had to take drastic measures.

    1. Close Android Studio.

    2. Open Terminal and navigate to your project's root directory.

    3. Delete all Gradle modules' build directories, so all modules will be recompiled soon.

      find . -wholename "*/build" -exec rm -rf {} \;
      

      But if you have a single module, then just:

      rm -rf app/build
      
    4. Purge Gradle cache. By default, it's located in your home directory.

      rm -rf ~/.gradle
      
    5. Open Android Studio again. It will start to build the project. It will take a long time, since we have just deleted the cache, but the issue should be resolved.

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