Search Unity

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

Discussion in 'Android' started by SAunAbbas, Aug 2, 2021.

  1. SAunAbbas

    SAunAbbas

    Joined:
    Jul 9, 2018
    Posts:
    3
    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 <queries> found in <manifest>."
    • "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."
    • "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.
    PublishingSettings.png ConsoleErrors.png EnvironmentVariables.png
     

    Attached Files:

    Last edited: Aug 2, 2021
  2. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    This is the actual error. You've got queries element in a wrong place in one of your manifests/template manifests.
     
    SAunAbbas likes this.
  3. SAunAbbas

    SAunAbbas

    Joined:
    Jul 9, 2018
    Posts:
    3
    @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...ected-element-queries-found-in-manifest-error
    https://answers.unity.com/questions/1804912/aapt-error-unexpected-element-queries-found-in-man.html

    Stay Blessed...!
     
    qenious, nimene505, JoWenk and 7 others like this.
  4. unity_RLHHrFVCu6Rtfg

    unity_RLHHrFVCu6Rtfg

    Joined:
    Oct 30, 2019
    Posts:
    1
    yes , Solved....
    Thank you so much!
     
  5. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,968
    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.
     
    Last edited: May 10, 2022
    SAunAbbas likes this.
  6. jeremyrcook

    jeremyrcook

    Joined:
    Feb 12, 2021
    Posts:
    3
    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.
     
  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    You can try increasing the JVM memory in Unity's preferences (I think it's external tools)
     
  8. tibtibc

    tibtibc

    Joined:
    Feb 11, 2019
    Posts:
    2
    Hello,
    Exactly the same error... I also try to increase the JVM memory but not better...
    Do you have any clues ?
     
  9. youngmusa

    youngmusa

    Joined:
    Apr 15, 2018
    Posts:
    13
    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!
     
  10. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    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. :(

    Screenshot 2023-06-28 at 4.23.32 pm.png

    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 <uses-permission> found in <manifest><application>.


    Any ideas? I'm building to this version. In Unity 2021.3.23f1
    Screenshot 2023-06-28 at 4.37.00 pm.png

    Thanks,
    P
     
  11. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,968
    Share the complete manifest file as seems like you entered uses-permission attribute in wrong place.
     
  12. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Ahhh okay, it looks like an old Prime 31 asset was creating the Manifest file :rolleyes:
    Working now, thanks :)
     
    Voxel-Busters likes this.
  13. elijahdoesVr

    elijahdoesVr

    Joined:
    Aug 1, 2023
    Posts:
    1
    it wont work and i dont know how to change it to com.ndroid.tools.build:gradle:3.4.3
     
  14. michaelorji713

    michaelorji713

    Joined:
    Jul 22, 2019
    Posts:
    4
    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>.

    Code (CSharp):
    1. manifest xmlns:android="http://schemas.android.com/apk/res/android"
    2.     xmlns:tools="http://schemas.android.com/tools"
    3.     package="com.facebook.common" >
    4.  
    5.     <uses-sdk
    6.         android:minSdkVersion="15"
    7.         android:targetSdkVersion="31" />
    8.  
    9.     <queries>
    10.         <package android:name="com.facebook.katana" />
    11.     </queries>
    12.  
    13.     <application>
    14.         <activity
    15.             android:name="com.facebook.FacebookActivity"
    16.             android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    17.             android:theme="@style/com_facebook_activity_theme" />
    18.         <activity android:name="com.facebook.CustomTabMainActivity" />
    19.         <activity
    20.             android:name="com.facebook.CustomTabActivity"
    21.             android:exported="true"
    22.             tools:node="merge" >
    23.             <intent-filter>
    24.                 <action android:name="android.intent.action.VIEW" />
    25.  
    26.                 <category android:name="android.intent.category.DEFAULT" />
    27.                 <category android:name="android.intent.category.BROWSABLE" />
    28.  
    29.                 <data
    30.                     android:host="cct.${applicationId}"
    31.                     android:scheme="fbconnect" />
    32.             </intent-filter>
    33.         </activity>
    34.     </application>
    35.  
    36. </manifest>
    This is the manifest file
     
  15. michaelorji713

    michaelorji713

    Joined:
    Jul 22, 2019
    Posts:
    4
    Please how did you fix this?