简体   繁体   English

Unity 无法构建并显示 android 的 gradle 错误

[英]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.我在 Mac 上使用 Unity 并尝试在 Android 上构建我的游戏。 The project builds fine on iOS and this is the first time i am trying to build it on Android.该项目在 iOS 上构建良好,这是我第一次尝试在 Android 上构建它。 I get 2 errors - they seem to be related to gradle .我收到 2 个错误 - 它们似乎与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?安装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 Go 统一首选项并检查您是否有 NDK 的路径 我将提供有关如何构建 apk 的教程的链接 您可以观看检查您是否正确执行所有操作 https://youtu.be/ j0L3SDYyMJI

To fix this i did 2 things:为了解决这个问题,我做了两件事:

  1. updated Gradle to 5.5.1, and将 Gradle 更新到 5.5.1,以及
  2. Unity didnt recognise the newer Java I installed. Unity 无法识别我安装的较新的 Java。 So i deleted all JDKs, and then only installed 1.8所以我删除了所有的JDK,然后只安装了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.然后 go 到 Assets -> External Dependency Manager -> Android Resolver -> Force Resolve。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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