条目名称“res/color/material_on_surface_disabled.xml”发生冲突。

15
我刚刚创建了一个已签名的apk,之后我向我的项目添加了两个文件- my_web_activity.xml 和 MyWebActivity.kt。编译代码后,我遇到了一个错误 - "条目名称'res/color/material_on_surface_disabled.xml'冲突",没有其他信息被指定。
my_web_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-3940256099942544/6300978111"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent" />

    <WebView
        android:id="@+id/my_web_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="1dp"
        app:layout_constraintBottom_toTopOf="@+id/adView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
```

MyWebActivity.kt
```
package com.albertjokelin.revise

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.MobileAds

class MyWebActivity : AppCompatActivity() {

    lateinit var mAdView: AdView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.my_web_activity)

        // Google Ad view
        MobileAds.initialize(this)
        mAdView = findViewById(R.id.adView)
        val adRequest: AdRequest = AdRequest.Builder().build()
        mAdView.loadAd(adRequest)
    }

}
```

Edit: I ended up rebuilding the whole project from scratch after trying everything available at that time. So I don't know which solution works. Cheers!

2
你尝试重新构建项目了吗? - Android_id
6个回答

24

当我在启动画面进行更新时,出现了问题,快速的解决方法是

  1. 从android/app/build或者yourProjectFoler/build中删除build文件夹
  2. 从android/app/release或者yourProjectFoler/release中删除release文件夹
  3. 最后一步,在Android Studio中转到 => Build > Rebuild Project

现在尝试一下吧!希望能解决问题...


8
这对我很有效 - 实际上只需执行“构建>清理项目”即可 - 但每次更改设备时都需要执行此操作,这是相当频繁的。 明显存在构建过程的问题。 - richjhart
我同意构建过程中存在严重的错误。现在,我再也无法生成已签名的APK文件,因为会出现“元数据冲突”消息,这迫使我执行上述所有步骤。仿佛我的Android生活还不够痛苦,似乎生成APK文件已经变得不可能了。 - rmirabelle

14

前往 Build 菜单 > 清理项目


2
这对我也起作用了。 "清理项目" + "重建项目" - Gil Becker

1
不要删除任何东西,只需关闭Android Studio,然后重新打开并对项目进行清理和重建,一切都会变好。

0

删除项目层次结构中的build文件夹和应用程序层次结构中的release/debug文件夹,然后重新构建您的项目,这种方法对我有效。


0
尝试过“使缓存无效并重新启动”,并且运行得很完美。主要原因是Android Studio尝试更新构建索引,但无法访问它!

0

我尝试了 Build -> Clean ProjectFile -> Invalidate cache too,但都没有用。

唯一有效的方法是删除之前生成的 apk 文件,即 android/app/debug/app-debug.apk


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接