Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/Android/AndroidPlatform.Automation.cs
Josh Adams 1b81c281d4 Copying //UE4/Dev-Platform to //UE4/Dev-Main (Source: //UE4/Dev-Platform @ 3120366)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2714591 on 2015/10/02 by Ben.Marsh

	Initial branch of files from Engine-Main (//UE4/Engine-Main) to Dev-Platform (//UE4/Dev-Platform)

Change 2916715 on 2016/03/21 by Daniel.Lamb

	First pass at splitting out build cook run into into seperate scripts.

Change 2948322 on 2016/04/19 by Nick.Shin

	update libwebsockets to v1.7.4

	part 4 of 4 - doing this in stages for tracking purposes

	#jira UEPLAT-1246  -  Update libWebsockets
	#jira UEPLAT-1221  -  update websocket library
	#jira UEPLAT-1204  -  Rebuild libwebsockets with SSL

Change 2970016 on 2016/05/07 by Nick.Shin

	undo all of the following upgrades:
	- zlib
	- openssl
	- libcurl
	- libwebsockets

	and reset webrtc

	#jira UE-30298 - Fortnite and Orion crash on login

Change 3059693 on 2016/07/21 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3061151 on 2016/07/22 by Niklas.Smedberg

	Fast ASTC texture compression, using ISPC.

	#jira UE-32308

Change 3061428 on 2016/07/22 by Peter.Sauerbrei

	Back out changelist 3061151 as it wasn't approved for submission

Change 3061970 on 2016/07/22 by Steve.Cano

	Adding AdMob interstitital ad support for Android, including Blueprint functions

	#jira UE-33286
	#ue4
	#android

Change 3062160 on 2016/07/22 by Mark.Satterthwaite

	Fix the fix for handling RHISetStreamSource overriding stride on Metal - not all MTLVertexDescriptors are equally hashable so do this ourselves.
	#jira UE-33355

Change 3062770 on 2016/07/24 by Brent.Pease

	UE-32397 Error Message displays as Unknown Error when failing to supply a Remote Build server for ios on Windows

Change 3063227 on 2016/07/25 by Dmitry.Rekman

	Update hlslcc cross-compile after libc++ change.

Change 3063314 on 2016/07/25 by Jeff.Campeau

	Xbox One DLL loading
	Receipts can be read back by request for target info

Change 3063329 on 2016/07/25 by Mark.Satterthwaite

	CL #3046743 was breaking other samples in unexpected ways after a recent Main merge, so make a Metal-specific change to the shader instead and amend the MetalBackend to better match HLSL's handling of NaN/inf with common single-precision float intrinsics. This is sufficient to fix the AtmosphericFog and the recent regressions.
	#jira UE-33600
	#jira UE-33028
	#jira UE-27879
	#jira UE-25802

Change 3063492 on 2016/07/25 by Brent.Pease

	UE-23846 - iOS Movie Player can't handle videos at resolutions that aren't multiples of 16
	UE-33200 - A movie isn't played on iOS occasionally.

Change 3063729 on 2016/07/25 by Dmitry.Rekman

	Linux: enable XGE on all platforms.

	#tests Cross-compiled a number of Linux targets on Windows.

Change 3063732 on 2016/07/25 by Dmitry.Rekman

	Fixed formatting (spaces->tabs) in previous change.

Change 3063750 on 2016/07/25 by Daniel.Lamb

	Added code to dump the cook modification delegate loads to log.
	Fixed the memory usage output log.
	#test cook paragon.

Change 3063804 on 2016/07/25 by Daniel.Lamb

	Added cookpartialgc additional commandline option to uat.
	#test UFE

Change 3064008 on 2016/07/25 by Mark.Satterthwaite

	For non-shipping builds conditionally bind a default uniform buffer in Metal and report an error if the slot was unbound, if our validation layer is enabled attempt to report the shader source in question. This relies on the shader compiler providing accurate information about uniform buffer bindings and won't fix all occurances of bad uniform usage (if a buffer is bound but too short the result will be GPU restarts or an error in Apple's validation layer - we can't detect this case) but will help debug the typical error of leaving an active slot unbound.
	#jira FORT-27685

Change 3064141 on 2016/07/25 by Jeff.Campeau

	Rebuild vpxmd.lib with delayed codegen disabled (fixes linker warning building Win64).

Change 3065024 on 2016/07/26 by Nick.Shin

	Change filetype
	remove exclusive check out bit

	requested by or.coheni & nick.penwarden

Change 3065274 on 2016/07/26 by Jonathan.Fitzpatrick

	DirectoriesToAlwaysStageAsUFS now properly filters out *.uasset and *.umap files
	This prevents the bug where cooked assets get trampled by staging their uncooked version on top of them during the UFS step

	Added a file filter to DirectoriesToAlwaysStageAsUFS for uasset and umap.

Change 3066338 on 2016/07/27 by Mark.Satterthwaite

	Handle releasing an SRV/UAV & the source object within a single Metal command-buffer.
	#jira UE-33779

Change 3066789 on 2016/07/27 by Daniel.Lamb

	Realtime mode does not save any packages anymore unless they are ready.
	#test cookontheside, cookbythebook shooter game

Change 3066847 on 2016/07/27 by Jeff.Campeau

	Fix define
	#2634
	#jira UE-33813

Change 3068868 on 2016/07/28 by Mark.Satterthwaite

	Extend hlslcc's handling of switch-statements to allow implict casts from scalar bool, half & float as HLSL itself permits while also making sure it errors if the expression input is not scalar. This fixes shader compile errors in UT.

Change 3070040 on 2016/07/29 by Dmitry.Rekman

	Delete Nadzorca.

Change 3070947 on 2016/07/29 by Jeff.Campeau

	Perforce C++ API 2015.2 (includes debug libraries)

Change 3073707 on 2016/08/02 by Daniel.Lamb

	Derived data cache commandlet runs resolve string asset references to load any string asset refereced packages from the map.
	Also process async results from shaders being compiled so they can have their memory resources released.
	#test DerivedDataCache commandlet shootergame.

Change 3076613 on 2016/08/03 by Brent.Pease

	 + UnrealTargetConfiguration is now passed into deploy and package methods
	 + The UIRequiredDeviceCapabilities  plist key now only considers the architectures from the corresponding target configuration (shipping or development)

Change 3076668 on 2016/08/03 by Brent.Pease

	Back out changelist 3076613

Change 3077157 on 2016/08/04 by Daniel.Lamb

	Fixed up DLC staging so that it stages to the proper mount point.
	Fixes up include engine content in DLC staging paths.
	#test Made up shooter game DLC

Change 3077191 on 2016/08/04 by Daniel.Lamb

	More smartly process async shader compilation if we are waiting for it.
	#test cook on the side shooter game cook by the book shooter game.

Change 3077412 on 2016/08/04 by Mark.Satterthwaite

	Fix "iOS Metal-based build crashes at launch with sub-levels":
	- Slate should not bind the null RHI texture from an unitialised texture atlas - atlases only have a valid texture pointer once an entry has been added to them and in the template projects an empty sub-level doesn't add anything.
	- To prevent this kind of bug resurfacing and being so hard to track down add Metal shader binding validation to our validation layer as Apple's is incomplete on iOS and won't warn us about nil texture usage which causes these GPU restarts. This requires reworking our vertex declaration handling to be more efficient so that we can cache the pipeline reflection data as well as the pipeline objects.
	- Fix validation error of texture reallocation on loading template projects under Metal.
	#jira UE-30847

Change 3077958 on 2016/08/04 by Brent.Pease

	 + UnrealTargetConfiguration is now passed into deploy and package methods
	 + The UIRequiredDeviceCapabilities  plist key now only considers the architectures from the corresponding target configuration (shipping or development)

Change 3079503 on 2016/08/05 by Mark.Satterthwaite

	Initialise more variable types to 0 in Metal shaders to workaround Xcode 8 toolchain no longer doing this for us for "threadgroup shared" variables. Everything but structs and atomic's will now be initialised.
	#jira UE-33856

Change 3079737 on 2016/08/05 by Jeff.Campeau

	Add support for delay load DLLs on Xbox One
	Turn off warnging for missing PDBs to match VCToolchain.cs

Change 3081005 on 2016/08/08 by Mark.Satterthwaite

	Fix-up Metal device name on AMD for macOS 10.12 which reports it correctly and enable tiled reflections on Intel from macOS 10.12 too as they now work.

Change 3081557 on 2016/08/08 by Daniel.Lamb

	File-> Package saves all packages before starting packaging.
	#test File package first person template

Change 3082215 on 2016/08/09 by Lee.Clark

	PS4 - Added 4k profile

Change 3082412 on 2016/08/09 by Daniel.Lamb

	Fixed cook on the fly server not handling cook requests.
	#test Cook on the fly shooter game.

Change 3082955 on 2016/08/09 by Dmitry.Rekman

	Linux: convert existing Strcat() uses to Strncat().

	- Strcat() does not check destination size so can silently corrupt memory. While this was not observed, this conversion removes this concern altogether.

Change 3083772 on 2016/08/10 by Luke.Thatcher

	[PLATFORM] [PS4] [+]
	Checking in PS4CrashHandler files so we have a copy in Perforce rather than just on the server.
	 - Taken from \\devweb-02 and removed all the unused files/dependencies.
	 - Created a publish profile pointing to \\devweb-02\Sites\PS4Services\PS4CrashHandlerDev so I'm not writing over the existing deployed crash handler.
	 - Moved all code in the Page_Load event to inside the check for the HTTP method (POST) otherwise GET'ing the page from a browser will generate crash folders that hang around forever.

Change 3085450 on 2016/08/11 by Lee.Clark

	PS4 - Fix mediaplayer pipeline allocation

Change 3086360 on 2016/08/11 by Michael.Trepka

	Fixed a non-unity build error in Mac UnrealFrontend

Change 3087224 on 2016/08/12 by Luke.Thatcher

	[PLATFORM] [PS4] [~]
	Refactor PS4 Crash Handler site
	 - Removed CoreDumpHandler. Processing dump files is handled directly by an async thread within the aspx process.
	 - Separated configuration values into their own class. Currently set to output to a testing directory, rather than the actual crash reporter landing zone.
	 - Added a debug upload page to allow manual submission of .orbisdmp/.txt settings files, accessible by GET'ing Default.aspx.
	 - Added logging. Logs self-delete after 30 days.

	Testing required before we switch to the new system.

	#jira UE-34504
	#jira OR-26886

Change 3087626 on 2016/08/12 by Dmitry.Rekman

	PR #2689: Fix copying/duplicating failing on Linux (UE-34586).

	- Contributed by Web-eWorks.

Change 3087991 on 2016/08/12 by Mark.Satterthwaite

	Initial AVFoundation implementation of Media Framework for Mac, iOS & tvOS.
	- Video playback occurs via AVPlayerItemVideoOutput's attached to the AVPlayerItem's output. This means gathering video samples is trivial.
	- Metal texture updates occur by wrapping the texture object provided by AVF - for Mac this is simple as it can bind to the IOSurface directly, for iOS/tvOS we have to create a CVMetalTextureCache and allocate our texture from there.
	- OpenGL and OpenGLES currently have to lock the pixel buffer and upload to a texture the old fashioned way - this should be revisited when there is time.
	- Subtitles/Captions are captured using AVPlayerItemLegibleOutput which also connects to the AVPlayerItem's output.
	- On Mac audio samples are returned by manually reading from the stream using an AVAssetReaderTrackOutput, including manual seeking and synching.
	- On iOS/tvOS the audio is played directly by AVPlayer because the IOSAudio system can't handle procedural buffers - otherwise it could reuse the Mac code.
	- AVFoundation does not support AVI - that's an obsolete Microsoft/Windows file-format.
	- Only 'file://' URLs are supported - streaming would require a totally different audio solution (using MTAudioProcessingTap) and has many more edge and failure cases that would need to be handled.
	#jira UE-34315

Change 3088790 on 2016/08/15 by Luke.Thatcher

	[PLATFORM] [PS4] [~]
	Hook new PS4 crash handler up to the crash reporter website.
	 - Removed indentation from generated crash context XML file. The crash reporter process does manual XML parsing which doesn't correctly handle whitespace at the start of lines.
	 - Switched the final output folder to match the one the crash reporter process is watching.
	 - Hide upload form on a config variable.

	#jira UE-34504
	#jira OR-26886

Change 3089060 on 2016/08/15 by Luke.Thatcher

	[PLATFORM] [PS4] [!]
	Change PS4 crash handler log file extension to ".ps4chlog", otherwise the crash reporter site attaches the wrong log file to the crash report.
	Allowed showing of debug upload form via "Default.aspx?showform=1" query string.

	#jira UE-34504
	#jira OR-26886

Change 3089089 on 2016/08/15 by Mark.Satterthwaite

	Duplicated changes to AppleMovieStreamer from CL #3088149.
	#jira UE-34315

Change 3089460 on 2016/08/15 by Mark.Satterthwaite

	Duplicate CL #3080971:
	Workaround a macOS 10.12 Beta bug on some Metal drivers that can't initialise temporary/local variable arrays, only those that are marked threadgroup shared.
	#jira UE-34355

Change 3089465 on 2016/08/15 by Mark.Satterthwaite

	For Metal shader translation retain more precision for float constants -1.0f >< 1.0f by emitting them in scientific notation - prevents Hammersley constant amongst others from being flushed to 0.

Change 3089902 on 2016/08/15 by Daniel.Lamb

	Changed the next compiling ID to the correct compiling ID.
	#test Cook

Change 3089903 on 2016/08/15 by Daniel.Lamb

	Cooker monitors config useage during cook and uses those settings to invalidate cooked content instead of all config settings.

Change 3090114 on 2016/08/16 by Luke.Thatcher

	[PLATFORM] [PS4] [~]
	Minor change to PS4 settings text on crash handler site.

Change 3090949 on 2016/08/16 by Nick.Shin

	WebSocketNetDriver crash fix

	filled in missing chunk of code that calls PacketHandler's "packet modifiers"

	#jira UE-25492   HTML5 Client cannot connect to Windows Server
	#jira UE-30880   WinServer crashes when NetDriver is set to WebSocket and Client attempts to connect via websocket
	#code.review john.pollard john.barrett

Change 3091265 on 2016/08/16 by Brent.Pease

	Add IOS support to HarfBuzz

Change 3091267 on 2016/08/16 by Brent.Pease

	Add references to fix mono build

Change 3091291 on 2016/08/16 by Nick.Shin

	CIS warning fix

	#jira UE-25492   HTML5 Client cannot connect to Windows Server
	#jira UE-30880   WinServer crashes when NetDriver is set to WebSocket and Client attempts to connect via websocket

Change 3091781 on 2016/08/17 by Joe.Barnes

	UE-33640: Exposed UPrimitiveComponent::IsAnyRigidBodyAwake() to Blueprints.

Change 3092687 on 2016/08/17 by Daniel.Lamb

	Added support for using binned allocator in cooker instead of tbb.
	#test Cook shootergame.

Change 3093867 on 2016/08/18 by Mark.Satterthwaite

	Use a read/write mutex to protect access to Metal's internal shader pipeline caches so that parallel threads can progress in the common case where new shaders are not being compiled.

Change 3093950 on 2016/08/18 by Mark.Satterthwaite

	Change the Mac GPU identification code to cope with AMD's new naming scheme on 10.12.

Change 3093951 on 2016/08/18 by Mark.Satterthwaite

	More SCW threads on Mac - they work now.

Change 3093960 on 2016/08/18 by Mark.Satterthwaite

	Increase the default number of command-buffers on Mac because bigger games overflow the current limit of 64 per queue.

Change 3096493 on 2016/08/22 by Jeff.Campeau

	Use Xbox version of DirectX include.

Change 3097509 on 2016/08/23 by Luke.Thatcher

	[PLATFORM] [PS4] [+]
	Refactor PS4 Symbol Publish
	 - Moved the SymStore task from Win.Automation to BuildGraph.Automation, and made it more generic.
	 - The specifics of uploading symbols are now implemented in the platform tool chain, alongside StripSymbols().
	 - Re-generated the build graph schema file.
	 - Removed the old PS4 symbols upload path in the package step.

	Modified OrionBuild.xml to publish symbols for all PS4 dev, test and shipping config builds of OrionClient.

Change 3097635 on 2016/08/23 by Luke.Thatcher

	[PLATFORM] [PS4] [+]
	Refactor Age Symbols task in UAT.
	 - Moved the AgeStore task from Win.Automation to BuildGraph.Automation and made it more generic.
	 - Symbol server directory structure is now defined by the platform tool chain, which the common task uses to clean out old symbols.
	 - Added a "filter" parameter to prevent age tasks deleting symbols from unrelated builds in shared symbol servers.

	Modified OrionBuild.xml to age both the Windows and PS4 symbol stores.

Change 3097713 on 2016/08/23 by Luke.Thatcher

	[PLATFORM] [PS4] [+]
	Enable new PS4 crash handler server
	 - Created live deployment profile and applied the required config file changes.

Change 3099214 on 2016/08/24 by Luke.Thatcher

	[PLATFORM] [PS4] [!]
	Fix compile error in PS4 tool chain. For some reason, this only breaks ocassionally. Maybe we're alternating between the 2013 and 2015 C# compilers depending on what initiates the build (e.g. Visual Studio vs GenerateProjectFiles)?

Change 3099222 on 2016/08/24 by Luke.Thatcher

	[PLATFORM] [PS4] [+]
	Added PS4 support for FPlatformMisc::MessageBoxExt using the MsgDialog library.
	 - Note, only one and two button message dialogs are supported (limitation of MsgDialog).

Change 3099260 on 2016/08/24 by Luke.Thatcher

	[PLATFORM] [PS4] [~]
	Better PS4 exit function. Calls quick_exit instead of abort when we've not asserted. Allows for a "cleaner" forced exit without generating a crash dump.

Change 3101192 on 2016/08/25 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3101944 on 2016/08/25 by Daniel.Lamb

	Ask to save the current level when we are using launch on.

Change 3102036 on 2016/08/25 by Nick.Shin

	check for minimum expected size upon data received from network

	#jira UE-13657 - HTML5 plugin OnRawRecieve overflow

Change 3102115 on 2016/08/25 by Brent.Pease

	 - Fix small errors that probably only show up in the mac mono build

	#code.review peter.sauerbrei

Change 3102747 on 2016/08/26 by Jeremiah.Waldron

	Re-submitting OnlineSubsystemGameCircle with TPS permission for Amazon SDK
	 - Also fixed the plugin to remove any related files from the final package when IAP is disabled or GameCircle support itself is disabled with the plugin still enabled
	 - Added support for new AlreadyOwned IAP response code as well which is already used for GooglePlay and IOS

Change 3102900 on 2016/08/26 by Nick.Shin

	since last checkin (CL: 2981945) - prints are crashing the browser - this change will allow browser to print the details via console.log()

	#jira UE-26047 - HTML5 HTTP Response Headers not implemented

Change 3103130 on 2016/08/26 by Brent.Pease

	UE-24679 - Enable the ability to change ports for a firewall to pass them through rsync

Change 3103225 on 2016/08/26 by Daniel.Lamb

	Fixed issue with warning which would cause crash.

Change 3103425 on 2016/08/26 by Dmitry.Rekman

	Enable offscreen GL rendering without X.

	- Added new video subsystem to SDL that is uses EGL to initialize the context.
	- Most windoing functions stubbed.
	- Also added a new test case to TestPAL for easier debugging.

Change 3104743 on 2016/08/29 by Brent.Pease

	Support remote offline metal shader compilation

Change 3105051 on 2016/08/29 by Brent.Pease

	UE-2382 - TASK: MobleMVP: iOS: Add ability to view iOS device console output in the editor UFE

	 - IOS Automation will now create a thread to collect the console logs from the device and send them to C# Console output while the app is running on device
	 - Made ProcessResult an interface (IProcessResult) which ProcessResult implements. This allows platforms to provide their own implementation if needed.
	 - Moved the RunLoop related parts of CoreFoundation into MobileDevice.cs

Change 3105053 on 2016/08/29 by Brent.Pease

	 - IOS dll's as part of the last check-in

Change 3106853 on 2016/08/30 by Jeff.Campeau

	Implement FD3D11DynamicRHI::RHICreateComputeFence to prevent memory overwrite

Change 3107361 on 2016/08/30 by Dmitry.Rekman

	Renderer: changes to allow postproc delegates.

Change 3107362 on 2016/08/30 by Dmitry.Rekman

	Plugin with a CUDA postproc example.

	- Linux version only. Runs under a headless GL too (without X).
	- Disabled during cross-compilation, can be compiled natively only.
	- CUDA kernel should be compiled separately, CMakefile with compilation attached (can be used to generate VStudio projects as well).
	- To test the output, run under the debugger, interrupt and set global variable GSaveTheOutput to 50 (this will write out kernel output buffer 50 times as .bmp files into working directory).

Change 3107913 on 2016/08/31 by Daniel.Lamb

	Fixed loading of cooked content in the editor.

Change 3107916 on 2016/08/31 by Daniel.Lamb

	Added error case when shader compilation fails to notify shader.
	#test Cook shooter game.

Change 3108080 on 2016/08/31 by Josh.Adams

	- Fixed PS4Automation compile errors

Change 3109077 on 2016/08/31 by Brent.Pease

	Fix C# debug builds by specifying x64 and add reference to MobileDeviceInterface

Change 3110086 on 2016/09/01 by Dmitry.Rekman

	Fix race condition in PThread runnable (UE-35074).

	- Instead of relying on busy-wait, join the threads. This prevents race between PostRun() (executed in the context of the thread) and FPThreadRunnableThread() destructor (see UE-34909).
	- Do not use an invalid value for pthread_t, since there's none.

Change 3110172 on 2016/09/01 by Dmitry.Rekman

	Fixed a crash exiting VR Preview on Windows GL4 (UE-28708).

	- PR #2188 submitted by ardneran.

Change 3110313 on 2016/09/01 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3111134 on 2016/09/01 by Dmitry.Rekman

	UBT: prevent mono from hanging on Ctrl-C.

	- Sometimes Ctrl-C can cause thread creation to fail. Without this change, UBT would lock up.

Change 3111171 on 2016/09/01 by Brent.Pease

	Move all C# projects to use the x64 Platform for consistency with other changes made to move to the x64 Platform

Change 3111177 on 2016/09/01 by Dmitry.Rekman

	Fix Linux build on systems without CUDA (UE-35460).

Change 3111548 on 2016/09/02 by Luke.Thatcher

	[PLATFORM] [PS4] [!]
	Fix for PS4 iterative deployment.
	 - Changes in Dev-Mobile broke the deployment manifests, as PS4 was now using the wrong filename when creating delta and obsolete file lists.

Change 3111863 on 2016/09/02 by Dmitry.Rekman

	Better fix for build without CUDA (UE-35460).

Change 3112738 on 2016/09/02 by Mark.Satterthwaite

	Fix the pausing particles on Metal - one line bug in the Metal query implementation meant that the first query wouldn't return the correct result for no good reason.
	#jira UE-34989

Change 3114579 on 2016/09/06 by Chris.Babcock

	Fix Vulkan include path in NDK check (contributed by geediiiiky)
	#jira UE-35490
	#github #2758
	#ue4
	#android

Change 3115115 on 2016/09/06 by Jeff.Campeau

	Calculate buffer size for paks using the bitwindow override as needed

Change 3115600 on 2016/09/07 by Luke.Thatcher

	[PLATFORM] [PS4] [~]
	Make the crash dump handler registration much earlier, to catch crashes in early engine init.
	 - Fixed up places in FGenericCrashContext::SerializeContentToBuffer which used the command line. If we crash early, the command line may not have been initialized yet.
	 - Added a GetNoInit function to FThreadHeartBeat to avoid creating the heart beat thread if we crash early, and the thread doesn't exist yet.

	Tested by calling abort() immediately inside int main(), and we get a valid crash dump that the crash handler service can consume.

Change 3115676 on 2016/09/07 by Luke.Thatcher

	[PLATFORM] [~]
	Dev-Platform integration fix for original CL 3064888 in //Orion/Release-29.1
	Add .exe and .dll to windows symbol upload file filters.

Change 3115811 on 2016/09/07 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3115944 on 2016/09/07 by Michael.Trepka

	Implemented IsGamepadAttached() for Mac

Change 3115948 on 2016/09/07 by Michael.Trepka

	Don't try to restore Help menu item on Mac if MenuBlock does not contain it

Change 3116200 on 2016/09/07 by Jeff.Campeau

	Fix parameter ordering

Change 3117660 on 2016/09/08 by Josh.Adams

	Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)

Change 3117728 on 2016/09/08 by Michael.Trepka

	Copy of CL 3117698 by Mike.Fricker

	Fixed regression with editor's Simulate mode where cursor would teleport back to the center of the viewport after every click
	- This bug was introduced in CL 3075932 from a borderless window cursor handling fix that was needed for games that capture the cursor

Change 3117797 on 2016/09/08 by Peter.Sauerbrei

	Shader Resource compression

Change 3117988 on 2016/09/08 by Brent.Pease

	 - Solutiion generator will now pick x64 instead of AnyCPU for the default platform configuration
	 - Fix what I think was a merge error in BuildGraph.cs

Change 3118296 on 2016/09/08 by Daniel.Lamb

	Fixed crash with launch on.  Couldnt' correctly detect previous generated ini settings.
	#test launch on QA game
	#jira UE-35741

Change 3118438 on 2016/09/08 by JohnHenry.Carawon

	Fix UAT compilation on Linux
	#UE-35745

Change 3118934 on 2016/09/08 by Jeff.Campeau

	Shader compression setting based on target platform instead of cooking host platform.

	#jira UE-35753

Change 3120190 on 2016/09/09 by Ben.Marsh

	Add missing Platform attribute to build script for Dev-Platform.

[CL 3120378 by Josh Adams in Main branch]
2016-09-09 20:13:41 -04:00

1525 lines
60 KiB
C#

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Threading;
using AutomationTool;
using UnrealBuildTool;
using Ionic.Zip;
public class AndroidPlatform : Platform
{
private const int DeployMaxParallelCommands = 6;
private const string TargetAndroidLocation = "obb/";
public AndroidPlatform()
: base(UnrealTargetPlatform.Android)
{
}
private static string GetSONameWithoutArchitecture(ProjectParams Params, string DecoratedExeName)
{
return Path.Combine(Path.GetDirectoryName(Params.ProjectGameExeFilename), DecoratedExeName) + ".so";
}
private static string GetFinalApkName(ProjectParams Params, string DecoratedExeName, bool bRenameUE4Game, string Architecture, string GPUArchitecture)
{
string ProjectDir = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(Params.RawProjectPath.FullName)), "Binaries/Android");
if (Params.Prebuilt)
{
ProjectDir = Path.Combine(Params.BaseStageDirectory, "Android");
}
// Apk's go to project location, not necessarily where the .so is (content only packages need to output to their directory)
string ApkName = Path.Combine(ProjectDir, DecoratedExeName) + Architecture + GPUArchitecture + ".apk";
// if the source binary was UE4Game, handle using it or switching to project name
if (Path.GetFileNameWithoutExtension(Params.ProjectGameExeFilename) == "UE4Game")
{
if (bRenameUE4Game)
{
// replace UE4Game with project name (only replace in the filename part)
ApkName = Path.Combine(Path.GetDirectoryName(ApkName), Path.GetFileName(ApkName).Replace("UE4Game", Params.ShortProjectName));
}
else
{
// if we want to use UE4 directly then use it from the engine directory not project directory
ApkName = ApkName.Replace(ProjectDir, Path.Combine(CmdEnv.LocalRoot, "Engine/Binaries/Android"));
}
}
return ApkName;
}
private static string GetFinalObbName(string ApkName)
{
// calculate the name for the .obb file
string PackageName = GetPackageInfo(ApkName, false);
if (PackageName == null)
{
throw new AutomationException(ExitCode.Error_FailureGettingPackageInfo, "Failed to get package name from " + ApkName);
}
string PackageVersion = GetPackageInfo(ApkName, true);
if (PackageVersion == null || PackageVersion.Length == 0)
{
throw new AutomationException(ExitCode.Error_FailureGettingPackageInfo, "Failed to get package version from " + ApkName);
}
if (PackageVersion.Length > 0)
{
int IntVersion = int.Parse(PackageVersion);
PackageVersion = IntVersion.ToString("0");
}
string ObbName = string.Format("main.{0}.{1}.obb", PackageVersion, PackageName);
// plop the .obb right next to the executable
ObbName = Path.Combine(Path.GetDirectoryName(ApkName), ObbName);
return ObbName;
}
private static string GetDeviceObbName(string ApkName)
{
string ObbName = GetFinalObbName(ApkName);
string PackageName = GetPackageInfo(ApkName, false);
return TargetAndroidLocation + PackageName + "/" + Path.GetFileName(ObbName);
}
private static string GetStorageQueryCommand()
{
if (Utils.IsRunningOnMono)
{
return "shell 'echo $EXTERNAL_STORAGE'";
}
else
{
return "shell \"echo $EXTERNAL_STORAGE\"";
}
}
private static string GetFinalBatchName(string ApkName, ProjectParams Params, string Architecture, string GPUArchitecture, bool bNoOBBInstall, bool bUninstall, bool bIsPC)
{
return Path.Combine(Path.GetDirectoryName(ApkName), (bUninstall ? "Uninstall_" : "Install_") + Params.ShortProjectName + (!bNoOBBInstall ? "_" : "_NoOBBInstall_") + Params.ClientConfigsToBuild[0].ToString() + Architecture + GPUArchitecture + (bIsPC ? ".bat" : ".command"));
}
private List<string> CollectPluginDataPaths(DeploymentContext SC)
{
// collect plugin extra data paths from target receipts
List<string> PluginExtras = new List<string>();
foreach (StageTarget Target in SC.StageTargets)
{
TargetReceipt Receipt = Target.Receipt;
var Results = Receipt.AdditionalProperties.Where(x => x.Name == "AndroidPlugin");
foreach (var Property in Results)
{
// Keep only unique paths
string PluginPath = Property.Value;
if (PluginExtras.FirstOrDefault(x => x == PluginPath) == null)
{
PluginExtras.Add(PluginPath);
Log("AndroidPlugin: {0}", PluginPath);
}
}
}
return PluginExtras;
}
public override void Package(ProjectParams Params, DeploymentContext SC, int WorkingCL)
{
AndroidToolChain ToolChain = new AndroidToolChain(Params.RawProjectPath);
var Architectures = ToolChain.GetAllArchitectures();
var GPUArchitectures = ToolChain.GetAllGPUArchitectures();
bool bMakeSeparateApks = UnrealBuildTool.UEDeployAndroid.ShouldMakeSeparateApks();
var Deploy = new UEDeployAndroid(Params.RawProjectPath);
bool bPackageDataInsideApk = Deploy.PackageDataInsideApk(false);
string BaseApkName = GetFinalApkName(Params, SC.StageExecutables[0], true, "", "");
Log("BaseApkName = {0}", BaseApkName);
// Create main OBB with entire contents of staging dir. This
// includes any PAK files, movie files, etc.
string LocalObbName = SC.StageDirectory.TrimEnd(new char[] {'/', '\\'})+".obb";
// Always delete the target OBB file if it exists
if (File.Exists(LocalObbName))
{
File.Delete(LocalObbName);
}
// Now create the OBB as a ZIP archive.
Log("Creating {0} from {1}", LocalObbName, SC.StageDirectory);
using (ZipFile ObbFile = new ZipFile(LocalObbName))
{
ObbFile.CompressionMethod = CompressionMethod.None;
ObbFile.CompressionLevel = Ionic.Zlib.CompressionLevel.None;
ObbFile.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Never;
int ObbFileCount = 0;
ObbFile.AddProgress +=
delegate(object sender, AddProgressEventArgs e)
{
if (e.EventType == ZipProgressEventType.Adding_AfterAddEntry)
{
ObbFileCount += 1;
Log("[{0}/{1}] Adding {2} to OBB",
ObbFileCount, e.EntriesTotal,
e.CurrentEntry.FileName);
}
};
ObbFile.AddDirectory(SC.StageDirectory+"/"+SC.ShortProjectName, SC.ShortProjectName);
try
{
ObbFile.Save();
}
catch (Exception)
{
Log("Failed to build OBB: " + LocalObbName);
throw new AutomationException(ExitCode.Error_MissingExecutable, "Stage Failed. Could not build OBB {0}. The file may be too big to fit in an OBB (2 GiB limit)", LocalObbName);
}
}
// collect plugin extra data paths from target receipts
Deploy.SetAndroidPluginData(Architectures, CollectPluginDataPaths(SC));
foreach (string Architecture in Architectures)
{
foreach (string GPUArchitecture in GPUArchitectures)
{
string ApkName = GetFinalApkName(Params, SC.StageExecutables[0], true, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "");
if (!SC.IsCodeBasedProject)
{
string UE4SOName = GetFinalApkName(Params, SC.StageExecutables[0], false, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "");
UE4SOName = UE4SOName.Replace(".apk", ".so");
if (FileExists_NoExceptions(UE4SOName) == false)
{
Log("Failed to find game .so " + UE4SOName);
throw new AutomationException(ExitCode.Error_MissingExecutable, "Stage Failed. Could not find .so {0}. You may need to build the UE4 project with your target configuration and platform.", UE4SOName);
}
}
if (!Params.Prebuilt)
{
string CookFlavor = SC.FinalCookPlatform.IndexOf("_") > 0 ? SC.FinalCookPlatform.Substring(SC.FinalCookPlatform.IndexOf("_")) : "";
string SOName = GetSONameWithoutArchitecture(Params, SC.StageExecutables[0]);
Deploy.PrepForUATPackageOrDeploy(Params.RawProjectPath, Params.ShortProjectName, SC.ProjectRoot, SOName, SC.LocalRoot + "/Engine", Params.Distribution, CookFlavor, false);
}
// Create APK specific OBB in case we have a detached OBB.
string DeviceObbName = "";
string ObbName = "";
if (!bPackageDataInsideApk)
{
DeviceObbName = GetDeviceObbName(ApkName);
ObbName = GetFinalObbName(ApkName);
CopyFile(LocalObbName, ObbName);
}
//figure out which platforms we need to create install files for
bool bNeedsPCInstall = false;
bool bNeedsMonoInstall = false;
GetPlatformInstallOptions(SC, out bNeedsPCInstall, out bNeedsMonoInstall);
//helper delegate to prevent code duplication but allow us access to all the local variables we need
var CreateInstallFilesAction = new Action<bool>(bPCInstall =>
{
// Write install batch file(s).
string BatchName = GetFinalBatchName(ApkName, Params, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "", false, false, bPCInstall);
string PackageName = GetPackageInfo(ApkName, false);
// make a batch file that can be used to install the .apk and .obb files
string[] BatchLines = GenerateInstallBatchFile(bPackageDataInsideApk, PackageName, ApkName, Params, ObbName, DeviceObbName, false, bPCInstall);
File.WriteAllLines(BatchName, BatchLines);
// make a batch file that can be used to uninstall the .apk and .obb files
string UninstallBatchName = GetFinalBatchName(ApkName, Params, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "", false, true, bPCInstall);
BatchLines = GenerateUninstallBatchFile(bPackageDataInsideApk, PackageName, ApkName, Params, ObbName, DeviceObbName, false, bPCInstall);
File.WriteAllLines(UninstallBatchName, BatchLines);
if (Utils.IsRunningOnMono)
{
CommandUtils.FixUnixFilePermissions(BatchName);
CommandUtils.FixUnixFilePermissions(UninstallBatchName);
//if(File.Exists(NoInstallBatchName))
//{
// CommandUtils.FixUnixFilePermissions(NoInstallBatchName);
//}
}
}
);
if (bNeedsPCInstall)
{
CreateInstallFilesAction.Invoke(true);
}
if(bNeedsMonoInstall)
{
CreateInstallFilesAction.Invoke(false);
}
// If we aren't packaging data in the APK then lets write out a bat file to also let us test without the OBB
// on the device.
//String NoInstallBatchName = GetFinalBatchName(ApkName, Params, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "", true, false);
// if(!bPackageDataInsideApk)
//{
// BatchLines = GenerateInstallBatchFile(bPackageDataInsideApk, PackageName, ApkName, Params, ObbName, DeviceObbName, true);
// File.WriteAllLines(NoInstallBatchName, BatchLines);
//}
}
}
PrintRunTime();
}
private string[] GenerateInstallBatchFile(bool bPackageDataInsideApk, string PackageName, string ApkName, ProjectParams Params, string ObbName, string DeviceObbName, bool bNoObbInstall, bool bIsPC)
{
string[] BatchLines = null;
if (!bIsPC)
{
string OBBInstallCommand = bNoObbInstall ? "shell 'rm -r $EXTERNAL_STORAGE/" + DeviceObbName + "'" : "push " + Path.GetFileName(ObbName) + " $STORAGE/" + DeviceObbName;
Log("Writing shell script for install with {0}", bPackageDataInsideApk ? "data in APK" : "separate obb");
BatchLines = new string[] {
"#!/bin/sh",
"cd \"`dirname \"$0\"`\"",
"ADB=",
"if [ \"$ANDROID_HOME\" != \"\" ]; then ADB=$ANDROID_HOME/platform-tools/adb; else ADB=" +Environment.GetEnvironmentVariable("ANDROID_HOME") + "; fi",
"DEVICE=",
"if [ \"$1\" != \"\" ]; then DEVICE=\"-s $1\"; fi",
"echo",
"echo Uninstalling existing application. Failures here can almost always be ignored.",
"$ADB $DEVICE uninstall " + PackageName,
"echo",
"echo Installing existing application. Failures here indicate a problem with the device \\(connection or storage permissions\\) and are fatal.",
"$ADB $DEVICE install " + Path.GetFileName(ApkName),
"if [ $? -eq 0 ]; then",
"\techo",
"\techo Removing old data. Failures here are usually fine - indicating the files were not on the device.",
"\t$ADB $DEVICE shell 'rm -r $EXTERNAL_STORAGE/UE4Game/" + Params.ShortProjectName + "'",
"\t$ADB $DEVICE shell 'rm -r $EXTERNAL_STORAGE/UE4Game/UE4CommandLine.txt" + "'",
"\t$ADB $DEVICE shell 'rm -r $EXTERNAL_STORAGE/" + TargetAndroidLocation + PackageName + "'",
bPackageDataInsideApk ? "" : "\techo",
bPackageDataInsideApk ? "" : "\techo Installing new data. Failures here indicate storage problems \\(missing SD card or bad permissions\\) and are fatal.",
bPackageDataInsideApk ? "" : "\tSTORAGE=$(echo \"`$ADB $DEVICE shell 'echo $EXTERNAL_STORAGE'`\" | cat -v | tr -d '^M')",
bPackageDataInsideApk ? "" : "\t$ADB $DEVICE " + OBBInstallCommand,
bPackageDataInsideApk ? "if [ 1 ]; then" : "\tif [ $? -eq 0 ]; then",
"\t\techo",
"\t\techo Installation successful",
"\t\texit 0",
"\tfi",
"fi",
"echo",
"echo There was an error installing the game or the obb file. Look above for more info.",
"echo",
"echo Things to try:",
"echo Check that the device (and only the device) is listed with \\\"$ADB devices\\\" from a command prompt.",
"echo Make sure all Developer options look normal on the device",
"echo Check that the device has an SD card.",
"exit 1"
};
}
else
{
string OBBInstallCommand = bNoObbInstall ? "shell rm -r %STORAGE%/" + DeviceObbName : "push " + Path.GetFileName(ObbName) + " %STORAGE%/" + DeviceObbName;
Log("Writing bat for install with {0}", bPackageDataInsideApk ? "data in APK" : "separate OBB");
BatchLines = new string[] {
"setlocal",
"set ANDROIDHOME=%ANDROID_HOME%",
"if \"%ANDROIDHOME%\"==\"\" set ANDROIDHOME="+Environment.GetEnvironmentVariable("ANDROID_HOME"),
"set ADB=%ANDROIDHOME%\\platform-tools\\adb.exe",
"set DEVICE=",
"if not \"%1\"==\"\" set DEVICE=-s %1",
"for /f \"delims=\" %%A in ('%ADB% %DEVICE% " + GetStorageQueryCommand() +"') do @set STORAGE=%%A",
"@echo.",
"@echo Uninstalling existing application. Failures here can almost always be ignored.",
"%ADB% %DEVICE% uninstall " + PackageName,
"@echo.",
"@echo Installing existing application. Failures here indicate a problem with the device (connection or storage permissions) and are fatal.",
"%ADB% %DEVICE% install " + Path.GetFileName(ApkName),
"@if \"%ERRORLEVEL%\" NEQ \"0\" goto Error",
"%ADB% %DEVICE% shell rm -r %STORAGE%/UE4Game/" + Params.ShortProjectName,
"%ADB% %DEVICE% shell rm -r %STORAGE%/UE4Game/UE4CommandLine.txt", // we need to delete the commandline in UE4Game or it will mess up loading
"%ADB% %DEVICE% shell rm -r %STORAGE%/" + TargetAndroidLocation + PackageName,
bPackageDataInsideApk ? "" : "@echo.",
bPackageDataInsideApk ? "" : "@echo Installing new data. Failures here indicate storage problems (missing SD card or bad permissions) and are fatal.",
bPackageDataInsideApk ? "" : "%ADB% %DEVICE% " + OBBInstallCommand,
bPackageDataInsideApk ? "" : "if \"%ERRORLEVEL%\" NEQ \"0\" goto Error",
"@echo.",
"@echo Installation successful",
"goto:eof",
":Error",
"@echo.",
"@echo There was an error installing the game or the obb file. Look above for more info.",
"@echo.",
"@echo Things to try:",
"@echo Check that the device (and only the device) is listed with \"%ADB$ devices\" from a command prompt.",
"@echo Make sure all Developer options look normal on the device",
"@echo Check that the device has an SD card.",
"@pause"
};
}
return BatchLines;
}
private string[] GenerateUninstallBatchFile(bool bPackageDataInsideApk, string PackageName, string ApkName, ProjectParams Params, string ObbName, string DeviceObbName, bool bNoObbInstall, bool bIsPC)
{
string[] BatchLines = null;
if (!bIsPC)
{
Log("Writing shell script for uninstall with {0}", bPackageDataInsideApk ? "data in APK" : "separate obb");
BatchLines = new string[] {
"#!/bin/sh",
"cd \"`dirname \"$0\"`\"",
"ADB=",
"if [ \"$ANDROID_HOME\" != \"\" ]; then ADB=$ANDROID_HOME/platform-tools/adb; else ADB=" +Environment.GetEnvironmentVariable("ANDROID_HOME") + "; fi",
"DEVICE=",
"if [ \"$1\" != \"\" ]; then DEVICE=\"-s $1\"; fi",
"echo",
"echo Uninstalling existing application. Failures here can almost always be ignored.",
"$ADB $DEVICE uninstall " + PackageName,
"echo",
"echo Removing old data. Failures here are usually fine - indicating the files were not on the device.",
"$ADB $DEVICE shell 'rm -r $EXTERNAL_STORAGE/UE4Game/" + Params.ShortProjectName + "'",
"$ADB $DEVICE shell 'rm -r $EXTERNAL_STORAGE/UE4Game/UE4CommandLine.txt" + "'",
"$ADB $DEVICE shell 'rm -r $EXTERNAL_STORAGE/" + TargetAndroidLocation + PackageName + "'",
"echo",
"echo Uninstall completed",
"exit 0",
};
}
else
{
Log("Writing bat for uninstall with {0}", bPackageDataInsideApk ? "data in APK" : "separate OBB");
BatchLines = new string[] {
"setlocal",
"set ANDROIDHOME=%ANDROID_HOME%",
"if \"%ANDROIDHOME%\"==\"\" set ANDROIDHOME="+Environment.GetEnvironmentVariable("ANDROID_HOME"),
"set ADB=%ANDROIDHOME%\\platform-tools\\adb.exe",
"set DEVICE=",
"if not \"%1\"==\"\" set DEVICE=-s %1",
"for /f \"delims=\" %%A in ('%ADB% %DEVICE% " + GetStorageQueryCommand() +"') do @set STORAGE=%%A",
"@echo.",
"@echo Uninstalling existing application. Failures here can almost always be ignored.",
"%ADB% %DEVICE% uninstall " + PackageName,
"@echo.",
"echo Removing old data. Failures here are usually fine - indicating the files were not on the device.",
"%ADB% %DEVICE% shell rm -r %STORAGE%/UE4Game/" + Params.ShortProjectName,
"%ADB% %DEVICE% shell rm -r %STORAGE%/UE4Game/UE4CommandLine.txt", // we need to delete the commandline in UE4Game or it will mess up loading
"%ADB% %DEVICE% shell rm -r %STORAGE%/" + TargetAndroidLocation + PackageName,
"@echo.",
"@echo Uninstall completed",
};
}
return BatchLines;
}
public override void GetFilesToArchive(ProjectParams Params, DeploymentContext SC)
{
if (SC.StageTargetConfigurations.Count != 1)
{
throw new AutomationException(ExitCode.Error_OnlyOneTargetConfigurationSupported, "Android is currently only able to package one target configuration at a time, but StageTargetConfigurations contained {0} configurations", SC.StageTargetConfigurations.Count);
}
AndroidToolChain ToolChain = new AndroidToolChain(Params.RawProjectPath);
var Architectures = ToolChain.GetAllArchitectures();
var GPUArchitectures = ToolChain.GetAllGPUArchitectures();
bool bMakeSeparateApks = UnrealBuildTool.UEDeployAndroid.ShouldMakeSeparateApks();
bool bPackageDataInsideApk = new UnrealBuildTool.UEDeployAndroid(Params.RawProjectPath).PackageDataInsideApk(false);
bool bAddedOBB = false;
foreach (string Architecture in Architectures)
{
foreach (string GPUArchitecture in GPUArchitectures)
{
string ApkName = GetFinalApkName(Params, SC.StageExecutables[0], true, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "");
string ObbName = GetFinalObbName(ApkName);
//string NoOBBBatchName = GetFinalBatchName(ApkName, Params, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "", true, false);
// verify the files exist
if (!FileExists(ApkName))
{
throw new AutomationException(ExitCode.Error_AppNotFound, "ARCHIVE FAILED - {0} was not found", ApkName);
}
if (!bPackageDataInsideApk && !FileExists(ObbName))
{
throw new AutomationException(ExitCode.Error_ObbNotFound, "ARCHIVE FAILED - {0} was not found", ObbName);
}
SC.ArchiveFiles(Path.GetDirectoryName(ApkName), Path.GetFileName(ApkName));
if (!bPackageDataInsideApk && !bAddedOBB)
{
bAddedOBB = true;
SC.ArchiveFiles(Path.GetDirectoryName(ObbName), Path.GetFileName(ObbName));
}
bool bNeedsPCInstall = false;
bool bNeedsMonoInstall = false;
GetPlatformInstallOptions(SC, out bNeedsPCInstall, out bNeedsMonoInstall);
//helper delegate to prevent code duplication but allow us access to all the local variables we need
var CreateBatchFilesAndArchiveAction = new Action<bool>(bPCInstall =>
{
string BatchName = GetFinalBatchName(ApkName, Params, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "", false, false, bPCInstall);
string UninstallBatchName = GetFinalBatchName(ApkName, Params, bMakeSeparateApks ? Architecture : "", bMakeSeparateApks ? GPUArchitecture : "", false, true, bPCInstall);
SC.ArchiveFiles(Path.GetDirectoryName(BatchName), Path.GetFileName(BatchName));
SC.ArchiveFiles(Path.GetDirectoryName(UninstallBatchName), Path.GetFileName(UninstallBatchName));
//SC.ArchiveFiles(Path.GetDirectoryName(NoOBBBatchName), Path.GetFileName(NoOBBBatchName));
}
);
//it's possible we will need both PC and Mac/Linux install files, do both
if (bNeedsPCInstall)
{
CreateBatchFilesAndArchiveAction(true);
}
if(bNeedsMonoInstall)
{
CreateBatchFilesAndArchiveAction(false);
}
}
}
}
private void GetPlatformInstallOptions(DeploymentContext SC, out bool bNeedsPCInstall, out bool bNeedsMonoInstall)
{
ConfigCacheIni Ini = ConfigCacheIni.CreateConfigCacheIni(SC.StageTargetPlatform.PlatformType, "Engine", DirectoryReference.FromFile(SC.RawProjectPath));
bool bGenerateAllPlatformInstall = false;
Ini.GetBool("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings", "bCreateAllPlatformsInstall", out bGenerateAllPlatformInstall);
if(bGenerateAllPlatformInstall)
{
bNeedsMonoInstall = bNeedsPCInstall = true;
}
else
{
bNeedsMonoInstall = Utils.IsRunningOnMono;
bNeedsPCInstall = !bNeedsMonoInstall;
}
}
private string GetAdbCommandLine(ProjectParams Params, string SerialNumber, string Args)
{
if (SerialNumber != "")
{
SerialNumber = "-s " + SerialNumber;
}
return string.Format("{0} {1}", SerialNumber, Args);
}
static string LastSpewFilename = "";
public string ADBSpewFilter(string Message)
{
if (Message.StartsWith("[") && Message.Contains("%]"))
{
int LastIndex = Message.IndexOf(":");
LastIndex = LastIndex == -1 ? Message.Length : LastIndex;
if (Message.Length > 7)
{
string Filename = Message.Substring(7, LastIndex - 7);
if (Filename == LastSpewFilename)
{
return null;
}
LastSpewFilename = Filename;
}
return Message;
}
return Message;
}
private IProcessResult RunAdbCommand(ProjectParams Params, string SerialNumber, string Args, string Input = null, ERunOptions Options = ERunOptions.Default)
{
string AdbCommand = Environment.ExpandEnvironmentVariables("%ANDROID_HOME%/platform-tools/adb" + (Utils.IsRunningOnMono ? "" : ".exe"));
if (Options.HasFlag(ERunOptions.AllowSpew) || Options.HasFlag(ERunOptions.SpewIsVerbose))
{
LastSpewFilename = "";
return Run(AdbCommand, GetAdbCommandLine(Params, SerialNumber, Args), Input, Options, SpewFilterCallback: new ProcessResult.SpewFilterCallbackType(ADBSpewFilter));
}
return Run(AdbCommand, GetAdbCommandLine(Params, SerialNumber, Args), Input, Options);
}
private string RunAndLogAdbCommand(ProjectParams Params, string SerialNumber, string Args, out int SuccessCode)
{
string AdbCommand = Environment.ExpandEnvironmentVariables("%ANDROID_HOME%/platform-tools/adb" + (Utils.IsRunningOnMono ? "" : ".exe"));
LastSpewFilename = "";
return RunAndLog(CmdEnv, AdbCommand, GetAdbCommandLine(Params, SerialNumber, Args), out SuccessCode, SpewFilterCallback: new ProcessResult.SpewFilterCallbackType(ADBSpewFilter));
}
public override void GetConnectedDevices(ProjectParams Params, out List<string> Devices)
{
Devices = new List<string>();
IProcessResult Result = RunAdbCommand(Params, "", "devices");
if (Result.Output.Length > 0)
{
string[] LogLines = Result.Output.Split(new char[] { '\n', '\r' });
bool FoundList = false;
for (int i = 0; i < LogLines.Length; ++i)
{
if (FoundList == false)
{
if (LogLines[i].StartsWith("List of devices attached"))
{
FoundList = true;
}
continue;
}
string[] DeviceLine = LogLines[i].Split(new char[] { '\t' });
if (DeviceLine.Length == 2)
{
// the second param should be "device"
// if it's not setup correctly it might be "unattached" or "powered off" or something like that
// warning in that case
if (DeviceLine[1] == "device")
{
Devices.Add("@" + DeviceLine[0]);
}
else
{
CommandUtils.LogWarning("Device attached but in bad state {0}:{1}", DeviceLine[0], DeviceLine[1]);
}
}
}
}
}
/*
private class TimeRegion : System.IDisposable
{
private System.DateTime StartTime { get; set; }
private string Format { get; set; }
private System.Collections.Generic.List<object> FormatArgs { get; set; }
public TimeRegion(string format, params object[] format_args)
{
Format = format;
FormatArgs = new List<object>(format_args);
StartTime = DateTime.UtcNow;
}
public void Dispose()
{
double total_time = (DateTime.UtcNow - StartTime).TotalMilliseconds / 1000.0;
FormatArgs.Insert(0, total_time);
CommandUtils.Log(Format, FormatArgs.ToArray());
}
}
*/
public override bool RetrieveDeployedManifests(ProjectParams Params, DeploymentContext SC, string DeviceName, out List<string> UFSManifests, out List<string> NonUFSManifests)
{
UFSManifests = null;
NonUFSManifests = null;
// Query the storage path from the device
string DeviceStorageQueryCommand = GetStorageQueryCommand();
IProcessResult StorageResult = RunAdbCommand(Params, DeviceName, DeviceStorageQueryCommand, null, ERunOptions.AppMustExist);
String StorageLocation = StorageResult.Output.Trim();
string RemoteDir = StorageLocation + "/UE4Game/" + Params.ShortProjectName;
// Note: appends the device name to make the filename unique; these files will be deleted later during delta manifest generation
// Replace colon with underscore for legal filename (colon may be present for wifi connected devices)
string SanitizedDeviceName = DeviceName.Replace(":", "_");
// Try retrieving the UFS files manifest files from the device
string UFSManifestFileName = CombinePaths(SC.StageDirectory, SC.UFSDeployedManifestFileName + "_" + SanitizedDeviceName);
IProcessResult UFSResult = RunAdbCommand(Params, DeviceName, " pull " + RemoteDir + "/" + SC.UFSDeployedManifestFileName + " \"" + UFSManifestFileName + "\"", null, ERunOptions.AppMustExist);
if (!(UFSResult.Output.Contains("bytes") || UFSResult.Output.Contains("[100%]")))
{
return false;
}
// Try retrieving the non UFS files manifest files from the device
string NonUFSManifestFileName = CombinePaths(SC.StageDirectory, SC.NonUFSDeployedManifestFileName + "_" + SanitizedDeviceName);
IProcessResult NonUFSResult = RunAdbCommand(Params, DeviceName, " pull " + RemoteDir + "/" + SC.NonUFSDeployedManifestFileName + " \"" + NonUFSManifestFileName + "\"", null, ERunOptions.AppMustExist);
if (!(NonUFSResult.Output.Contains("bytes") || NonUFSResult.Output.Contains("[100%]")))
{
// Did not retrieve both so delete one we did retrieve
File.Delete(UFSManifestFileName);
return false;
}
// Return the manifest files
UFSManifests = new List<string>();
UFSManifests.Add(UFSManifestFileName);
NonUFSManifests = new List<string>();
NonUFSManifests.Add(NonUFSManifestFileName);
return true;
}
internal class LongestFirst : IComparer<string>
{
public int Compare(string a, string b)
{
if (a.Length == b.Length) return a.CompareTo(b);
else return b.Length - a.Length;
}
}
public override void Deploy(ProjectParams Params, DeploymentContext SC)
{
foreach (var DeviceName in Params.DeviceNames)
{
string DeviceArchitecture = GetBestDeviceArchitecture(Params, DeviceName);
string GPUArchitecture = GetBestGPUArchitecture(Params, DeviceName);
string ApkName = GetFinalApkName(Params, SC.StageExecutables[0], true, DeviceArchitecture, GPUArchitecture);
// make sure APK is up to date (this is fast if so)
var Deploy = new UEDeployAndroid(Params.RawProjectPath);
if (!Params.Prebuilt)
{
string CookFlavor = SC.FinalCookPlatform.IndexOf("_") > 0 ? SC.FinalCookPlatform.Substring(SC.FinalCookPlatform.IndexOf("_")) : "";
string SOName = GetSONameWithoutArchitecture(Params, SC.StageExecutables[0]);
List<string> Architectures = new List<string>();
Architectures.Add(DeviceArchitecture);
Deploy.SetAndroidPluginData(Architectures, CollectPluginDataPaths(SC));
Deploy.PrepForUATPackageOrDeploy(Params.RawProjectPath, Params.ShortProjectName, SC.ProjectRoot, SOName, SC.LocalRoot + "/Engine", Params.Distribution, CookFlavor, true);
}
// now we can use the apk to get more info
string PackageName = GetPackageInfo(ApkName, false);
// Setup the OBB name and add the storage path (queried from the device) to it
string DeviceStorageQueryCommand = GetStorageQueryCommand();
IProcessResult Result = RunAdbCommand(Params, DeviceName, DeviceStorageQueryCommand, null, ERunOptions.AppMustExist);
String StorageLocation = Result.Output.Trim(); // "/mnt/sdcard";
string DeviceObbName = StorageLocation + "/" + GetDeviceObbName(ApkName);
string RemoteDir = StorageLocation + "/UE4Game/" + Params.ShortProjectName;
// determine if APK out of date
string APKLastUpdateTime = new FileInfo(ApkName).LastWriteTime.ToString();
bool bNeedAPKInstall = true;
if (Params.IterativeDeploy)
{
// Check for apk installed with this package name on the device
IProcessResult InstalledResult = RunAdbCommand(Params, DeviceName, "shell pm list packages " + PackageName, null, ERunOptions.AppMustExist);
if (InstalledResult.Output.Contains(PackageName))
{
// See if apk is up to date on device
InstalledResult = RunAdbCommand(Params, DeviceName, "shell cat " + RemoteDir + "/APKFileStamp.txt", null, ERunOptions.AppMustExist);
if (InstalledResult.Output.StartsWith("APK: "))
{
if (InstalledResult.Output.Substring(5).Trim() == APKLastUpdateTime)
bNeedAPKInstall = false;
// Stop the previously running copy (uninstall/install did this before)
InstalledResult = RunAdbCommand(Params, DeviceName, "shell am force-stop " + PackageName, null, ERunOptions.AppMustExist);
if (InstalledResult.Output.Contains("Error"))
{
// force-stop not supported (Android < 3.0) so check if package is actually running
// Note: cannot use grep here since it may not be installed on device
InstalledResult = RunAdbCommand(Params, DeviceName, "shell ps", null, ERunOptions.AppMustExist);
if (InstalledResult.Output.Contains(PackageName))
{
// it is actually running so use the slow way to kill it (uninstall and reinstall)
bNeedAPKInstall = true;
}
}
}
}
}
// install new APK if needed
if (bNeedAPKInstall)
{
// try uninstalling an old app with the same identifier.
int SuccessCode = 0;
string UninstallCommandline = "uninstall " + PackageName;
RunAndLogAdbCommand(Params, DeviceName, UninstallCommandline, out SuccessCode);
// install the apk
string InstallCommandline = "install \"" + ApkName + "\"";
string InstallOutput = RunAndLogAdbCommand(Params, DeviceName, InstallCommandline, out SuccessCode);
int FailureIndex = InstallOutput.IndexOf("Failure");
// adb install doesn't always return an error code on failure, and instead prints "Failure", followed by an error code.
if (SuccessCode != 0 || FailureIndex != -1)
{
string ErrorMessage = string.Format("Installation of apk '{0}' failed", ApkName);
if (FailureIndex != -1)
{
string FailureString = InstallOutput.Substring(FailureIndex + 7).Trim();
if (FailureString != "")
{
ErrorMessage += ": " + FailureString;
}
}
if (ErrorMessage.Contains("OLDER_SDK"))
{
LogError("minSdkVersion is higher than Android version installed on device, possibly due to NDK API Level");
}
throw new AutomationException(ExitCode.Error_AppInstallFailed, ErrorMessage);
}
}
// update the ue4commandline.txt
// update and deploy ue4commandline.txt
// always delete the existing commandline text file, so it doesn't reuse an old one
string IntermediateCmdLineFile = CombinePaths(SC.StageDirectory, "UE4CommandLine.txt");
Project.WriteStageCommandline(IntermediateCmdLineFile, Params, SC);
// copy files to device if we were staging
if (SC.Stage)
{
// cache some strings
string BaseCommandline = "push";
HashSet<string> EntriesToDeploy = new HashSet<string>();
if (Params.IterativeDeploy)
{
// always send UE4CommandLine.txt (it was written above after delta checks applied)
EntriesToDeploy.Add(IntermediateCmdLineFile);
// Add non UFS files if any to deploy
String NonUFSManifestPath = SC.GetNonUFSDeploymentDeltaPath(DeviceName);
if (File.Exists(NonUFSManifestPath))
{
string NonUFSFiles = File.ReadAllText(NonUFSManifestPath);
foreach (string Filename in NonUFSFiles.Split('\n'))
{
if (!string.IsNullOrEmpty(Filename) && !string.IsNullOrWhiteSpace(Filename))
{
EntriesToDeploy.Add(CombinePaths(SC.StageDirectory, Filename.Trim()));
}
}
}
// Add UFS files if any to deploy
String UFSManifestPath = SC.GetUFSDeploymentDeltaPath(DeviceName);
if (File.Exists(UFSManifestPath))
{
string UFSFiles = File.ReadAllText(UFSManifestPath);
foreach (string Filename in UFSFiles.Split('\n'))
{
if (!string.IsNullOrEmpty(Filename) && !string.IsNullOrWhiteSpace(Filename))
{
EntriesToDeploy.Add(CombinePaths(SC.StageDirectory, Filename.Trim()));
}
}
}
// For now, if too many files may be better to just push them all
if (EntriesToDeploy.Count > 500)
{
// make sure device is at a clean state
RunAdbCommand(Params, DeviceName, "shell rm -r " + RemoteDir);
EntriesToDeploy.Clear();
EntriesToDeploy.TrimExcess();
EntriesToDeploy.Add(SC.StageDirectory);
}
}
else
{
// make sure device is at a clean state
RunAdbCommand(Params, DeviceName, "shell rm -r " + RemoteDir);
// Copy UFS files..
string[] Files = Directory.GetFiles(SC.StageDirectory, "*", SearchOption.AllDirectories);
System.Array.Sort(Files);
// Find all the files we exclude from copying. And include
// the directories we need to individually copy.
HashSet<string> ExcludedFiles = new HashSet<string>();
SortedSet<string> IndividualCopyDirectories
= new SortedSet<string>((IComparer<string>)new LongestFirst());
foreach (string Filename in Files)
{
bool Exclude = false;
// Don't push the apk, we install it
Exclude |= Path.GetExtension(Filename).Equals(".apk", StringComparison.InvariantCultureIgnoreCase);
// For excluded files we add the parent dirs to our
// tracking of stuff to individually copy.
if (Exclude)
{
ExcludedFiles.Add(Filename);
// We include all directories up to the stage root in having
// to individually copy the files.
for (string FileDirectory = Path.GetDirectoryName(Filename);
!FileDirectory.Equals(SC.StageDirectory);
FileDirectory = Path.GetDirectoryName(FileDirectory))
{
if (!IndividualCopyDirectories.Contains(FileDirectory))
{
IndividualCopyDirectories.Add(FileDirectory);
}
}
if (!IndividualCopyDirectories.Contains(SC.StageDirectory))
{
IndividualCopyDirectories.Add(SC.StageDirectory);
}
}
}
// The directories are sorted above in "deepest" first. We can
// therefore start copying those individual dirs which will
// recreate the tree. As the subtrees will get copied at each
// possible individual level.
foreach (string DirectoryName in IndividualCopyDirectories)
{
string[] Entries
= Directory.GetFileSystemEntries(DirectoryName, "*", SearchOption.TopDirectoryOnly);
foreach (string Entry in Entries)
{
// We avoid excluded files and the individual copy dirs
// (the individual copy dirs will get handled as we iterate).
if (ExcludedFiles.Contains(Entry) || IndividualCopyDirectories.Contains(Entry))
{
continue;
}
else
{
EntriesToDeploy.Add(Entry);
}
}
}
if (EntriesToDeploy.Count == 0)
{
EntriesToDeploy.Add(SC.StageDirectory);
}
}
// We now have a minimal set of file & dir entries we need
// to deploy. Files we deploy will get individually copied
// and dirs will get the tree copies by default (that's
// what ADB does).
HashSet<IProcessResult> DeployCommands = new HashSet<IProcessResult>();
foreach (string Entry in EntriesToDeploy)
{
string FinalRemoteDir = RemoteDir;
string RemotePath = Entry.Replace(SC.StageDirectory, FinalRemoteDir).Replace("\\", "/");
string Commandline = string.Format("{0} \"{1}\" \"{2}\"", BaseCommandline, Entry, RemotePath);
// We run deploy commands in parallel to maximize the connection
// throughput.
DeployCommands.Add(
RunAdbCommand(Params, DeviceName, Commandline, null,
ERunOptions.Default | ERunOptions.NoWaitForExit));
// But we limit the parallel commands to avoid overwhelming
// memory resources.
if (DeployCommands.Count == DeployMaxParallelCommands)
{
while (DeployCommands.Count > DeployMaxParallelCommands / 2)
{
Thread.Sleep(1);
DeployCommands.RemoveWhere(
delegate (IProcessResult r)
{
return r.HasExited;
});
}
}
}
foreach (IProcessResult deploy_result in DeployCommands)
{
deploy_result.WaitForExit();
}
// delete the .obb file, since it will cause nothing we just deployed to be used
RunAdbCommand(Params, DeviceName, "shell rm " + DeviceObbName);
}
else if (SC.Archive)
{
// deploy the obb if there is one
string ObbPath = Path.Combine(SC.StageDirectory, GetFinalObbName(ApkName));
if (File.Exists(ObbPath))
{
// cache some strings
string BaseCommandline = "push";
string Commandline = string.Format("{0} \"{1}\" \"{2}\"", BaseCommandline, ObbPath, DeviceObbName);
RunAdbCommand(Params, DeviceName, Commandline);
}
}
else
{
// cache some strings
string BaseCommandline = "push";
string FinalRemoteDir = RemoteDir;
/*
// handle the special case of the UE4Commandline.txt when using content only game (UE4Game)
if (!Params.IsCodeBasedProject)
{
FinalRemoteDir = "/mnt/sdcard/UE4Game";
}
*/
string RemoteFilename = IntermediateCmdLineFile.Replace(SC.StageDirectory, FinalRemoteDir).Replace("\\", "/");
string Commandline = string.Format("{0} \"{1}\" \"{2}\"", BaseCommandline, IntermediateCmdLineFile, RemoteFilename);
RunAdbCommand(Params, DeviceName, Commandline);
}
// write new timestamp for APK (do it here since RemoteDir will now exist)
if (bNeedAPKInstall)
{
int SuccessCode = 0;
RunAndLogAdbCommand(Params, DeviceName, "shell \"echo 'APK: " + APKLastUpdateTime + "' > " + RemoteDir + "/APKFileStamp.txt\"", out SuccessCode);
}
}
}
/** Internal usage for GetPackageName */
private static string PackageLine = null;
private static Mutex PackageInfoMutex = new Mutex();
private static string LaunchableActivityLine = null;
/** Run an external exe (and capture the output), given the exe path and the commandline. */
private static string GetPackageInfo(string ApkName, bool bRetrieveVersionCode)
{
// we expect there to be one, so use the first one
string AaptPath = GetAaptPath();
PackageInfoMutex.WaitOne();
var ExeInfo = new ProcessStartInfo(AaptPath, "dump badging \"" + ApkName + "\"");
ExeInfo.UseShellExecute = false;
ExeInfo.RedirectStandardOutput = true;
using (var GameProcess = Process.Start(ExeInfo))
{
PackageLine = null;
LaunchableActivityLine = null;
GameProcess.BeginOutputReadLine();
GameProcess.OutputDataReceived += ParsePackageName;
GameProcess.WaitForExit();
}
PackageInfoMutex.ReleaseMutex();
string ReturnValue = null;
if (PackageLine != null)
{
// the line should look like: package: name='com.epicgames.qagame' versionCode='1' versionName='1.0'
string[] Tokens = PackageLine.Split("'".ToCharArray());
int TokenIndex = bRetrieveVersionCode ? 3 : 1;
if (Tokens.Length >= TokenIndex + 1)
{
ReturnValue = Tokens[TokenIndex];
}
}
return ReturnValue;
}
/** Returns the launch activity name to launch (must call GetPackageInfo first), returns "com.epicgames.ue4.SplashActivity" default if not found */
private static string GetLaunchableActivityName()
{
string ReturnValue = "com.epicgames.ue4.SplashActivity";
if (LaunchableActivityLine != null)
{
// the line should look like: launchable-activity: name='com.epicgames.ue4.SplashActivity' label='TappyChicken' icon=''
string[] Tokens = LaunchableActivityLine.Split("'".ToCharArray());
if (Tokens.Length >= 2)
{
ReturnValue = Tokens[1];
}
}
return ReturnValue;
}
/** Simple function to pipe output asynchronously */
private static void ParsePackageName(object Sender, DataReceivedEventArgs Event)
{
// DataReceivedEventHandler is fired with a null string when the output stream is closed. We don't want to
// print anything for that event.
if (!String.IsNullOrEmpty(Event.Data))
{
if (PackageLine == null)
{
string Line = Event.Data;
if (Line.StartsWith("package:"))
{
PackageLine = Line;
}
}
if (LaunchableActivityLine == null)
{
string Line = Event.Data;
if (Line.StartsWith("launchable-activity:"))
{
LaunchableActivityLine = Line;
}
}
}
}
static private string CachedAaptPath = null;
static private string LastAndroidHomePath = null;
private static uint GetRevisionValue(string VersionString)
{
// read up to 4 sections (ie. 20.0.3.5), first section most significant
// each section assumed to be 0 to 255 range
uint Value = 0;
try
{
string[] Sections= VersionString.Split(".".ToCharArray());
Value |= (Sections.Length > 0) ? (uint.Parse(Sections[0]) << 24) : 0;
Value |= (Sections.Length > 1) ? (uint.Parse(Sections[1]) << 16) : 0;
Value |= (Sections.Length > 2) ? (uint.Parse(Sections[2]) << 8) : 0;
Value |= (Sections.Length > 3) ? uint.Parse(Sections[3]) : 0;
}
catch (Exception)
{
// ignore poorly formed version
}
return Value;
}
private static string GetAaptPath()
{
// return cached path if ANDROID_HOME has not changed
string HomePath = Environment.ExpandEnvironmentVariables("%ANDROID_HOME%");
if (CachedAaptPath != null && LastAndroidHomePath == HomePath)
{
return CachedAaptPath;
}
// get a list of the directories in build-tools.. may be more than one set installed (or none which is bad)
string[] Subdirs = Directory.GetDirectories(Path.Combine(HomePath, "build-tools"));
if (Subdirs.Length == 0)
{
throw new AutomationException(ExitCode.Error_AndroidBuildToolsPathNotFound, "Failed to find %ANDROID_HOME%/build-tools subdirectory. Run SDK manager and install build-tools.");
}
// valid directories will have a source.properties with the Pkg.Revision (there is no guarantee we can use the directory name as revision)
string BestToolPath = null;
uint BestVersion = 0;
foreach (string CandidateDir in Subdirs)
{
string AaptFilename = Path.Combine(CandidateDir, Utils.IsRunningOnMono ? "aapt" : "aapt.exe");
uint RevisionValue = 0;
if (File.Exists(AaptFilename))
{
string SourcePropFilename = Path.Combine(CandidateDir, "source.properties");
if (File.Exists(SourcePropFilename))
{
string[] PropertyContents = File.ReadAllLines(SourcePropFilename);
foreach (string PropertyLine in PropertyContents)
{
if (PropertyLine.StartsWith("Pkg.Revision="))
{
RevisionValue = GetRevisionValue(PropertyLine.Substring(13));
break;
}
}
}
}
// remember it if newer version or haven't found one yet
if (RevisionValue > BestVersion || BestToolPath == null)
{
BestVersion = RevisionValue;
BestToolPath = AaptFilename;
}
}
if (BestToolPath == null)
{
throw new AutomationException(ExitCode.Error_AndroidBuildToolsPathNotFound, "Failed to find %ANDROID_HOME%/build-tools subdirectory with aapt. Run SDK manager and install build-tools.");
}
CachedAaptPath = BestToolPath;
LastAndroidHomePath = HomePath;
Log("Using this aapt: {0}", CachedAaptPath);
return CachedAaptPath;
}
private string GetBestDeviceArchitecture(ProjectParams Params, string DeviceName)
{
bool bMakeSeparateApks = UnrealBuildTool.UEDeployAndroid.ShouldMakeSeparateApks();
// if we are joining all .so's into a single .apk, there's no need to find the best one - there is no other one
if (!bMakeSeparateApks)
{
return "";
}
var AppArchitectures = new AndroidToolChain(Params.RawProjectPath).GetAllArchitectures();
// ask the device
IProcessResult ABIResult = RunAdbCommand(Params, DeviceName, " shell getprop ro.product.cpu.abi", null, ERunOptions.AppMustExist);
// the output is just the architecture
string DeviceArch = UnrealBuildTool.UEDeployAndroid.GetUE4Arch(ABIResult.Output.Trim());
// if the architecture wasn't built, look for a backup
if (!AppArchitectures.Contains(DeviceArch))
{
// go from 64 to 32-bit
if (DeviceArch == "-arm64")
{
DeviceArch = "-armv7";
}
// go from 64 to 32-bit
else if (DeviceArch == "-x64")
{
if (!AppArchitectures.Contains("-x86"))
{
DeviceArch = "-x86";
}
// if it didn't have 32-bit x86, look for 64-bit arm for emulation
// @todo android 64-bit: x86_64 most likely can't emulate arm64 at this ponit
// else if (Array.IndexOf(AppArchitectures, "-arm64") == -1)
// {
// DeviceArch = "-arm64";
// }
// finally try for 32-bit arm emulation (Houdini)
else
{
DeviceArch = "-armv7";
}
}
// use armv7 (with Houdini emulation)
else if (DeviceArch == "-x86")
{
DeviceArch = "-armv7";
}
else
{
// future-proof by dropping back to armv7 for unknown
DeviceArch = "-armv7";
}
}
// if after the fallbacks, we still don't have it, we can't continue
if (!AppArchitectures.Contains(DeviceArch))
{
throw new AutomationException(ExitCode.Error_NoApkSuitableForArchitecture, "Unable to run because you don't have an apk that is usable on {0}. Looked for {1}", DeviceName, DeviceArch);
}
return DeviceArch;
}
private string GetBestGPUArchitecture(ProjectParams Params, string DeviceName)
{
bool bMakeSeparateApks = UnrealBuildTool.UEDeployAndroid.ShouldMakeSeparateApks();
// if we are joining all .so's into a single .apk, there's no need to find the best one - there is no other one
if (!bMakeSeparateApks)
{
return "";
}
var AppGPUArchitectures = new AndroidToolChain(Params.RawProjectPath).GetAllGPUArchitectures();
// get the device extensions
IProcessResult ExtensionsResult = RunAdbCommand(Params, DeviceName, "shell dumpsys SurfaceFlinger", null, ERunOptions.AppMustExist);
string Extensions = ExtensionsResult.Output.Trim();
// look for AEP support (on device and in project)
if (Extensions.Contains("GL_ANDROID_extension_pack_es31a") && Extensions.Contains("GL_EXT_color_buffer_half_float"))
{
if (AppGPUArchitectures.Contains("-esdeferred"))
{
return "-esdeferred";
}
}
return "-es2";
}
public override IProcessResult RunClient(ERunOptions ClientRunFlags, string ClientApp, string ClientCmdLine, ProjectParams Params)
{
//make a copy of the device names, we'll be working through them
List<string> DeviceNames = new List<string>();
//same with the package names
List<string> PackageNames = new List<string>();
foreach (string DeviceName in Params.DeviceNames)
{
//save the device name
DeviceNames.Add(DeviceName);
//get the package name and save that
string DeviceArchitecture = GetBestDeviceArchitecture(Params, DeviceName);
string GPUArchitecture = GetBestGPUArchitecture(Params, DeviceName);
string ApkName = ClientApp + DeviceArchitecture + ".apk";
if (!File.Exists(ApkName))
{
ApkName = GetFinalApkName(Params, Path.GetFileNameWithoutExtension(ClientApp), true, DeviceArchitecture, GPUArchitecture);
}
Console.WriteLine("Apk='{0}', ClientApp='{1}', ExeName='{2}'", ApkName, ClientApp, Params.ProjectGameExeFilename);
// run aapt to get the name of the intent
string PackageName = GetPackageInfo(ApkName, false);
if (PackageName == null)
{
throw new AutomationException(ExitCode.Error_FailureGettingPackageInfo, "Failed to get package name from " + ClientApp);
}
PackageNames.Add(PackageName);
// clear the log for the device
RunAdbCommand(Params, DeviceName, "logcat -c");
// start the app on device!
string CommandLine = "shell am start -n " + PackageName + "/" + GetLaunchableActivityName();
RunAdbCommand(Params, DeviceName, CommandLine, null, ClientRunFlags);
// save the output to the staging directory
string LogPath = Path.Combine(Params.BaseStageDirectory, "Android\\logs");
Directory.CreateDirectory(LogPath);
}
//now check if each device still has the game running, and time out if it's taking too long
DateTime StartTime = DateTime.Now;
int TimeOutSeconds = Params.RunTimeoutSeconds;
while (DeviceNames.Count > 0)
{
for(int DeviceIndex = 0; DeviceIndex < DeviceNames.Count; DeviceIndex++)
{
string DeviceName = DeviceNames[DeviceIndex];
bool FinishedRunning = false;
IProcessResult ProcessesResult = RunAdbCommand(Params, DeviceName, "shell ps", null, ERunOptions.SpewIsVerbose);
string RunningProcessList = ProcessesResult.Output;
if (!RunningProcessList.Contains(PackageNames[DeviceIndex]))
{
FinishedRunning = true;
}
Thread.Sleep(10);
if(!FinishedRunning)
{
TimeSpan DeltaRunTime = DateTime.Now - StartTime;
if ((DeltaRunTime.TotalSeconds > TimeOutSeconds) && (TimeOutSeconds != 0))
{
Log("Device: " + DeviceName + " timed out while waiting for run to finish");
FinishedRunning = true;
}
}
//log the results, then clear out the device from our list
if(FinishedRunning)
{
// this is just to get the ue4 log to go to the output
RunAdbCommand(Params, DeviceName, "logcat -d -s UE4 -s Debug");
// get the log we actually want to save
IProcessResult LogFileProcess = RunAdbCommand(Params, DeviceName, "logcat -d", null, ERunOptions.AppMustExist);
string LogPath = Path.Combine(Params.BaseStageDirectory, "Android\\logs");
string LogFilename = Path.Combine(LogPath, "devicelog" + DeviceName + ".log");
string ServerLogFilename = Path.Combine(CmdEnv.LogFolder, "devicelog" + DeviceName + ".log");
File.WriteAllText(LogFilename, LogFileProcess.Output);
File.WriteAllText(ServerLogFilename, LogFileProcess.Output);
DeviceNames.RemoveAt(DeviceIndex);
PackageNames.RemoveAt(DeviceIndex);
--DeviceIndex;
}
}
}
return null;
}
public override void GetFilesToDeployOrStage(ProjectParams Params, DeploymentContext SC)
{
// if (SC.StageExecutables.Count != 1 && Params.Package)
// {
// throw new AutomationException("Exactly one executable expected when staging Android. Had " + SC.StageExecutables.Count.ToString());
// }
//
// // stage all built executables
// foreach (var Exe in SC.StageExecutables)
// {
// string ApkName = Exe + GetArchitecture(Params) + ".apk";
//
// SC.StageFiles(StagedFileType.NonUFS, Params.ProjectBinariesFolder, ApkName);
// }
}
/// <summary>
/// Gets cook platform name for this platform.
/// </summary>
/// <returns>Cook platform string.</returns>
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android";
}
public override bool DeployPakInternalLowerCaseFilenames()
{
return false;
}
public override bool DeployLowerCaseFilenames(bool bUFSFile)
{
return false;
}
public override string LocalPathToTargetPath(string LocalPath, string LocalRoot)
{
return LocalPath.Replace("\\", "/").Replace(LocalRoot, "../../..");
}
public override bool IsSupported { get { return true; } }
public override string Remap(string Dest)
{
return Dest;
}
public override PakType RequiresPak(ProjectParams Params)
{
// if packaging is enabled, always create a pak, otherwise use the Params.Pak value
return Params.Package ? PakType.Always : PakType.DontCare;
}
public override bool SupportsMultiDeviceDeploy
{
get
{
return true;
}
}
/*
public override bool RequiresPackageToDeploy
{
get { return true; }
}
*/
#region Hooks
public override void PostBuildTarget(UE4Build Build, FileReference UProjectPath, string TargetName, string Config)
{
// Run UBT w/ the prep for deployment only option
// This is required as UBT will 'fake' success when building via UAT and run
// the deployment prep step before all the required parts are present.
if (!String.IsNullOrEmpty(TargetName) && TargetName.Length > 0)
{
string ProjectArg = "";
if(UProjectPath != null)
{
ProjectArg = string.Format(" -project=\"{0}\"", UProjectPath);
}
string UBTCommand = string.Format("{0} Android {1} -prepfordeploy{2}", TargetName, Config, ProjectArg);
CommandUtils.RunUBT(UE4Build.CmdEnv, Build.UBTExecutable, UBTCommand);
}
}
#endregion
public override List<string> GetDebugFileExtentions()
{
return new List<string> { };
}
}
public class AndroidPlatformMulti : AndroidPlatform
{
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android_Multi";
}
public override TargetPlatformDescriptor GetTargetPlatformDescriptor()
{
return new TargetPlatformDescriptor(TargetPlatformType, "Multi");
}
}
public class AndroidPlatformATC : AndroidPlatform
{
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android_ATC";
}
public override TargetPlatformDescriptor GetTargetPlatformDescriptor()
{
return new TargetPlatformDescriptor(TargetPlatformType, "ATC");
}
}
public class AndroidPlatformDXT : AndroidPlatform
{
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android_DXT";
}
public override TargetPlatformDescriptor GetTargetPlatformDescriptor()
{
return new TargetPlatformDescriptor(TargetPlatformType, "DXT");
}
}
public class AndroidPlatformETC1 : AndroidPlatform
{
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android_ETC1";
}
public override TargetPlatformDescriptor GetTargetPlatformDescriptor()
{
return new TargetPlatformDescriptor(TargetPlatformType, "ETC1");
}
}
public class AndroidPlatformETC2 : AndroidPlatform
{
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android_ETC2";
}
public override TargetPlatformDescriptor GetTargetPlatformDescriptor()
{
return new TargetPlatformDescriptor(TargetPlatformType, "ETC2");
}
}
public class AndroidPlatformPVRTC : AndroidPlatform
{
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android_PVRTC";
}
public override TargetPlatformDescriptor GetTargetPlatformDescriptor()
{
return new TargetPlatformDescriptor(TargetPlatformType, "PVRTC");
}
}
public class AndroidPlatformASTC : AndroidPlatform
{
public override string GetCookPlatform(bool bDedicatedServer, bool bIsClientOnly)
{
return "Android_ASTC";
}
public override TargetPlatformDescriptor GetTargetPlatformDescriptor()
{
return new TargetPlatformDescriptor(TargetPlatformType, "ASTC");
}
}