简体   繁体   中英

Unity fails to build and shows a gradle error for android

I am using Unity on a mac and trying to build my game on Android. The project builds fine on iOS and this is the first time i am trying to build it on Android. I get 2 errors - they seem to be related to gradle .

Gradle failed to fetch dependencies.

Failed to run '/Applications/MAMP/htdocs/BQvF/BQ/Temp/PlayServicesResolverGradle/gradlew --no-daemon -b "/Applications/MAMP/htdocs/BQvF/BQ/Temp/PlayServicesResolverGradle/PlayServicesResolver.scripts.download_artifacts.gradle" "-PANDROID_HOME=/Applications/Unity/Hub/Editor/2020.1.2f1/PlaybackEngines/AndroidPlayer/SDK" "-PTARGET_DIR=/Applications/MAMP/htdocs/BQvF/BQ/Assets/Plugins/Android" "-PMAVEN_REPOS=" "-PPACKAGES_TO_COPY=com.android.support:support-v4:25.3.1;com.android.support:appcompat-v7:25.3.1;com.android.support:cardview-v7:25.3.1;com.android.support:customtabs:25.3.1;com.parse.bolts:bolts-android:1.4.0;com.facebook.android:facebook-core:[7.1.0, 8);com.facebook.android:facebook-applinks:[7.1.0, 8);com.facebook.android:facebook-login:[7.1.0, 8);com.facebook.android:facebook-share:[7.1.0, 8);com.facebook.android:facebook-gamingservices:[7.1.0, 8)" "-PUSE_JETIFIER=0" "-PDATA_BINDING_VERSION=3.6.0"'
stdout:

stderr:
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
    at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
    
FAILURE: Build failed with an exception.

* What went wrong:
Could not create an instance of type org.gradle.initialization.DefaultSettings_Decorated.
> Could not initialize class org.codehaus.groovy.reflection.ReflectionCache

* 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 2s

And the second error is

Unable to determine which Android packages are installed.
Failed to run '/Applications/Unity/Hub/Editor/2020.1.2f1/PlaybackEngines/AndroidPlayer/SDK/tools/bin/sdkmanager --list --verbose'
stdout:

stderr:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 5 more

exit code: 1

Did you install NDK? Go to preferences in unity and check whether you have the path for NDK i'll provide a link for a tutorial on how to build an apk You can watch that check whether you are doing everything correctly or not https://youtu.be/j0L3SDYyMJI

To fix this i did 2 things:

  1. updated Gradle to 5.5.1, and
  2. Unity didnt recognise the newer Java I installed. So i deleted all JDKs, and then only installed 1.8

Works like a charm

If you are using Custom Keystore in Project Settings -> Player -> Publishing Settings, enter your passwords in the both fields. Then go to Assets -> External Dependency Manager -> Android Resolver -> Force Resolve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM