Android build failed with error: Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

Hi everyone,

When I try to build my game for android, it fails at the end of the build and throw error:
“Picked up JAVA_TOOL_OPTIONS : -Dfile.encoding=UTF-8”

It also include other errors that appears after it:

  • "Note: C:\Users\Aun\Unity Projects\ThunderTraveler\Temp\gradleOut\unityLibrary\

src\main\java\com\unity3d\player\UnityPlayerActivity. java uses or overrides a deprecated API."

  • “Note: Recompile with -Xlint:deprecation for details.”

  • “FAILURE: Build failed with an exception.”

  • “Execution failed for task ’ : launcher : processReleaseResources’.”

  • “> Android resource linking failed”

  • " C:\Users\Aun\Unity Projects\ThunderTraveler\Temp\gradleOut\launcher\build\intermediates\

merged_manifests\release\AndroidManifest.xml : 41 : AAPT : error: unexpected element found in ."

  • "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 1m 8s”

  • “Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details”

  • “> Task :launcher : preBuild UP-TO-DATE”

  • “> Task :unityLibrary : preBuild UP-TO-DATE”

  • “> Task :unityLibrary : GoogleMobileAdsPlugin.androidlib : preReleaseBuild UP-TO-DATE”

  • “> Task :unityLibrary : checkReleaseManifest”

So there are actually 90+ errors in my console when build fails. l also click checked the " Custom Gradle Property Template" in my Player/Publishing Settings and I added “android.useAndroidX=true” and “android.enableJetifier=true” at the top of the “gradleTemplate.properties” file in the directory
“C:\Users\Aun\Unity Projects\ThunderTraveler\Assets\Plugins\Android”, but still no luck.
I also have set the JAVA_HOME environent variable correctly (I don’t know if it has something to do with environment variables or not)

What I did before these errors?

Before getting these errors, I integrated “google admob sdk version 6.0.1” in my project and implemented banner and interstitial ads with test ids. They were working fine in editor. when I created a build, the build created successfully with no errors. But test ads were not working in build. Then I start force resolving android dependencies but resolving android dependencies failed. Then I realized there are some corrupt files in gradle cache in the directory " C:\Users\Aun.gradle\wrapper\dists\gradle-5.1.1 bin \ 90y9l8txxfw1s2o6ctiqeruwn " which are causing the failure of resolving android dependencies.Then I deleted the corrupt files of Gradle Cache. The files were " gradle-5.1.1-bin.zip " and " gradle-5.1.1-bin.zip.lck " that I deleted from the directory " C:\Users\Aun.gradle\wrapper\dists\gradle-5.1.1-bin\90y9l8txxfw1s2o6ctiqeruwn ".
Then I restarted the resolving android dependencies and it started successfully and started downloading “gradle-5.1.1-bin.zip” file in the directory " C:\Users\Aun .gradle \ wrapper\dists\gradle-5.1.1-bin\ 90y9l8txxfw1s2o6ctiqeruwn " But due to slow internet connection on my system it did not downloaded successfully and failed, so I had to remove these files form gradle cache again.

Then I went to the official Website of Gradle and downloaded the gradle 5.1.1 with the name “gradle-5.1.1-all.zip”. I copied this file into “C:\Users\Aun.gradle \wrapper \dists\gradle-5.1.1-bin\ 90y9l8txxfw1s2o6ctiqeruwn” and renamed it from “gradle-5.1.1-all.zip” to “gradle-5.1.1-bin.zip”. Then I restarted force dependency resolver for android and It completed successfully with no error. But When I start building game for android, the build crashed with the error like " Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 " and other errors that I mentioned earlier.

I am using following tools:

  • Unity 2019.4.15f1
  • java version “1.8.0_271”
  • Google Admob version 6.0.1

Any idea how to fix this issue?
Thanks in Advance.

This is the actual error. You’ve got queries element in a wrong place in one of your manifests/template manifests.

2 Likes

@Yury-Habets Thank you for pointing out this error.
"C:\Users\Aun\UnityProjects\ThunderTraveler\Temp\gradleOut\launcher\build\intermediates\merged_manifests\release\AndroidManifest.xml : 41 : AAPT : error: unexpected element <queries> found in <manifest>."

After exploring this error I was able to fix it.

Solution:
Now to fix this error, go to Player Settings > Publishing Settings > and then tick “Custom Base Gradle Template”. So it will generate file at the location " assets / plugins / Android / baseProjectTemplate.gradle. Open this new generated file " baseProjectTemplate.gradle " and change the value of " classpath ‘com.android.tools.build:gradle:3.4.0’ " to
" classpath ‘com.android.tools.build:gradle:3.4.3’ ". Save these changes in a file and close it.

Now Restart Unity and start build for android. Since you are building first time after making changes, make sure to have proper internet connection because Unity will download some files during build time. Otherwise your build may crash with no internet connection. That’s all you need to do.

Why this error?
If you guys wanna know why this error happens, make sure to check these links for further details.
https://stackoverflow.com/questions/62969917/how-to-fix-unexpected-element-queries-found-in-manifest-error

Stay Blessed…!

10 Likes

yes , Solved…
Thank you so much!

queries in Android Manifest is supported from specific gradle versions which were released later. So, you need may need to adjust the gradle version so that its supported with in unity.

If you want to know more details,
If Target Api is >= 30, Make sure your Unity version supports any of the minimum android gradle versions starting from 3.3.3, 3.4.3, 3.5.4, 3.6.4, 4.0.1.

Update:
Enable base gradle template option in publishing settings of Player Settings and update the android gradle plugin version in that file.

1 Like

This error has caused me to lose the ability to build anything with unity. I’ve tried every single solution and nothing works. I’ve even installed other versions of Unity. These are the errors I’m Still getting:

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
java.lang.OutOfMemoryError (no error message)

  • 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 29s

UnityEditor.BuildPlayerWindow:BuildPlayerAndRun () (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPlayerWindow.cs:180)

It’s followed by this error:

CommandInvokationFailure: Gradle build failed.
/Applications/Unity/Hub/Editor/2021.3.8f1/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath “/Applications/Unity/Hub/Editor/2021.3.8f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-6.1.1.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx4096m” “assembleDebug”

Environment Variables:
BURST_ANDROID_MIN_API_LEVEL = 22
XPC_FLAGS = 0x0
JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF-8
PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands

TMPDIR = /var/folders/24/bdjgdlz91xg8bhybz_j_w45r0000gn/T/
SHELL = /bin/zsh
SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.Vepv3AYVpg/Listeners
HOME = /Users/jeremycook
__CFBundleIdentifier = com.unity3d.unityhub
USER = jeremycook
__CF_USER_TEXT_ENCODING = 0x1F5:0x0:0x0
LOGNAME = jeremycook
ORIGINAL_XDG_CURRENT_DESKTOP = undefined
JAVA_HOME = /Applications/Unity/Hub/Editor/2021.3.8f1/PlaybackEngines/AndroidPlayer/OpenJDK
ANDROID_NDK_ROOT = /Applications/Unity/Hub/Editor/2021.3.8f1/PlaybackEngines/AndroidPlayer/NDK
XPC_SERVICE_NAME = application.com.unity3d.unityhub.21706282.21707035
COMMAND_MODE = unix2003

stderr[
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:launcher:packageDebug’.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
java.lang.OutOfMemoryError (no error message)

  • 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.

What is the deal with this? It just started out of the blue and now I have no way to use any version of unity. Even after a complete restore, this thing keeps coming up. Any help beyond the already tried methods of checking and unchecking would be most appreciated.

You can try increasing the JVM memory in Unity’s preferences (I think it’s external tools)

Hello,
Exactly the same error… I also try to increase the JVM memory but not better…
Do you have any clues ?

I have had this issue tried everything here and nothing but simply putting my android sdk maximum target to the latest which is 33 it solved the issue!

Hi, I’m running into something similar. I’ve tried so many weird hacky solutions and I can’t for the life of me get it to build at all. :frowning:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ‘:launcher:processReleaseResources’.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/Users/…/Android/Prj/IL2CPP/Gradle/unityLibrary/build/intermediates/library_manifest/release/AndroidManifest.xml:35:9-85: AAPT: error: unexpected element found in .

Any ideas? I’m building to this version. In Unity 2021.3.23f1

Thanks,
P

Share the complete manifest file as seems like you entered uses-permission attribute in wrong place.

Ahhh okay, it looks like an old Prime 31 asset was creating the Manifest file :roll_eyes:
Working now, thanks :slight_smile:

1 Like

it wont work and i dont know how to change it to com.ndroid.tools.build:gradle:3.4.3

Hi, Can someone please assist me with this

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task :launcher:processReleaseResources. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > Android resource linking failed. C:\Users\Uche-Orji Michael.gradle\caches\transforms-2\files-2.1\cac0526fac8a06cd07b67df880360aca\jetified-facebook-common-15.2.0\AndroidManifest.xml:32:17-69: AAPT: error: unexpected element < property > found in < manifest>< application>.
```csharp
**manifest xmlns:android=“http://schemas.android.com/apk/res/android
xmlns:tools=“http://schemas.android.com/tools
package=“com.facebook.common” >

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="31" />

<queries>
    <package android:name="com.facebook.katana" />
</queries>

<application>
    <activity
        android:name="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:theme="@style/com_facebook_activity_theme" />
    <activity android:name="com.facebook.CustomTabMainActivity" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true"
        tools:node="merge" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="cct.${applicationId}"
                android:scheme="fbconnect" />
        </intent-filter>
    </activity>
</application>

**
```
This is the manifest file

Please how did you fix this?

did any one have proper solution for it?

I upgraged my unity editor to 2022.3.10f1, and I change classpath ‘com.android.tools.build:gradle:4.1.0’ in my baseProjectTemplate.gradle to classpath ‘com.android.tools.build:gradle:7.1.2’ and everything started working well

plugins {
// If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
// See which Gradle version is preinstalled with Unity here Unity - Manual: Gradle for Android
// See official Gradle and Android Gradle Plugin compatibility table here Android Gradle plugin 8.5 release notes  |  Android Studio  |  Android Developers
// To specify a custom Gradle version in Unity, go do “Preferences > External Tools”, uncheck “Gradle Installed with Unity (recommended)” and specify a path to a custom Gradle version
id ‘com.android.application’ version ‘7.1.2’ apply false
id ‘com.android.library’ version ‘7.1.2’ apply false
BUILD_SCRIPT_DEPS
}

task clean(type: Delete) {
delete rootProject.buildDir
}

Its already 7.1.2 but i did not see line com.android.tools.build:gradle:7.1.2

What is your current error? Make sure you set target api level to API 34 in player settings.