Unity android build keeps failing

I’ve managed to create an apk using:

With some tweaking, I got it to deploy on an emulator (nexus 4.0, API lvl 28, x86) but it’s stopping without giving any debug related info.

I’m not sure how to debug given that I don’t have the java sources for the project (except from R.java and BuildConfig.java).

Is debugging through android studio possible?

Can you at least use adb to get a logcat out of the device? That way if it is throwing some obvious exception you can at least get some clues.

Supposedly you can attach to a running Android process but I have actually never tried and succeeded. If I have an Android crash I usually just put in enough Debug.Log() output into it to identify where things are going south. You can see all the Debug.Log()/Warning/Error spew with adb -logcat and a USB-attached Android device.

1 Like

The easiest way I’ve found to check the logcat of an app whilst it’s running on the device is to use the Android Device Monitor program which you start by executing Monitor.bat in your android-sdk/tools folder (note it can take at least 10-15 seconds to appear after running the batch file).

With that running and your phone plugged into your PC via a USB cable, you can see a continuous readout of everything your phone logs while it’s happening (you can apply filters to just display the stuff you’re interested in). This makes it very easy to pinpoint errors to particular points in the program execution.

I’ve used this to find and fix many errors that only seem to happen on the device and not in the editor. Also, quite often I find there are a few warnings and errors that, whilst they don’t appear to stop the app working, I feel happier once they’ve been sorted.

2 Likes

The app works when run on a real android device. Thanks. Do you know how can android preferences be interfaced with unity (at a script level)?

Pretty sure this is available by using some of the C# Android-specific Java interface stuff. I would just google for how because you are not the first person to want to do this.

https://docs.unity3d.com/ScriptReference/AndroidJavaClass.html

1 Like