当我正在尝试为我正在通过Unity开发的游戏构建apk文件时,Android SDK未正确安装错误?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当我正在尝试为我正在通过Unity开发的游戏构建apk文件时,Android SDK未正确安装错误?相关的知识,希望对你有一定的参考价值。

每次我尝试构建我的APK文件导出到我的android设备时,Unity给我一条错误消息,指出它无法构建apk文件,我应该确保Android sdk已正确配置。但是,我已经通过Oracle或Android工作室多次重新安装了最新的sdk但我仍然收到相同的错误消息。我可以在Unity编辑器中测试游戏,但每次尝试导出时都会遇到问题。它还在外部工具的首选项中声明我没有使用正确的android sdk工具和ndk工具,但是就像我说我已经多次尝试安装正确的那些甚至重新安装所有东西但我继续同样的错误。

有人可能知道我应该做什么吗?

这是我在Unity编辑器中打开项目时收到的错误消息:

DirectoryNotFoundException: Could not find a part of the path 'D:Androiduild-tools'.
System.IO.__Error.WinIOError (System.Int32 errorCode, System.String maybeFullPath) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.IO.FileSystemEnumerableIterator`1[TSource].HandleError (System.Int32 hr, System.String path) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.IO.FileSystemEnumerableIterator`1[TSource].CommonInit () (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.IO.FileSystemEnumerableIterator`1[TSource]..ctor (System.String path, System.String originalUserPath, System.String searchPattern, System.IO.SearchOption searchOption, System.IO.SearchResultHandler`1[TSource] resultHandler, System.Boolean checkHost) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.IO.FileSystemEnumerableFactory.CreateFileNameIterator (System.String path, System.String originalUserPath, System.String searchPattern, System.Boolean includeFiles, System.Boolean includeDirs, System.IO.SearchOption searchOption, System.Boolean checkHost) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.IO.Directory.InternalGetFileDirectoryNames (System.String path, System.String userPathOriginal, System.String searchPattern, System.Boolean includeFiles, System.Boolean includeDirs, System.IO.SearchOption searchOption, System.Boolean checkHost) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.IO.Directory.InternalGetDirectories (System.String path, System.String searchPattern, System.IO.SearchOption searchOption) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.IO.Directory.GetDirectories (System.String path) (at <23c160f925be47d7a4fd083a3a62c920>:0)
UnityEditor.Android.AndroidSDKTools.FindLatestBuildTools () (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.AndroidSDKTools.UpdateToolsDirectories () (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.AndroidSDKTools..ctor (System.String sdkRoot) (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.AndroidSDKTools.CreateAndroidSDKTools (System.String rootDir) (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.AndroidSDKTools.GetInstance[T] (UnityEditor.Android.AndroidSDKTools+InstanceCreator creator) (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.AndroidSDKTools.GetInstance () (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.SDKManager..ctor () (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.SDKManager.GetInstance () (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.Android.AndroidPreferenceWindowExtension.WritePreferences () (at <252f3c2244e6415190676e82842416b7>:0)
UnityEditor.PreferencesProvider.WritePreferences () (at C:/buildslave/unity/build/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:753)
UnityEditor.PreferencesProvider.ApplyChangesToPrefs (System.Boolean force) (at C:/buildslave/unity/build/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:472)
UnityEditor.PreferencesProvider.ShowExternalApplications (System.String searchContext) (at C:/buildslave/unity/build/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:347)
UnityEditor.PreferencesProvider.OnGUI (System.String searchContext, System.Action`1[T] drawAction) (at C:/buildslave/unity/build/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:298)
UnityEditor.PreferencesProvider+<CreateExternalToolsProvider>c__AnonStorey1.<>m__0 (System.String searchContext) (at C:/buildslave/unity/build/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:201)
UnityEditor.SettingsProvider.OnGUI (System.String searchContext) (at C:/buildslave/unity/build/Editor/Mono/Settings/SettingsProvider.cs:103)
UnityEditor.SettingsWindow.DrawControls () (at C:/buildslave/unity/build/Editor/Mono/Settings/SettingsWindow.cs:322)
UnityEditor.SettingsWindow.DrawSettingsPanel () (at C:/buildslave/unity/build/Editor/Mono/Settings/SettingsWindow.cs:313)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:298)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:483)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:466)
UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:447)
UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at C:/buildslave/unity/build/Modules/UIElements/Events/MouseCaptureDispatchingStrategy.cs:93)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at C:/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:280)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at C:/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:156)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at C:/buildslave/unity/build/Modules/UIElements/Panel.cs:189)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:255)
UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:78)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
This is the error message I get after the apk build and run has failed:
CommandInvokationFailure: Unable to install APK to device. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details.
    C:/Users/mauri/AppData/Local/Android/Sdkplatform-toolsadb.exe -s "2245120c5e0d7ece" install -r "C:UsersmauriDesktopBall Tapall tap.apk"

    stderr[
    adb: failed to install C:UsersmauriDesktopBall Tapall tap.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.BallTap.Momo signatures do not match previously installed version; ignoring!]
    ]
    stdout[
    Performing Streamed Install
    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.ADB.RunInternal (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.ADB.Run (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.AndroidDevice.Exec (System.String[] command, System.String errorMsg) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.AndroidDevice.Install (System.String apkfile) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.AndroidDeploymentTargetsExtension+<UploadAPK>c__AnonStorey3.<>m__0 () (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.AndroidDeploymentTargetsExtension.UploadAPK (UnityEditor.Android.AndroidBuildProperties buildProperties, UnityEditor.Android.AndroidDevice device, UnityEditor.Android.AndroidDeploymentTargetsExtension+LaunchProgressTaskManager taskManager) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.AndroidDeploymentTargetsExtension+<LaunchBuildOnTarget>c__AnonStorey0.<>m__2 () (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.ProgressTaskManager.Run () (at C:/buildslave/unity/build/Editor/Mono/Utils/ProgressBarUtils.cs:71)
    UnityEditor.Android.AndroidDeploymentTargetsExtension.LaunchBuildOnTarget (UnityEditor.DeploymentTargets.IDeploymentTargetsMainThreadContext context, UnityEditor.BuildProperties buildProperties, UnityEditor.DeploymentTargets.DeploymentTargetId targetId, UnityEditor.ProgressHandler progressHandler) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.DeploymentTargets.DeploymentTargetManager.LaunchBuildOnTarget (UnityEditor.BuildProperties buildProperties, UnityEditor.DeploymentTargets.DeploymentTargetId targetId, UnityEditor.ProgressHandler progressHandler) (at C:/buildslave/unity/build/Editor/Mono/DeploymentTargets/DeploymentTargetManager.cs:45)
    UnityEditor.PostprocessBuildPlayer+<LaunchOnTargets>c__AnonStorey1.<>m__0 () (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:203)
    UnityEditor.ProgressTaskManager.Run () (at C:/buildslave/unity/build/Editor/Mono/Utils/ProgressBarUtils.cs:71)
    UnityEditor.PostprocessBuildPlayer.LaunchOnTargets (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget buildTarget, UnityEditor.Build.Reporting.BuildReport buildReport, System.Collections.Generic.List`1[T] launchTargets) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:222)
    UnityEditor.Android.PostProcessAndroidPlayer.Launch (UnityEditor.BuildTarget target, System.String installPath, UnityEditor.Build.Reporting.BuildReport report) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.LaunchPlayer (UnityEditor.Modules.BuildLaunchPlayerArgs args) (at <252f3c2244e6415190676e82842416b7>:0)
    UnityEditor.PostprocessBuildPlayer.Launch (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget buildTarget, System.String path, System.String productName, UnityEditor.BuildOptions options, UnityEditor.Build.Reporting.BuildReport buildReport) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:166)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
答案
  • 确保您的Android SDK已正确设置。可能是您针对的是特定的Android版本,并且缺少该目标的SDK平台。

  • 检查您的统一信息是否具有正确的SDK路径。
另一答案

1 / Android SDK

在第一个输出中,看起来您的路径未正确设置。你检查过路径'D: Android build-tools'是否存在?

通常,使用Android Studio进行常规安装会将SDK安装到

c:Users<YOUR USER>AppDataLocalAndroidSdk

在Unity中,您可以通过转到编辑 - >首选项 - >外部工具以及设置Android SDK路径在Unity中设置此路径。

2 / Android SDK版本

确保您在Unity中定位的SDK版本(播放器设置 - >其他设置 - >最低API级别和目标API级别)与您使用Android Studio下载的SDK相同。

3 /注意有空格或不规则字符的路径

特别是在Windows上,这往往会在Android构建过程中产生很多问题。如果你可以避免它,我会推荐它。

4 /包名和签名

您的第二个错误显示“签名与以前安装的版本不匹配”。您可能已在设备上安装了已安装的版本,并使用其他密钥进行签名。您需要完全删除设备上的应用程序才能解决此问题。 See this post

另一答案

我遇到了同样的问题,即使我正确设置了sdk,错误也没有消失。以下是我如何解决它:转到手机中的设置 - >应用程序。卸载应用程序(应用程序的名称应该是Momo,我猜)。然后尝试再次从统一建立,现在它应该工作

以上是关于当我正在尝试为我正在通过Unity开发的游戏构建apk文件时,Android SDK未正确安装错误?的主要内容,如果未能解决你的问题,请参考以下文章

Unity:如何通过网络销毁游戏对象?

为我的 Unity 游戏制作一个 moddingAPI 并在没有直接引用的情况下调用函数

Unity2D 小行星风格游戏

Unity UI按钮不对点击或悬停做出反应

FPS 角色全身或手 Unity 3d

Unity - 在 RayCast 命中时的游戏对象定位没有剪辑