Search Unity

Android crashes on Initialization.

Discussion in 'Unity Ads & User Acquisition' started by dvirus1023, Dec 28, 2014.

  1. dvirus1023

    dvirus1023

    Joined:
    Mar 4, 2013
    Posts:
    51
    I am trying to implement UnityAds into an android game. It works fine showing the sample ads in the editor, but as soon as I attempt to build and run it on device, it closes as soon as I try and Initialize.

    Right before I see the WIN DEATH log in the Logcat it logs this error:
    UnityAds: com.unity3d.ads.android.webapp.f.b() (line:755) :: Problems opening stream: failed to connect to impact.applifier.com/127.0.0.1 (port 443) after 20000ms: isConnected failed: ECONNREFUSED (Connection refused)

    I googled some and only came across one other instance of this being report and I could get no help out of reading the thread.

    This is using the latest build from the Asset Store, starting with a blank Unity Project and creating a Non-Released game on the UnityAd's site.

    The only thing in the project is the script from the integration guide attached to the camera. I did this to remove any other issues that could have been happening with my main game.

    Has anyone else encountered this? Or can see a missed step that I missed in integrating Ads into android.

    Thanks,
    Dan
     
  2. dvirus1023

    dvirus1023

    Joined:
    Mar 4, 2013
    Posts:
    51
    Could this be a case of not being able to test Ads in a game that is still only in development? Can you only hit the UnityAds server for games that are currently live?

    @unity-nikkolai, I see that you are on these boards answering questions fairly frequently, any chance you have any ideas as to why I could be having issues?
     
    Yash987654321 likes this.
  3. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Your game doesn't need to be live to see ads. You can run in Development Mode and it's recommend to initialize Unity Ads in your game with test mode enabled while testing.

    Did you move any of the Unity Ads assets around in your project after importing? Might be worth removing the existing version of Unity Ads from your project, just by deleting the files. Then download and import it again.

    If you have the Stripping Level set to anything other than Disabled in Player Settings, you'll need the file named "link" in the Assets directory of your project. This ensures you keep libraries for www classes.

    Could you copy the logcat output from startup to crash to a gist and share that with me? Also, if you wouldn't mind, try building one of the example scenes in this project to see if you get the same results.
     
    TheWarper and Hamid1350 like this.
  4. dvirus1023

    dvirus1023

    Joined:
    Mar 4, 2013
    Posts:
    51
    I will do all of the above when I get home and report back. Thanks for the quick response, I appreciate it.
     
    unity-nikkolai likes this.
  5. dvirus1023

    dvirus1023

    Joined:
    Mar 4, 2013
    Posts:
    51
    I built the Unity Ads demo and pushed to my Nexus 5 and it crashed at Initialization. I have copied over the Logcat, the initialization starts at line 295.

    https://gist.github.com/anonymous/885772b97881a8a48f42

    I am going to try and find another device to test on, as if your project normally works it must be my device.
     
    unity-nikkolai likes this.
  6. dvirus1023

    dvirus1023

    Joined:
    Mar 4, 2013
    Posts:
    51
    Ok, I tested on another phone and your project works fine. My guess is that the rom that is on my other device must have some sort of ad blocking built in, which for some reason causes the UnityAd code to completely bomb and close the app.

    I was going to request to close the thread, but I will leave open as maybe you or someone else on the UnityAds team could code around this scenario and prevent the application from crashing when this occurs during initialization.

    Thanks,
    Dan
     
    unity-nikkolai likes this.
  7. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    This seems to be related to adblocking on some Android 5 devices. We've gotten one other report about crashing with android 5 & adblock.

    This does not happen on all android 5 devices, we've so far been able to re-produce this with jailbroken android 5 with adblock.

    Android 5 does not yet today have significant share on the marketplace (https://developer.android.com/about/dashboards/index.html) , but we will look into this as soon as possible.

    Cheers,
    Heikki
     
  8. dvirus1023

    dvirus1023

    Joined:
    Mar 4, 2013
    Posts:
    51
    Awesome, Glad you are able to reproduce the issue. That is the same scenario I was in when noticing it, but I think the adblock was baked into the rom. Once I switched roms on the phone it worked as expected.

    Thanks for looking into it.
     
  9. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    What ROM were you using?

    H
     
  10. dvirus1023

    dvirus1023

    Joined:
    Mar 4, 2013
    Posts:
    51
    unity-nikkolai likes this.
  11. TheWarper

    TheWarper

    Joined:
    Nov 3, 2013
    Posts:
    112
    Thanks! Disabling Stripping for Android solved this in Unity 5.3.1f1 for me.

    Is there a way to bypass this in the latest version without disabling stripping for Android?
     
  12. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    TheWarper likes this.
  13. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    The bug has been fixed internally now, and will let you know here as soon as we have verified and released it
     
    TheWarper likes this.
  14. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Any update on it? I am experiencing the same problem right now. UnityAds + Android = crash.
     
  15. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    It's set to be released with Unity 5.3.3, and I'll let you know here as soon as it's released in a patch build (most likely during February). Another workaround is to select IL2CPP in player build settings.

    -Rasmus
     
  16. USAPRODUCER

    USAPRODUCER

    Joined:
    Mar 2, 2016
    Posts:
    5
    My android game still crashes with Unity ads installed. I can't seem to find anything other than this page on it. Can anyone suggest links to trouble shooting this?
     
  17. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Which version of Unity/Ads are you using?
     
  18. USAPRODUCER

    USAPRODUCER

    Joined:
    Mar 2, 2016
    Posts:
    5
    I'm using the latest version of unity and I turned ads on via services tab. I'm using the sample code for interstitial ads. It works in the editor and as a test apk that I've loaded on my android. It does not work when I export it as a Google Android Project.
    I've created a play again UI game button. Attached the script to the canvas. Added the onclick function to the button.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3.  
    4. public class unity_ad : MonoBehaviour
    5. {
    6.     public void ShowAd()
    7.     {
    8.         if (Advertisement.IsReady())
    9.         {
    10.             Advertisement.Show();
    11.  
    12.             Application.LoadLevel ("scene2");
    13.         }
    14.     }
    15.  
    16.  
    17.  
    18. }
     
    Last edited: Apr 5, 2016
  19. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Thanks for info about building from Android Studio. Can you please check your adb log from device, if it contains information about the crash? E.g. have you added/changed ProGuard settings in your project?
     
  20. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Btw, what is the reason you are exporting to Android Studio project?
     
  21. USAPRODUCER

    USAPRODUCER

    Joined:
    Mar 2, 2016
    Posts:
    5
    To place the game onto the google play store. Do I not have to bring it into Android Studio? Now I feel like I'm all turned around. LOL If there's an easier way I'll take it.
    I did not touch ProGuard and I'll check the adb log and post.
     
    Last edited: Apr 7, 2016
  22. USAPRODUCER

    USAPRODUCER

    Joined:
    Mar 2, 2016
    Posts:
    5
    Wow, it worked just uploading the apk directly to the play store. I was just following tutorials and thought I needed to bring the apk into Android studio as a google android project. So psyched. And Unity Ads worked. Thanks so much.
     
  23. byerdelen

    byerdelen

    Joined:
    Mar 27, 2010
    Posts:
    68
    Hi,
    I have a crash on Android directly related to the Unity Ads.
    It was working fine 3 months ago builds(interestingly it doesn't work with 3 months ago build now) and also it works fine with IOS.
    I didn't touch anything on the codeside of ads(rewarded videos) since it was working before.

    Basicly, problem is that it crashes after I watch a video and press close button of the video.
    It gives such error log among other messages but I believe this causes the crash:
    [EGL] Unable to acquire context: EGL_BAD_NATIVE_WINDOW: A NativeWindowType argument does not refer to a valid native window.

    I am building with Mono2x. It has some Prime31 plugins but nothing is updated since the working version instead of the Unity version that I use 5.3.4p1

    Do you have any ideo what may cause the crash? If not, I can send the whole crash debug message.

    Thanks
     
  24. Shiratori

    Shiratori

    Joined:
    Aug 27, 2014
    Posts:
    21
    Hi! I have been experimenting, trying to get unity ads to work in my latest game on Android.
    The issue I'm having is that as soon as a video is shown on the mobile, the app crashes and restarts. At most you can hear the ad sound for about 100-200ms before it crashes.
    The project is an almost clean project with unity ads added. Unity ads has been set up according to all guides and the code implementation is straight from the examples.

    The test ad shows perfectly in the editor.

    logcat shows the following output when the ad is trying to show:

    I/ActivityManager( 733): START u0 {flg=0x10010000 cmp=com.ByteSizedGames.ProductName/com.unity3d.ads.android.view.UnityAdsFullscreenActivity} from pid 10151
    W/ActivityManager( 733): mDVFSHelper.acquire()
    W/ActivityManager( 733): Permission Denial: getCurrentUser() from pid=10151, uid=10141 requires android.permission.INTERACT_ACROSS_USERS
    I/ActivityManager( 733): Config changes=480 {0 1.0 240mcc2mnc en_US ldltr sw320dp w533dp h294dp 240dpi nrml long land finger -keyb/v/h -nav/h s.95}
    I/ActivityManager( 733): Displayed com.ByteSizedGames.ProductName/com.unity3d.ads.android.view.UnityAdsFullscreenActivity: +522ms
    W/ActivityManager( 733): mDVFSHelper.release()
    I/ActivityManager( 733): Process com.ByteSizedGames.ProductName (pid 10151) (adj 0) has died.
    W/ActivityManager( 733): Force removing ActivityRecord{42532330 u0 com.ByteSizedGames.ProductName/com.unity3d.ads.android.view.UnityAdsFullscreenActivity t51}: app died, no saved state


    I have yet to find people with similar issues as mine online. In my research android.permission.INTERACT_ACROSS_USERS seems to be a permission normal developers can't set by themselves. Is there anything I'm missing? Why would unity ads need the android.permission.INTERACT_ACROSS_USERS permission?

    Using Unity v5.3.4f1 personal.

    Best regards, Shiratori.
     
    unity-nikkolai likes this.
  25. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    What is the Android system version you're seeing this issue with?
     
  26. Shiratori

    Shiratori

    Joined:
    Aug 27, 2014
    Posts:
    21
    My test device is a Samsung Galaxy ace 4 running Android 4.4.4.

    I had a theory regarding the crash since the call to getCurrentUser() seems to trigger the crash. My device had the details of two different google accounts on it. My main account, and a friends account used for testing google play services with another account than my own. I thought this might be a reason for the crash and removed the secondary account, However, no change was made regarding the issue with Unity Ads crashing.
     
  27. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Do you have any other plugins included in your project?

    Just to eliminate any external influences, try importing the UnityAdsHelper asset package into a new Unity project. Then enable and configure the Ads service, and build it to device with the UnityAdsExample scene.

    I haven't seen this issue before, and I wasn't able to find the getCurrentUser method anywhere in our source. I suspect it may be external to the Unity Ads SDK and our webview content.

    Please let me know what the results are. If you are able to reproduce the issue, please send me a link to the APK.
     
  28. Shiratori

    Shiratori

    Joined:
    Aug 27, 2014
    Posts:
    21
    I will try this today and come back to you!