google / play-unity-plugins

The Google Play Plugins for Unity provide C# APIs for accessing various Play services
Other
443 stars 115 forks source link

ANR exception #36

Open Sortexsvg opened 4 years ago

Sortexsvg commented 4 years ago

I am getting the ANR exception in PlayStore Console .

Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{20915a2 u0 com.packages.name/com.google.android.play.core.assetpacks.AssetPackExtractionService}.

How to slove this?

Few user also complained that asset bundle didn't download. It was stuck at some point. Didn't progress further. If I get any error during the asset bundle download, I will start downloading once again until the download is successful.

I will put 5 to 6 asset bundle at a time for download. Below I have written the code to download 5 to 6 asset bundle.

//--------------------------------------------------------------------------------- for(int i=0;i<assetbundleNames.Count;i++) { StartCoroutine( DownloadAssetBundle(assetbundleNames[i])); }

IEnumerator DownloadAssetBundle(string assetBundleName) { PlayAssetBundleRequest bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync (assetBundleName); while (!bundleRequest.IsDone) { yield return null; } if (bundleRequest.Error != AssetDeliveryErrorCode.NoError) { // Will start Download Once again DownloadAssetBundleOnceAgain(assetBundleName); } else { // No error . So Will Cache Asset Bundle AssetBundle assetBundle = bundleRequest.AssetBundle; } } //---------------------------------------------------------------------------------

How can I solve this?

I am using

jamcohen commented 4 years ago

Thanks for posting this issue.

Is this something you can reproduce locally? Does it occur consistently or only occasionally?

There is a known issue in the underlying Play Core library that would produce the error you mention. It occurs when the app's Application.OnCreate() process takes a long time (on the order of 5-10 seconds). You could try reducing the amount of data you load in your initial scene and see if that fixes the issue. You could also add a Thread.sleep() into the UnityPlayerActivity OnCreate method to reproduce it locally.

You can try updating the Plugin Version to 1.2 which includes the latest version of Play Core which includes fixes for other bugs that could lead to the Context.startForegroundService() error.

Let me know if any of these options work for you.

Sortexsvg commented 4 years ago

Thanks for your response.

Here is the answer for your questions.

  1. Is this something you can reproduce locally?

    • No
  2. Does it occur consistently or only occasionally?

    • occasionally (for few users we got this)

I can edit UnityPlayerActivity only in Android Studio. To do that I have to exporty project. But gradle project do not include on demand asset bundles right?

Then How can I edit UnityPlayerActivity ?

jamcohen commented 4 years ago

You're right that exported gradle projects don't include on demand asset bundles. I know of two ways to add code to the UnityPlayerActivity.onCreate() method :

  1. The quick and hacky way is to edit the UnityPlayerActivity for your Unity version in the PlayBackEngines folder next to your Unity executable. Example: /Applications/Unity/Hub/Editor/2018.4.6f1/PlaybackEngines/AndroidPlayer/Source/com/unity3d/player/UnityPlayerActivity.java
  2. You can create your own Activity that extends from UnityPlayerActivity and add an AndroidManifest to your project that points to that Activity. See here for details.
Sortexsvg commented 4 years ago

I have updated the Plugin and still issue didn't solve. ANR exceptions keep coming. Is there any other fix I should try?

jamcohen commented 4 years ago

Thank you for trying the latest update. If the updating the plugin didn't fix the issue, it is either being caused by the issue I mentioned in my first comment, or is something unrelated and unknown.

Have you tried reproducing the issue by editing the UnityPlayerActivity?

Sortexsvg commented 4 years ago

Sorry for the late reply.

We could not able to reproduce the issue by editing the UnityPlayerActivity.

Any other method you can suggest us?

pphaolu commented 3 years ago

We also encountered the same issue. A few users had this ANR. We suggested them upgrading the Google Play App. Some of them can solve it. We don’t know how to fix it by coding, any suggestions? Thank you.

mry-ship commented 3 years ago

image

I add startForeground() in AssetPackExtractionService.java; I find ExtractionForegroundService.java have startForeground(),but AssetPackExtractionService is not have this;

alex-zakrzhevskiy commented 3 years ago

I add startForeground() in AssetPackExtractionService.java; I find ExtractionForegroundService.java have startForeground(),but AssetPackExtractionService is not have this;

Can you describe how did you do that for Unity? Did that help with ANRs in Google Console?

ariallyp commented 3 years ago

Hi ,i also have this problem in my app ,have you solved ?

syedarif503 commented 2 years ago

I am getting the ANR exception in PlayStore Console .

Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{20915a2 u0 com.packages.name/com.google.android.play.core.assetpacks.AssetPackExtractionService}.

How to slove this?

Few user also complained that asset bundle didn't download. It was stuck at some point. Didn't progress further. If I get any error during the asset bundle download, I will start downloading once again until the download is successful.

I will put 5 to 6 asset bundle at a time for download. Below I have written the code to download 5 to 6 asset bundle.

//--------------------------------------------------------------------------------- for(int i=0;i<assetbundleNames.Count;i++) { StartCoroutine( DownloadAssetBundle(assetbundleNames[i])); }

IEnumerator DownloadAssetBundle(string assetBundleName) { PlayAssetBundleRequest bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync (assetBundleName); while (!bundleRequest.IsDone) { yield return null; } if (bundleRequest.Error != AssetDeliveryErrorCode.NoError) { // Will start Download Once again DownloadAssetBundleOnceAgain(assetBundleName); } else { // No error . So Will Cache Asset Bundle AssetBundle assetBundle = bundleRequest.AssetBundle; } } //---------------------------------------------------------------------------------

How can I solve this?

I am using - Unity 2018.4.20 - Play Asset Plugin Version 1.1 Same facing problem any one resolve its?

danyow commented 2 years ago

I got this problem too

WBoda commented 2 years ago

We also encountered the same issue I am using - Unity 2018.4.36

troy-lamerton commented 2 years ago

This Unity plugin behaves well. The underlying issue is in the com.google.android.play.core package.

There is a known issue in the underlying Play Core library that would produce the error you mention. It occurs when the app's Application.OnCreate() process takes a long time (on the order of 5-10 seconds). You could try reducing the amount of data you load in your initial scene and see if that fixes the issue. You could also add a Thread.sleep() into the UnityPlayerActivity OnCreate method to reproduce it locally.

@jamcohen is there a link to this issue in the Google issue tracker?

It would be helpful to have a link that I can reference.

506638093 commented 2 years ago

image

I add startForeground() in AssetPackExtractionService.java; I find ExtractionForegroundService.java have startForeground(),but AssetPackExtractionService is not have this;

This method works well, after test. Modify the method, check my ZhiHu: https://zhuanlan.zhihu.com/p/577738203?