Android Build and Run not working - Error.

Hi, I’m trying to build and run a simple scene to my android phone.
The scene is just a camera, light and a sphere.

Here’s the error:

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:/ProgramFiles/Unity/Hub/Editor/2019.3.0a12/Editor/Data/PlaybackEngines/AndroidPlayer\SDK\platform-tools\adb.exe
-s “b4d6d438” install -r -d “D:\Game Development\Unity\TestingAndroidBuild\build.apk”
stderr[ adb: failed to install D:\Game
Development\Unity\TestingAndroidBuild\build.apk:
Failure
[INSTALL_FAILED_USER_RESTRICTED:
Install canceled by user] ] stdout
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun
(UnityEditor.Utils.Program p,
UnityEdit Op
or.Android.Command+WaitingForProcessToExit
waitingForProcessToExit, System.String
errorMsg) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.Command.Run
(System.Diagnostics.ProcessStartInfo
psi,
UnityEditor.Android.Command+WaitingForProcessToExit
waitingForProcessToExit, System.String
errorMsg) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.Command.Run
(System.String command, System.String
args, System.String workingdir,
UnityEditor.Android.Command+WaitingForProcessToExit
waitingForProcessToExit, System.String
errorMsg) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.ADB.RunInternal
(System.String command,
UnityEditor.Android.Command+WaitingForProcessToExit
waitingForProcessToExit, System.String
errorMsg) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.ADB.Run
(System.String command,
UnityEditor.Android.Command+WaitingForProcessToExit
waitingForProcessToExit, System.String
errorMsg) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.AndroidDevice.Exec
(System.String command,
System.String errorMsg) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.AndroidDevice.Install
(System.String apkfile) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.AndroidDeploymentTargetsExtension+<>c__DisplayClass16_0.b__0 () (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.AndroidDeploymentTargetsExtension.UploadAPK
(UnityEditor.Android.AndroidBuildProperties
buildProperties,
UnityEditor.Android.AndroidDevice
device,
UnityEditor.Android.AndroidDeploymentTargetsExtension+LaunchProgressTaskManager
taskManager) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.AndroidDeploymentTargetsExtension+<>c__DisplayClass12_1.b__2
() (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.ProgressTaskManager.Run ()
(at
<2c7108252b3f412abf2ec8c94fb7c234>:0)
UnityEditor.Android.AndroidDeploymentTargetsExtension.LaunchBuildOnTarget
(UnityEditor.DeploymentTargets.IDeploymentTargetsMainThreadContext
context, UnityEditor.BuildProperties
buildProperties,
UnityEditor.DeploymentTargets.DeploymentTargetId
targetId, UnityEditor.ProgressHandler
progressHandler) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.DeploymentTargets.DeploymentTargetManager.LaunchBuildOnTarget
(UnityEditor.BuildProperties
buildProperties,
UnityEditor.DeploymentTargets.DeploymentTargetId
targetId, UnityEditor.ProgressHandler
progressHandler) (at
<2c7108252b3f412abf2ec8c94fb7c234>:0)
UnityEditor.PostprocessBuildPlayer+<>c__DisplayClass18_1.b__1
() (at
<2c7108252b3f412abf2ec8c94fb7c234>:0)
UnityEditor.ProgressTaskManager.Run ()
(at
<2c7108252b3f412abf2ec8c94fb7c234>:0)
UnityEditor.PostprocessBuildPlayer.LaunchOnTargets
(UnityEditor.BuildTargetGroup
targetGroup, UnityEditor.BuildTarget
buildTarget,
UnityEditor.Build.Reporting.BuildReport
buildReport,
System.Collections.Generic.List`1[T]
launchTargets) (at
<2c7108252b3f412abf2ec8c94fb7c234>:0)
UnityEditor.Android.PostProcessAndroidPlayer.Launch
(UnityEditor.BuildTarget target,
System.String installPath,
UnityEditor.Build.Reporting.BuildReport
report) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>:0)
UnityEditor.Android.AndroidBuildPostprocessor.LaunchPlayer
(UnityEditor.Modules.BuildLaunchPlayerArgs
args) (at
<8cd4d302de7a4b8a869bb3b9abf1c98a>: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
<2c7108252b3f412abf2ec8c94fb7c234>:0)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

Here’s a few things I’ve checked:

  • Unity 2019.3.0a12 installed with android support, android sdk & ndk and openjdk selected. Old versions of jdk and android studio and their folders removed.
  • Reinstalled unity to make sure I’ve included the sdk, ndk and jdk.
  • Build settings switched to Android. My android phone (Mi Max 3) set as the run device.
  • Developer mode, usb debugging and ptp via usb enabled on phone.
  • Project setting > Player > Package Name: com.Anthony.TestingAndroidBuild
  • Preference > External Tools > JDK, SDK, NDK and Gradle all Installed with Unity confirmed.
  • Tested on another PC with fresh install of Unity and included sdk, ndk and jdk…same errors.

Thanks for any help you can give, or recommendations for another tutorial to watch.

Hey there! I had same problem on my Xiaomi MI 8. In Dev-Mode window (in options) MIUI have option “install by USB”. It’s need to be turned on. By default it’s turned off.

This helped in my case.