无法加载 AppCompat ActionBar,出现未知错误 android studio 3.0
Failed to load AppCompat ActionBar with unknown error android studio 3.0
将 android studio 更新到 3.0 版后,我无法预览我的应用程序布局,出现如下错误:
'Failed to load AppCompat ActionBar with unknown error'.
我该如何解决这个问题?但如果我 运行 我设备上的应用程序 phone,它通常 运行。
这是我的 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'
}
非常感谢您在这件事上的时间和帮助。
首先,您需要使用相同版本的compileSdkVersion
、buildToolsVersion
、targetSdkVersion
和support library version
。我看到您想使用 buildToolsVersion '26.0.2'
。因此,将它们全部更改为版本 26.
其次,您需要清理 build.gradle。不需要重复依赖。
第三,尝试清理并构建您的项目。作为最后的手段,尝试 File -> Invalidate Caches/Restart...
您的 app 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 指出的那样),像这样:
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
.
这是 android 支持库版本“26.0.0-beta2”
中的错误
使用:
compile 'com.android.support:appcompat-v7:24.2.1'
与:
buildToolsVersion '26.0.0'
和
类路径
'com.android.tools.build:gradle:3.0.0-alpha8'
一切正常。
我遇到了类似的问题(可能不完全相同)。
我能够 运行 phone 上的起始代码并且菜单在那里。但是,Android Studio 中的预览窗格未显示实际布局。
我已通过将 Theme.AppCompat.Light.DarkActionBar 更改为 Base.Theme.AppCompat.Light.DarkActionBar in 来修复它styles.xml.
将 android studio 更新到 3.0 版后,我无法预览我的应用程序布局,出现如下错误:
'Failed to load AppCompat ActionBar with unknown error'.
我该如何解决这个问题?但如果我 运行 我设备上的应用程序 phone,它通常 运行。
这是我的 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'
}
非常感谢您在这件事上的时间和帮助。
首先,您需要使用相同版本的compileSdkVersion
、buildToolsVersion
、targetSdkVersion
和support library version
。我看到您想使用 buildToolsVersion '26.0.2'
。因此,将它们全部更改为版本 26.
其次,您需要清理 build.gradle。不需要重复依赖。
第三,尝试清理并构建您的项目。作为最后的手段,尝试 File -> Invalidate Caches/Restart...
您的 app 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 指出的那样),像这样:
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
.
这是 android 支持库版本“26.0.0-beta2”
中的错误使用:
compile 'com.android.support:appcompat-v7:24.2.1'
与:
buildToolsVersion '26.0.0'
和
类路径
'com.android.tools.build:gradle:3.0.0-alpha8'
一切正常。
我遇到了类似的问题(可能不完全相同)。
我能够 运行 phone 上的起始代码并且菜单在那里。但是,Android Studio 中的预览窗格未显示实际布局。
我已通过将 Theme.AppCompat.Light.DarkActionBar 更改为 Base.Theme.AppCompat.Light.DarkActionBar in 来修复它styles.xml.