Failed to load AppCompat ActionBar with unknown error android studio 3.0

后端 未结 3 1136
走了就别回头了
走了就别回头了 2020-12-11 21:10

After updating android studio to version 3.0, I can\'t preview layout of my app, I get the error like:

\'Failed to load AppCompat ActionBar with unknown erro         


        
3条回答
  •  生来不讨喜
    2020-12-11 21:28

    First, you need to use the same version of compileSdkVersion, buildToolsVersion, targetSdkVersion, and support library version. I see that you want to use buildToolsVersion '26.0.2'. So, change all of them to version 26.

    Second, you need to clean up your build.gradle. There is no need for duplicate dependencies.

    Third, try clean and build your project. As the last resort, try File -> Invalidate Caches/Restart...

    Your app build.gradle should be something like this:

    apply plugin: 'com.android.application'
    
    android {
      compileSdkVersion 26
      buildToolsVersion '26.0.2'
      defaultConfig {
        applicationId 'com.halloo'
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
        release {
          minifyEnabled false
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
      }
      productFlavors {
      }
    }
    
    dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
      })
      compile 'com.android.support:appcompat-v7:26.1.0'
      compile 'com.android.support:design:26.1.0'
      compile 'com.android.support:support-v4:26.1.0'
      compile 'com.squareup.okhttp3:okhttp:3.5.0'
      compile 'com.android.support:recyclerview-v7:26.1.0'
      compile 'com.mikhaellopez:hfrecyclerview:1.0.0'
      testCompile 'junit:junit:4.12'
    }
    

    You also need to check for your project build.gradle. It should contain build:gradle:3.0.0 (as @dheeraj-joshi has pointing out), something like this:

    buildscript {
      repositories {
        jcenter()
        mavenCentral()
      }
      dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
      }
    }
    
    allprojects {
      repositories {
        jcenter()
        mavenCentral()
    //    maven { url "https://maven.google.com" }
        google()
      }
    }
    
    
    task clean(type: Delete) {
      delete rootProject.buildDir
    }
    

    Then, you need to check your gradle version. It should at least using gradle-4.1.

提交回复
热议问题