将 android studio 更新到 3.0 版后,我无法预览我的应用程序布局,我收到如下错误:
'Failed to load AppCompat ActionBar with unknown error'.
我该如何解决这个问题?但如果我在我的手机上运行该应用程序,它会正常运行。
这是我的 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
、支持库版本
。我看到您想使用 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'
}
您还需要检查您的项目 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 - 无法加载 AppCompat ActionBar,出现未知错误 android studio 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47067706/