无法加载带有未知错误android studio 3.0的AppCompat ActionBar

Den*_*wan 4 android gradle android-actionbar android-studio-3.0

在将android studio更新到3.0版之后,我无法预览我的应用程序的布局,我得到的错误如下:

'Failed to load AppCompat ActionBar with unknown error'.
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?但如果我在设备手机上运行应用程序,它会正常运行.

这是我的Gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId 'com.halloo'
        minSdkVersion 16
        targetSdkVersion 24
        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:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    testCompile 'junit:junit:4.12'
}

dependencies {
    compile 'com.squareup.okhttp3:okhttp:3.5.0'
}
dependencies {
    compile 'com.android.support:support-v4:24.+'
}
dependencies {
    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
}

dependencies {
    compile 'com.android.support:support-v4:24.+'
    compile 'junit:junit:4.12'
}

dependencies {
    compile 'com.android.support:support-v4:24.+'
    compile 'com.mikhaellopez:hfrecyclerview:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)

非常感谢您在这件事上的时间和帮助.

ישו*_*ותך 7

首先,您需要使用同一版本compileSdkVersion,buildToolsVersion,targetSdkVersion,和support library version.我知道你想用buildToolsVersion '26.0.2'.因此,将所有这些更改为版本26.

其次,您需要清理build.gradle.不需要重复的依赖项.

第三,尝试清理并构建您的项目.作为最后的手段,试试吧File -> Invalidate Caches/Restart...

你的应用 build.gradle应该是这样的:

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'
}
Run Code Online (Sandbox Code Playgroud)

您还需要检查您的项目 build.gradle.它应该包含build:gradle:3.0.0(正如@ dheeraj-joshi指出的那样),如下所示:

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
}
Run Code Online (Sandbox Code Playgroud)

然后,您需要检查您的gradle版本.它应该至少使用gradle-4.1.