将安卓工作室更新到 3.1.2 后,我得到了"Failed to load AppCompat ActionBar with unknown error. "



我尝试在stackoverflow上查找其他类似的问题,他们建议我们改用"buildToolsVersion"版本,但我在我的gradle文件中没有看到这样的词。

我的 Gradle 文件 (项目(:-

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

My build.gradle (Module:app(: 这是我的第二个 gradle 文件

apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.dhruv.testhello"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- 
core:3.0.2'
}

我遇到了同样的问题。我搜索了很多,我终于发现appcompat-v7:28.0.0-alpha3Android Studio的"设计视图"部分有一些错误。

所以我建议将com.android.support:appcompat-v7:28.0.0-alpha3更改为com.android.support:appcompat-v7:28.0.0-alpha1版本,然后单击文件 -> 使缓存失效/重新启动。沃拉一切都好。

当然,您应该可以访问互联网以下载com.android.support:appcompat-v7:28.0.0-alpha1

侯赛因·塞菲的回复帮助了我,但有所改变

implementation 'com.android.support:design:28.0.0-alpha3'

implementation 'com.android.support:design:28.0.0-alpha1'

,然后单击文件 -> 使缓存失效/重新启动

更新

2

正如您在支持 28.0.0 发行说明中看到的那样。

这将是 android.support 下的最后一个功能版本 打包,鼓励开发者迁移到 AndroidX 1.0.0

从现在开始,Android 将不会更新支持库。因此,我建议您在 androidx 弃用支持库之前迁移到它们。

更新

支持28.0.0发布,因此您可以使用此稳定版本。

implementation 'com.android.support:design:28.0.0'

我建议永远不要使用 alpha 版本,因为 alpha、beta 版本有错误,即测试库。

模块应用程序gradle文件看起来像这样...在您的文件中,您缺少buildToolsVersion,添加此版本可能会对您有所帮助

apply plugin: 'com.android.application'
android {
//changes
compileSdkVersion 26
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.dhruv.testhello"
minSdkVersion 24
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//changes
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- 
core:3.0.2'
}

在样式.xml,

将主题从 Theme.AppCompat.Light.DarkActionBar更改为 Base.Theme.AppCompat.Light.DarkActionBar 对我有用。

是的,它的工作,

实现 'com.android.support:design:28.0.0-alpha3' 自

实现 'com.android.support:design:28.0.0-alpha1'

之后到达文件并单击 -> 使缓存失效/重新启动

在回答这个答案时,AndroidStudio 3.1.4已经发布了Android 支持 28.0.0 候选版本(潜在最终版本,测试版(,所以请更新。 好吧,这是一个肯定适合您的配置。

targetSdkVersion 28
com.android.support:*:28.0.0-rc01

其中 * 是资源类型。

Open,res>values>styles.xml,在这里你会找到一行:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

将该行替换为:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

这意味着:在父主题的名称开头添加"Base."一词。

Open, res -->values --> styles.xml,在这里你会发现这样的一行:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

将其更改为:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

换句话说,将"黑暗操作栏"更改为"无操作栏">

相关内容

最新更新