Bug 50354 - Deployment stuck at zipalign.exe
Summary: Deployment stuck at zipalign.exe
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 7.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2016-12-18 19:55 UTC by p.frass
Modified: 2017-12-07 23:01 UTC (History)
20 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

Output log of Visual Studio build (20.96 KB, text/plain)
2016-12-18 19:55 UTC, p.frass
Xamarin Logs (4.61 KB, application/x-zip-compressed)
2017-03-30 16:16 UTC, Jeremy Kolb

Description p.frass 2016-12-18 19:55:44 UTC
Created attachment 18915 [details]
Output log of Visual Studio build

When I try to deploy my app to my phone, the process gets stuck at the zipalign.exe
The app is definitely working, because deployment on an emulator is working fine.
Comment 1 Jeremy Kolb 2017-03-30 16:14:25 UTC
I see this too.  Sometimes builds are stuck at the zipalign step for over 2 minutes.

2>C:\Users\jkolb\AppData\Local\Android\android-sdk\build-tools\25.0.2\zipalign.exe 4 "C:\Projects\EugsClient\EugsClient\EugsClient.Droid\bin\Debug\com.ara.eugsclient-Signed-Unaligned.apk" "bin\Debug\\com.ara.eugsclient-Signed.apk"
Comment 2 Jeremy Kolb 2017-03-30 16:16:51 UTC
Created attachment 21078 [details]
Xamarin Logs
Comment 3 Jeremy Kolb 2017-03-30 18:19:58 UTC
Jonathan Pryor,

This isn't an issue with zipalign.  It appears to be during the deploy process.  Build output hangs for minutes at the end of the following output:

2>C:\Users\jkolb\AppData\Local\Android\android-sdk\build-tools\25.0.2\zipalign.exe 4 "C:\Projects\EugsClient\EugsClient\EugsClient.Droid\bin\Debug\com.ara.eugsclient-Signed-Unaligned.apk" "bin\Debug\\com.ara.eugsclient-Signed.apk" 
2>Deleting file "C:\Projects\EugsClient\EugsClient\EugsClient.Droid\bin\Debug\com.ara.eugsclient-Signed-Unaligned.apk".
2>Detecting installed packages...
2>Copying application to device...
2>10% ... 960kb of 9531kb copied
2>20% ... 1920kb of 9531kb copied
2>30% ... 2880kb of 9531kb copied
2>40% ... 3840kb of 9531kb copied
2>50% ... 4800kb of 9531kb copied
2>60% ... 5760kb of 9531kb copied
2>70% ... 6720kb of 9531kb copied
2>80% ... 7680kb of 9531kb copied
2>90% ... 8640kb of 9531kb copied
2>100% ... 9531kb of 9531kb copied
Comment 4 soorosh_abi@hotmail.com 2017-03-31 05:37:52 UTC

I have the same problem, and zipalign.exe never finished.
Comment 5 Jeremy Kolb 2017-03-31 13:56:55 UTC
I may have a workaround (or it's the root of the problem?).  If you go into your developer settings on the phone and uncheck the verify apps over usb/adb does that fix it?  I looked at the adb logs and the phone was spending minutes validating the support library with dex2oat.
Comment 6 soorosh_abi@hotmail.com 2017-03-31 15:31:59 UTC
I have this problem in emulator too, I check this in Visual Studio 2017 Enterprise 15.0.0+26228.10 with Xamarin
Comment 7 soorosh_abi@hotmail.com 2017-03-31 15:35:56 UTC
Visual Studio does not go further after zipalign.exe. and freez it.
Comment 8 soorosh_abi@hotmail.com 2017-04-02 07:50:25 UTC
I may have a workaround about this, If you install visual studio 2015 previously and uninstall it and install visual studio 2017, this problem raised, so for resolved this problem you must removed Xamarin and android sdk completely from your computer and install again visual studio 2017.
Comment 9 softlion 2017-04-07 09:17:35 UTC
Comment 10 soorosh_abi@hotmail.com 2017-05-26 15:30:30 UTC
Hi again, I still have this problem in Visual Studio 2017 15.2 with Xamarin please consider this problem as a bug and resolve it. thanks
Comment 11 Eduardo Carísio 2017-06-02 01:21:23 UTC
Same here...
Visual Studio 2017 15.2 with Xamarin
Comment 12 Heinrich Braasch 2017-06-02 02:27:59 UTC
Same here ...
For me this problem occurs when deploying to an ACTUAL device, directly after a clean build. It is fine on simulators. The deploy process waits up to at least 5 min at:
2>Copying application to device...
2>10% ... 832kb of 7688kb copied
2>20% ... 1600kb of 7688kb copied
2>30% ... 2368kb of 7688kb copied
2>40% ... 3136kb of 7688kb copied
2>50% ... 3904kb of 7688kb copied
2>60% ... 4672kb of 7688kb copied
2>70% ... 5440kb of 7688kb copied
2>90% ... 6976kb of 7688kb copied
2>100% ... 7688kb of 7688kb copied

I got these log output by setting Options=>Projects and Solutions => Build and Run => MSBuild project build output verbosity => Detailed

After a while it then carries on. Thereafter, if I do not clean the solution (forcing a clean build), the deploy happens fast.

This problem started occurring after a recent upgrade to latest version of VS (sitting currently at VS 2017 15.2 (26439.12)) Xamarin

This is definitely a bug that PLEASE needs some serious attention.
Comment 13 Cody Beyer (MSFT) 2017-06-13 21:55:45 UTC
Confirming this issue as it is periodically reproducible on my system. Unclear at this point if the issue falls within the purview of Android or the Visual Studio extension (issue does not occur using VS for Mac)
Comment 14 Jan Göltenboth 2017-06-23 16:39:45 UTC
I'm facing the same issue with VS 15.2 and the latest preview of VS2017. I tried both, the latest android sdk v26 and v25..none of these worked. The first time after reinstalling either 15.2 or preview the deployment works once but starts hanging in the future deployments.
Comment 15 Lance 2017-06-23 17:06:25 UTC
For anyone having issues here still, try this: (I think this was how I fixed it.)

- Uninstall the app from the physical device you're trying to deploy to,
- Turn off, and restart the device,
- Then clean and rebuild/redeploy after the device has restarted

NOTES: This issue only happened on physical devices for me, although you might try these steps with the emulator as well if you're having issues there.

I believe I ended up reading somewhere that this issue occurs in corner-case situations when the build/deploy process gets hung trying to locate the old version of the app before installing the new one.

If these steps fix your issue, make sure in the future that when you build/deploy, that the device is UNLOCKED. The lock screen seems to be an issue at play here.

Hope this helps someone.
Comment 16 Jan Göltenboth 2017-06-23 17:14:32 UTC
@Lance thanks for your help. I remember that I've exactly applied your steps earlier today when the deployment worked (once). I thought it could deploy due to the re-installation of VS 15.2 / 15.3 preview. But once the deployment succeeded it did not work a second or third time. I assume I'd have to go through your steps before each deployment :-/... I'll test your suggestion and provide feedback later on.
Comment 17 Jan Göltenboth 2017-06-23 20:42:52 UTC
I can confirm the steps suggested by @Lance are a valid workaround for now till its fixed.

In my case the app hangs at one of these deployment steps (without applied steps from above):

 > Project "***.csproj" (Install target(s)):
 > 5>C:\Program Files (x86)\Android\android-sdk\build-tools\25.0.3\zipalign.exe 4 "C:\repos\***\src\***\***.Mobile.Android\bin\Debug\com.***.***-Signed-Unaligned.apk" "bin\Debug\\com.poinfo.mobile-Signed.apk" 

I am currently using the following configuration:
 > VS: 2017, 15.2 (26430.14)
 > Build-Tools: 25.0.3
 > Xamarin:
 > Xamarin.Android.SDK:

As already mentioned, deployment only works when following these steps (Step 1 and 2 may be switched):
 1. Delete app on device
 2. Restart device
 3. Clean Android solution
 4. Deploy

Since this issue also appears on my VS 15.0 instance (which worked fine in the past), I assume the problem is somewhere in the android tooling or some cached magic which I am not aware of :-)....
Comment 18 Cliff Hudson 2017-06-30 22:47:30 UTC
I was also having this problem with the emulator.  There was another version of the app with the same name on the emulator.  In Settings on the emulated device, I uninstalled the app and was then able to successfully deploy the app.

My Setup:

Microsoft Visual Studio Community 2017 
Version 15.2 (26430.14) Release
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Community

Visual Basic 2017   00369-60000-00001-AA202
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA202
Microsoft Visual C# 2017

Visual C++ 2017   00369-60000-00001-AA202
Microsoft Visual C++ 2017

Visual F# 4.1   00369-60000-00001-AA202
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package   8.6.00404.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.30503.0
ASP.NET and Web Tools 2017

ASP.NET Web Frameworks and Tools 2017   5.2.50303.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.0.30209.0
Azure App Service Tools v3.0.0

Common Azure Tools   1.9
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

KofePackagePackage Extension   1.0
KofePackagePackage Visual Studio Extension Detailed Info

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50131.1

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.3.50417.1
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager   4.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

SQL Server Data Tools   15.1.61702.140
Microsoft SQL Server Data Tools

Syntax Highlighting Pack   2.7.125
Adds syntax highlighting and snippet support for a wide variety of programming languages such as Clojure, Go, Jade, Lua, Swift, Ruby and many more...

TypeScript tools for Visual Studio

Visual Studio tools for CMake   1.0
Visual Studio tools for CMake

Visual Studio Tools for Unity
Visual Studio Tools for Unity

Xamarin (fec6f88)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK (9dbc4c5)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK (ad35de4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Comment 19 Jon Douglas [MSFT] 2017-07-14 15:48:48 UTC
Does anyone CC'd on this bug have a reproduction project that demonstrates this behavior? Although I've ran into this in the past, it's typically because of another hang in the deployment process and zipalign is the last task in APK creation. i.e. zipalign is ran after the APK is signed. I have however seen reports where zipalign is the hanging process and it actually fails internally, but we do not exit from it as soon as it fails.

This perhaps could be fixed using apksigner as per my bug report here: https://bugzilla.xamarin.com/show_bug.cgi?id=57914

I'm asking for any additional help in pinpointing this issue as it's not a 100% reproducible situation. Basically once I can get a reproduction project or at least an environment in which I can reproduce, I can dig further into this MSBuild target/task and indicate whether zipalign is working / failing and see what's going on for these situations where there is a hang.
Comment 20 Jeremy Kolb 2017-07-14 15:55:53 UTC
I don't think the reproduction of this bug is project based.  It seems to happen to me intermittently and/or gets progressively worse.

I've seen a few cases where the device spends AGES verifying the APK while Xamarin reports that it's stuck at zipalign.
Comment 21 Lance 2017-07-14 16:11:16 UTC
Agree with Jeremy.

Additionally, my suspicion tells me that this is likely due to the way the device stops/restarts the app. It seems that this happens most commonly when the build process begins looking for the currently installed app, in order to kill and replace it's installation. Almost as if it's looking for a running instance that doesn't exist. I believe that's why restarting the physical device seems to solve the issue. Some sort of identifier mismatch maybe?

I can't substantiate my claims yet, but when I have some downtime I will try to investigate and repro the issue through corner case actions, etc.
Comment 22 Philipp Sumi 2017-08-07 16:02:32 UTC
As far as repro projects go: I'm seeing this on my main dev machine while I don't have the issue on my laptop, so this seems to be an environment or Xamarin issue.
Comment 23 softlion 2017-08-07 16:12:00 UTC
I can repro this when:
- using android emus
- no emu is launched
- using ctrl F5

The common pattern is that
The emu is not launched
When it happens.
Comment 24 softlion 2017-08-09 17:35:42 UTC
Log when it happens:

1>  Found AndroidNdk at C:\Dev\android-sdk
1>  Found AndroidTools at C:\Dev\android-sdk\tools
1>DEBUG RunShellCommand emulator-5554 getprop
1>TASK: GetProperties getprop completed?:[dalvik.vm.dex2oat-Xms]: [64m]
1>[dalvik.vm.dex2oat-Xmx]: [512m]
1>[dalvik.vm.heapsize]: [384m]

(locked here, only way to go out is CTRL-BREAK)
Comment 25 softlion 2017-08-15 06:55:10 UTC
Same problem with 15.3

Only on first start of emulator 
Emulator settings:

(Android 5.1 API 22 Google version)

avd.ini.displayname=Nexus 5X API 22
hw.device.name=Nexus 5X
tag.display=Google APIs
Comment 27 Alper Ebicoglu 2017-09-25 07:49:36 UTC
i have solved the problem with  removing Bin & Obj output folders. by the way sometimes installed app should be uninstalled from target device (if signature of apk has changed)

Note You need to log in before you can comment on or make changes to this bug.