无法加载未知错误的Android Studio 3.0的AppCompat ActionBar [英] Failed to load AppCompat ActionBar with unknown error android studio 3.0

查看:72
本文介绍了无法加载未知错误的Android Studio 3.0的AppCompat ActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将android studio更新到3.0版之后,我无法预览应用的布局,但出现如下错误:

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 error'.

我该如何解决?但是如果我在设备手机上运行该应用程序,则该应用程序可以正常运行.

How can I fix this? but if I run the app on my device phone, its run normally.

这是我的Gradle文件:

This is my Gradle file:

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'
}

非常感谢您的时间和协助.

Thank you very much for your time and assistance in this matter.

推荐答案

首先,您需要使用相同版本的compileSdkVersionbuildToolsVersiontargetSdkVersionsupport library version.我看到您要使用buildToolsVersion '26.0.2'.因此,将它们全部更改为版本26.

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.

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

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

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

Third, try clean and build your project. As the last resort, try 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'
}

您还需要检查您的项目 build.gradle.它应包含build:gradle:3.0.0(如 @ dheeraj-joshi 指出的那样),类似这样:

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
}

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

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

这篇关于无法加载未知错误的Android Studio 3.0的AppCompat ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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