如何修复ic_launcher_foregorund.xml意外令牌和顶级元素未找到

时间:2019-05-30 09:27:50

标签: java android

我正在构建TODO应用,当我想运行我的应用时出现此错误,该应用说v23 / ic_launcher_foreground.xml中的问题是这样的代码

<adaptive-icon
    xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="white"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon> 

问题是 1.意外令牌
2.找不到顶级元素

错误

Executing tasks: [:app:assembleDebug]

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> 1 exception was raised by workers:
  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  C:\Users\CHARAN\Desktop\Android Development\BPTODO\app\src\main\res\drawable-v24\ic_launcher_foreground.xml:40: error: not well-formed (invalid token).
  C:\Users\CHARAN\Desktop\Android Development\BPTODO\app\src\main\res\drawable-v24\ic_launcher_foreground.xml: error: file failed to compile.



* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 27s
8 actionable tasks: 1 executed, 7 up-to-date

1 个答案:

答案 0 :(得分:1)

我认为意外标记是指“白色”一词。

尝试一下:

选项1:

<adaptive-icon
    xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="#FFFFFF"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon> 

或选项2:

<adaptive-icon
    xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/white"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon> 

并添加到您的 colors.xml

<color name="white">#FFFFFF</color>