简体   繁体   English

尝试在 Unity3d 中构建 Android 版本时遇到问题

[英]I have a issue when trying to build Android version in Unity3d

I have tried building my app in Unity3d in both Gradle and Internal but both times I get errors at the end of building processes.我曾尝试在 Unity3d 中的 Gradle 和 Internal 中构建我的应用程序,但两次在构建过程结束时都出现错误。 I also have some plugins in my app so I tried changing SDK and made sure all the plugins are imported into my assets but that didn't help.我的应用程序中还有一些插件,所以我尝试更改 SDK 并确保所有插件都导入到我的资产中,但这没有帮助。

Error when build system is Gradle:构建系统为 Gradle 时出错:

CommandInvokationFailure: Gradle build failed. 
C:/Program Files/Java/jdk1.8.0_181\bin\java.exe -classpath 



"C:\ProgramFiles\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\
gradle\li 
b\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "- 
Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"

stderr[
Note: C:\Users\Hendrik\Desktop\POOWA- 
master\Temp\gradleOut\src\main\java\com\google\unity\ads\Banner.java uses or 
overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformDexWithDexForRelease'.
> com.android.build.api.transform.TransformException: 
com.android.ide.common.process.ProcessException: 
java.util.concurrent.ExecutionException: 
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 
65536

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or -- 
debug option to get more log output.

* Get more help at https://help.gradle.org

Error when build system is Internal:构建系统为内部时出错:

CommandInvokationFailure: Failed to re-package resources.
E:\sdkandroid\build-tools\27.0.3\aapt.exe package --auto-add-overlay -v -f - 
m -J "gen" -M "AndroidManifest.xml" -S "res" -I 
"E:/sdkandroid\platforms\android-28\android.jar" -F bin/resources.ap_ -- 
extra-packages 

These are not complete errors, but I think these still should show what's wrong.这些不是完整的错误,但我认为这些仍然应该表明什么是错误的。 I could also provide more if needed.如果需要,我也可以提供更多。

Have you tried this?你试过这个吗?

Android environment setup Whether you're building an Android application in Unity or programming it from scratch, you must set up the Android Software Development Kit (SDK) before you can build and run any code on your Android device. Android 环境设置 无论您是在 Unity 中构建 Android 应用程序还是从头开始编程,您都必须先设置 Android 软件开发工具包 (SDK),然后才能在您的 Android 设备上构建和运行任何代码。

  1. Install the Java Development Kit Download and install the Java Development Kit (JDK).安装 Java 开发工具包 下载并安装 Java 开发工具包 (JDK)。 Unity requires the 64-bit version JDK 8 (1.8). Unity 需要 64 位版本的 JDK 8 (1.8)。

  2. Download the Android SDK You can install the Android SDK using command line tools orthrough Android Studio.下载 Android SDK 您可以使用命令行工具或通过 Android Studio 安装 Android SDK。 Android Studio provides an easy to use GUI based tool, but installs additional software on your computer. Android Studio 提供了一个易于使用的基于 GUI 的工具,但会在您的计算机上安装其他软件。 Using the command line tools is a smaller download and does not install additional software, but it can be more challenging to use.使用命令行工具的下载量较小,不会安装额外的软件,但使用起来可能更具挑战性。

2a. 2a. Install the Android SDK using the command line tools Install or unpack the Android SDK.使用命令行工具安装 Android SDK 安装或解压 Android SDK。 After installing, open the Android SDK Manager and add: at least one Android SDK Platform, the Platform Tools, the Build Tools, and the USB drivers if you're using Windows.安装后,打开 Android SDK 管理器并添加:至少一个 Android SDK 平台、平台工具、构建工具和 USB 驱动程序(如果您使用的是 Windows)。

To install an Android platform SDK and the associated tools:要安装 Android 平台 SDK 和相关工具:

Download the Android Software command line tool.下载 Android 软件命令行工具。

Unzip the tools folder to a location on your hard drive.将工具文件夹解压缩到硬盘驱动器上的某个位置。

Open a command-prompt window.打开命令提示符窗口。

Navigate to the bin folder in the location where you unzipped the tools folder: “install folder” > tools > bin导航到解压工具文件夹所在位置的 bin 文件夹:“安装文件夹”>“工具”>“bin”

Use the sdkmanager command line tool to retrieve the list of packages that you can install.使用 sdkmanager 命令行工具检索可以安装的软件包列表。 The installable packages include the Platform SDKs, Build Tools, Platform tools, and other tools.可安装包包括平台 SDK、构建工具、平台工具和其他工具。

sdkmanager –list sdkmanager – 列表

Select a version of the Platform SDK to install.选择要安装的 Platform SDK 版本。 Platform SDKs take the following form in the list: platforms;android-xx.平台 SDK 在列表中采用以下形式:platforms;android-xx。 The xx indicates the SDK level. xx 表示 SDK 级别。 The larger the number, the newer the package.数字越大,包越新。 Typically, you can install the latest available version.通常,您可以安装最新的可用版本。 But, there might be cases in which Google has released a new version of the SDK that causes errors when you build your Unity Project.但是,在某些情况下,Google 发布了新版本的 SDK,这会导致您在构建 Unity 项目时出错。 In that case you must uninstall the SDK and install an earlier version.在这种情况下,您必须卸载 SDK 并安装早期版本。 The general format of the command for package installation is sdkmanager .软件包安装命令的一般格式为 sdkmanager 。 You can install the corresponding Platform Tools and Build Tools at the same time.您可以同时安装相应的平台工具和构建工具。

Example: sdkmanager “platform-tools” “platforms;android–27” “build-tools;27.0.3”示例:sdkmanager “platform-tools” “platforms;android–27” “build-tools;27.0.3”

If you are running on Windows, install the USB device drivers.如果您在 Windows 上运行,请安装 USB 设备驱动程序。

sdkmanager “extras;google;usb_driver” sdkmanager “附加功能;谷歌;usb_driver”

This installs the SDK in a directory named “platforms” in the directory in which you unzipped the tools folder.这会将 SDK 安装在解压缩工具文件夹的目录中名为“platforms”的目录中。 Example: c:\\\\platforms示例:c:\\\\平台

2b. 2b. Install the SDK using Android Studio Install Android studio from the Android developer portal.使用 Android Studio 安装 SDK 从 Android 开发人员门户安装 Android Studio。 The Android developer portal provides detailed installation instructions. Android 开发人员门户提供了详细的安装说明。

When installing the Android platform SDK and other tools, you can typically install the latest available version.在安装 Android 平台 SDK 和其他工具时,您通常可以安装最新的可用版本。 There might be cases in which Google has released a new version of the SDK that causes errors when you build your Unity Project.在某些情况下,Google 发布了新版本的 SDK,这会导致您在构建 Unity 项目时出错。 In that case you must uninstall the SDK and install an earlier version.在这种情况下,您必须卸载 SDK 并安装早期版本。

Install the associated Platform and Build tools at the same time.同时安装相关的平台和构建工具。 If you are running on Windows, install the USB device drivers.如果您在 Windows 上运行,请安装 USB 设备驱动程序。

  1. Enable USB debugging on your device To enable USB debugging, you must enable Developer options on your device.在您的设备上启用 USB 调试 要启用 USB 调试,您必须在您的设备上启用开发人员选项。 To do this, find the build number in your device's Settings menu.为此,请在设备的“设置”菜单中找到版本号。 The location of the build number varies between devices.内部版本号的位置因设备而异。 The stock Android setting can be found by navigating to Settings > About phone > Build number.可以通过导航到“设置”>“关于手机”>“版本号”找到常用的 Android 设置。 For specific information on your device and Android version, refer to your hardware manufacturer.有关您的设备和 Android 版本的具体信息,请咨询您的硬件制造商。

Build number as displayed in Android 5.0 (Lollipop) on a Samsung Galaxy Note 3 Build number as displayed in Android 5.0 (Lollipop) on a Samsung Galaxy Note 3 Note: On Android versions prior to 4.2 (Jelly Bean), the Developer options aren't hidden.在三星 Galaxy Note 3 上的 Android 5.0 (Lollipop) 中显示的内部版本号在三星 Galaxy Note 3 上的 Android 5.0 (Lollipop) 中显示的内部版本号 注意:在 4.2 (Jelly Bean) 之前的 Android 版本上,开发人员选项是'隐藏。 Go to Settings > Developer options, then enable USB debugging.转到设置 > 开发人员选项,然后启用 USB 调试。

After you navigate to the build number using the instructions above, tap on the build number seven times.使用上述说明导航到内部版本号后,点击内部版本号七次。 A pop-up notification saying “You are now X steps away from being a developer” appears, with “X” being a number that counts down with every additional tap.出现一个弹出通知,上面写着“你现在离成为开发者还有 X 步之遥”,其中“X”是一个数字,每次点击都会倒计时。 On the seventh tap, Developer options are unlocked.在第七次点击时,开发人员选项被解锁。

Connect your device to your computer using a USB cable.使用 USB 数据线将您的设备连接到计算机。 If you are developing on a Windows computer, you might need to install the a device specific USB driver.如果您在 Windows 计算机上进行开发,则可能需要安装特定于设备的 USB 驱动程序。 See the manufacture web site for your device for additional information.有关其他信息,请参阅您设备的制造商网站。

The setup process differs for Windows and macOS, and is explained in detail on the Android developer website. Windows 和 macOS 的设置过程有所不同,Android 开发者网站上有详细说明。 For more information on connecting your Android device to the SDK, refer to the Running Your App section of the Android Developer documentation.有关将您的 Android 设备连接到 SDK 的更多信息,请参阅 Android 开发人员文档的运行您的应用程序部分。

Go to Settings > Developer options, and check the USB debugging checkbox to enable debug mode when the device is connected to a computer via USB.转到设置 > 开发人员选项,然后选中 USB 调试复选框以在设备通过 USB 连接到计算机时启用调试模式。

Developer options as displayed in Android 5.0 (Lollipop) - Samsung Galaxy Note 3 Developer options as displayed in Android 5.0 (Lollipop) - Samsung Galaxy Note 3 4. Configure the Android SDK path in Unity The first time you create a Project for Android (or if Unity later fails to locate the SDK), Unity asks you to locate the folder in which you installed the Android SDK. Android 5.0 (Lollipop) - Samsung Galaxy Note 3 中显示的开发者选项 Android 5.0 (Lollipop) - Samsung Galaxy Note 3 中显示的开发者选项 4. 在 Unity 中配置 Android SDK 路径 第一次为 Android 创建项目(或如果 Unity 后来无法找到 SDK),Unity 会要求您找到安装 Android SDK 的文件夹。

If you installed the SDK using the sdkmanager, you can find the folder in \\platforms\\.如果您使用 sdkmanager 安装了 SDK,您可以在 \\platforms\\ 中找到该文件夹​​。

Example:例子:

c:\\\\platforms\\android–27 c:\\\\平台\\android–27

If you installed the SDK when you installed Android Studio, you can find the location in the Android Studio SDK Manager.如果您在安装 Android Studio 时安装了 SDK,您可以在 Android Studio SDK Manager 中找到该位置。 To open the SDK Manager from Android Studio, click Tools > Android > SDK Manager or click SDK Manager in the toolbar.要从 Android Studio 打开 SDK 管理器,请单击工具 > Android > SDK 管理器或单击工具栏中的 SDK 管理器。

SDK Manager toolbar button SDK Manager toolbar button To change the location of the Android SDK, in the menu bar go to Unity > Preferences > External Tools. SDK 管理器工具栏按钮 SDK 管理器工具栏按钮 要更改 Android SDK 的位置,请在菜单栏中转到 Unity > Preferences > External Tools。

  1. Download and set up the Android NDK If you are using the IL2CPP scripting backend for Android, you need the Android Native Development Kit (NDK).下载并设置 Android NDK 如果您使用的是 Android 的 IL2CPP 脚本后端,则需要 Android 本机开发工具包 (NDK)。 It contains the toolchains (such as compiler and linker) needed to build the necessary libraries, and finally produce the output package (APK).它包含构建必要库所需的工具链(例如编译器和链接器),并最终生成输出包(APK)。 If you are not targeting the IL2CPP back end, you can skip this step.如果您的目标不是 IL2CPP 后端,则可以跳过此步骤。

Download Android NDK version r13b (64-bit) from the NDK Downloads web page.从 NDK 下载网页下载 Android NDK 版本 r13b(64 位)。 Extract the android-ndk folder to a directory on your computer and note the location.将 android-ndk 文件夹解压缩到您计算机上的目录并记下位置。

The first time you build a Project for Android using IL2CPP, you are asked to locate the folder in which you installed the Android NDK.首次使用 IL2CPP 为 Android 构建项目时,系统会要求您找到安装 Android NDK 的文件夹。 Select the root folder of your NDK installation.选择 NDK 安装的根文件夹。 To change the location of the Android NDK, in the Unity Editor, navigate to the menu: Unity > Preferences to display the Unity Preferences dialog box.要更改 Android NDK 的位置,请在 Unity Editor 中导航至菜单:Unity > Preferences 以显示 Unity Preferences 对话框。 Here, click External Tools.在这里,单击外部工具。

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

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