Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Play Bundle throws ThreadAbortException #102

Open
joonjoonjoon opened this issue Apr 30, 2021 · 9 comments
Open

Building Play Bundle throws ThreadAbortException #102

joonjoonjoon opened this issue Apr 30, 2021 · 9 comments
Assignees

Comments

@joonjoonjoon
Copy link

When trying to build my app through the Google > Build App Bundle command in Unity, it often does not reach signing stage, and throws an error

Exception failed: System.Threading.ThreadAbortException
  at (wrapper managed-to-native) System.Threading.WaitHandle.Wait_internal(intptr*,int,bool,int)
  at System.Threading.WaitHandle.WaitOneNative (System.Runtime.InteropServices.SafeHandle

I think using EditorApplication.Update (in AppBundleBuilder, line 336) as a loop cycle for the postbuild stuff is really bad, since it requries that I have the Editor focused, or the script will stall on each step until the editor was focused.
I added an extra line to try and make sure it doesn't stall, and after that my build started getting to the signing stage more frequently, but I'm not sure this is a real solution... SceneView.duringSceneGui += (x) => {HandleUpdate();};

@thanwah thanwah self-assigned this Apr 30, 2021
@thanwah
Copy link
Contributor

thanwah commented Apr 30, 2021

Hi @joonjoonjoon, thanks for reporting this issue.

I just tried a build while the Editor was unfocused and wasn't able to reproduce the error.

What operating system are you using? What version of Unity are you using?

@joonjoonjoon
Copy link
Author

joonjoonjoon commented Apr 30, 2021 via email

@joonjoonjoon
Copy link
Author

My workaround did not work, I am still getting ThreadAbort errors when building, and the result is that the bundle is not signed and the progress window shows me "Importing Assets" and never finishes.

The debug line above this reads "Signing bundle..."
and then this:

Exception failed: System.Threading.ThreadAbortException
  at (wrapper managed-to-native) System.Threading.WaitHandle.Wait_internal(intptr*,int,bool,int)
  at System.Threading.WaitHandle.WaitOneNative (System.Runtime.InteropServices.SafeHandle waitableSafeHandle, System.UInt32 millisecondsTimeout, System.Boolean hasThreadAffinity, System.Boolean exitContext) [0x00019] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Threading.WaitHandle.InternalWaitOne (System.Runtime.InteropServices.SafeHandle waitableSafeHandle, System.Int64 millisecondsTimeout, System.Boolean hasThreadAffinity, System.Boolean exitContext) [0x00014] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Threading.WaitHandle.WaitOne (System.Int64 timeout, System.Boolean exitContext) [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Threading.WaitHandle.WaitOne (System.Int32 millisecondsTimeout, System.Boolean exitContext) [0x00019] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Diagnostics.Process.WaitForExit (System.Int32 milliseconds) [0x00024] in <aa976c2104104b7ca9e1785715722c9d>:0 
  at System.Diagnostics.Process.WaitForExit () [0x00000] in <aa976c2104104b7ca9e1785715722c9d>:0 
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.WaitForExit()
  at Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine.RunViaShellInternal (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine+IOHandler ioHandler, System.Boolean useShellExecution, System.Boolean stdoutRedirectionInShellMode) [0x00341] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/PlayServices/CommandLine.cs:645 
  at Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine.RunViaShell (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine+IOHandler ioHandler, System.Boolean useShellExecution, System.Boolean stdoutRedirectionInShellMode) [0x00022] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/PlayServices/CommandLine.cs:541 
  at Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine.Run (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine+IOHandler ioHandler) [0x00000] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/PlayServices/CommandLine.cs:504 
  at Google.Android.AppBundle.Editor.Internal.BuildTools.JarSigner.Sign (System.String zipFilePath) [0x00098] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/JarSigner.cs:121 
  at Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder.CreateBundle (System.String aabFilePath, Google.Android.AppBundle.Editor.AssetPackConfig assetPackConfig) [0x002b0] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:305 
  at Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder+<>c__DisplayClass45_0.<CreateBundleAsync>b__1 () [0x00000] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:344 
UnityEngine.Debug:LogError (object)
Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder:DisplayBuildError (string,string) (at Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:765)
Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder/<>c__DisplayClass45_0:<CreateBundleAsync>b__1 () (at Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:349)
System.Threading.ThreadHelper:ThreadStart ()

@thanwah
Copy link
Contributor

thanwah commented May 4, 2021

I wasn't able to reproduce this on an Intel Mac with Unity 2020.3.3f1.

Since you mentioned that this may be due to the Editor not having focus, I tried adding the following code to HandleUpdate() method that is triggered by EditorApplication.update:

var tmp = InternalEditorUtility.isApplicationActive;
if (tmp != _lastIsApplicationActive)
{
    Debug.Log("isApplicationActive new value " + tmp);
}
_lastIsApplicationActive = tmp;

I found that even when I opened another program while the build was running and saw isApplicationActive change from true to false, the HandleUpdate() method continued to receive callbacks and the build finished successfully.

I unfortunately don't have an M1 Mac to test on.

@joonjoonjoon
Copy link
Author

Yes, I believe you are right and my original assumption that this was related was wrong.
It seems to crash pretty randomly, as in

  • sometimes it finishes,
  • sometimes it crashes after "Running Bundletool"
  • sometimes it crashes after "Signing Bundle"

It might be an M1 specific issue then?
It always crashes with this error.

Exception failed: System.Threading.ThreadAbortException
  at (wrapper managed-to-native) System.Threading.WaitHandle.Wait_internal(intptr*,int,bool,int)
  at System.Threading.WaitHandle.WaitOneNative (System.Runtime.InteropServices.SafeHandle waitableSafeHandle, System.UInt32 millisecondsTimeout, System.Boolean hasThreadAffinity, System.Boolean exitContext) [0x00019] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Threading.WaitHandle.InternalWaitOne (System.Runtime.InteropServices.SafeHandle waitableSafeHandle, System.Int64 millisecondsTimeout, System.Boolean hasThreadAffinity, System.Boolean exitContext) [0x00014] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Threading.WaitHandle.WaitOne (System.Int64 timeout, System.Boolean exitContext) [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Threading.WaitHandle.WaitOne (System.Int32 millisecondsTimeout, System.Boolean exitContext) [0x00019] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at System.Diagnostics.Process.WaitForExit (System.Int32 milliseconds) [0x00024] in <aa976c2104104b7ca9e1785715722c9d>:0 
  at System.Diagnostics.Process.WaitForExit () [0x00000] in <aa976c2104104b7ca9e1785715722c9d>:0 
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.WaitForExit()
  at Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine.RunViaShellInternal (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine+IOHandler ioHandler, System.Boolean useShellExecution, System.Boolean stdoutRedirectionInShellMode) [0x00341] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/PlayServices/CommandLine.cs:645 
  at Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine.RunViaShell (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine+IOHandler ioHandler, System.Boolean useShellExecution, System.Boolean stdoutRedirectionInShellMode) [0x00022] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/PlayServices/CommandLine.cs:541 
  at Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine.Run (System.String toolPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.Dictionary`2[TKey,TValue] envVars, Google.Android.AppBundle.Editor.Internal.PlayServices.CommandLine+IOHandler ioHandler) [0x00000] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/PlayServices/CommandLine.cs:504 
  at Google.Android.AppBundle.Editor.Internal.BuildTools.BundletoolHelper.Run (System.String bundletoolCommand, System.Object[] args) [0x0001f] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/BundletoolHelper.cs:277 
  at Google.Android.AppBundle.Editor.Internal.BuildTools.BundletoolHelper.BuildBundle (System.String outputFile, System.Collections.Generic.IEnumerable`1[T] moduleFiles, System.Collections.Generic.IEnumerable`1[T] metadataFiles, Google.Android.AppBundle.Editor.Internal.BuildTools.BundletoolHelper+BuildBundleConfigParams buildBundleConfigParams) [0x00068] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/BundletoolHelper.cs:229 
  at Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder.CreateBundle (System.String aabFilePath, Google.Android.AppBundle.Editor.AssetPackConfig assetPackConfig) [0x0026d] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:294 
  at Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder+<>c__DisplayClass45_0.<CreateBundleAsync>b__1 () [0x00000] in /Users/joon/git/inua/Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:345 
UnityEngine.Debug:LogError (object)
Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder:DisplayBuildError (string,string) (at Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:774)
Google.Android.AppBundle.Editor.Internal.BuildTools.AppBundleBuilder/<>c__DisplayClass45_0:<CreateBundleAsync>b__1 () (at Assets/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs:350)
System.Threading.ThreadHelper:ThreadStart ()

@binouze
Copy link

binouze commented May 24, 2021

Hi, I have the same problem,
it seems related to the fact that I change the Compiler Arguments at the end of the build (OnPostprocessBuild) but the build is not really complete, Anyway to know when the build is totally complete ?
I added a log after AppBundlePublisher.Build and AppBundlePublisher.BuildAndRun, but I got the log before "Processing asset pack 1 of 2..." so the compilation is not finished.

For infomation, I use Unity 2021.1.3f1 on Windows 10

[EDIT]
I manged to get it work by adding a static Action var to call at the same time as AppBundleBuilder._createBundleAsyncOnSuccess.
But it would be great to be able to give a complete handler in AppBundlePublisher.Build and AppBundlePublisher.BuildAndRun.
Or maybe a yield instruction like in PlayAssetBundleRequest and so we could do while( !build.IsDone ){...}

@davidejones88
Copy link

davidejones88 commented Jun 16, 2021

Hi! I have the same problem, Windows10, Unity 2020.3, definitely not an M1 issue.

In my case, I believe the problem is that when I use AppBundlePublisher.BuildBundle with BuildOptions.AutoRunPlayer unity deploys the aab as soon as it's ready, while BuildTool is still trying to do its thing, so I end with the game running on the device pushed by Unity but in a faulty state as no AssetBundles are present.

This theory is somehow confirmed by the fact that everything works fine if I use AppBundlePublisher.BuildAndRun();.

@binouze May I ask for more details on how exactly did you solve this? Are you using the static Action instead of OnPostprocessBuild to 'manually' know when the build is ready?

@thanwah It would be nice to have a AppBundlePublisher.BuildAndRun(); that accepts BuildOptions in the future!

@binouze
Copy link

binouze commented Jun 16, 2021

@davidejones88 Yes, that's it.
I added a static variable OnBuildComplete in com.google.android.appbundle/Editor/Scripts/Internal/BuildTools/AppBundleBuilder.cs
It's called in the lambda _createBundleAsyncOnSuccess of the function CreateBundleAsync.
After that, instead of using OnPostProcessBuild I assigned my post process build function to AppBundleBuilder.OnBuildComplete.
Hope it's clear enough.

@davidejones88
Copy link

@binouze Yes, thanks! It worked like a charm to solve the post-process issue.

But it would be great to be able to give a complete handler in AppBundlePublisher.Build and AppBundlePublisher.BuildAndRun.
Or maybe a yield instruction like in PlayAssetBundleRequest and so we could do while( !build.IsDone ){...}

@thanwah This idea from @binouze should be really taken into consideration for next updates!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants