Aiero
Aiero

Reputation: 3

How to fix ic_launcher_foregorund.xml unexpected token and top level element not found

I am building a TODO app and I'm getting this error when I wanna run my app that says the problem in v23/ic_launcher_foreground.xml the code is like this

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

the problems are 1. Unexpected token
2. top level element not found

Error

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

Upvotes: 0

Views: 261

Answers (1)

Vasili Fedotov
Vasili Fedotov

Reputation: 1171

I think the unexpected token is referring to the word "white".

try this:

Option 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> 

Or Option 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> 

and add to your colors.xml

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

Upvotes: 1

Related Questions