1

I'm building a Unity game that uses a native android library with one activity. This library includes bluetooth functionality from an sdk for which i created a Helper class that i can't instantiate or reference in any way in my MainActivity without the game crashing.

I'm new to Kotlin and android studio and can't figure out how to fix this.

Building & running in android and unity works without any errors. Running an android native app set up in the same way like the android library, works flawless.

But when running the game independantly on phone it crashes, this has been tested on multiple devices.

MainActivity snippet

import com.X.unitylib.BluetoothDeviceHelper //this import is not used for some reason

    class MainActivity : UnityPlayerActivity ()/*, BluetoothDeviceHelper.Listener*/ {
    
            private lateinit var bluetoothDeviceHelper: BluetoothDeviceHelper // App runs with this
            //private var bluetoothDevices = emptyList<BluetoothDeviceHelper.BluetoothDevice>() //Doesn't run
            //private var connectedBluetoothDevice: BluetoothDeviceHelper.BluetoothDevice? = null //Doesn't run
        
            override fun onCreate(savedInstanceState: Bundle?) {
                super.onCreate(savedInstanceState)
                bluetoothDeviceHelper = BluetoothDeviceHelper(applicationContext) //App doesn't run with this uncommented
            }
        
           /* override fun onStart() {
                super.onStart()
                //bluetoothDeviceHelper.addListener(this)
                bluetoothDeviceHelper.startScan()
            }*/

**BluetoothDeviceHelper snippet**

    class BluetoothDeviceHelper(context: Context) : BLEDevice.Delegate<BLEDevice>, BLEManager.Delegate<BLEObject>
  • Edit: was able to fix a couple issues so i updated my initial description and replaced the outdated stack trace with the latest error.

  • Edit2: New error, on monday i'll try the steps described in the link below and once i get it working, i'll post an answer with all the steps i took for others that end up in the same fringe situation.

Kotlin and Unity development error

latestError

Dane Gillis
  • 137
  • 1
  • 3
  • 14
  • 2
    Need to see the stack trace. – Tenfour04 Dec 10 '20 at 16:08
  • Thanks for responding, i turned on stack trace in unity player settings and added --stacktrace to compiler command-line options but where should i see the stack trace? When running on phone from android there's no problem but also nothing there since the actual app is made in unity and when using unity remote and pressing play, the app also runs with no problem. It's only when i run the app independantly on phone that it crashes on startup, and only when try to use the bluetoothDeviceHelper, else it runs fine. – Dane Gillis Dec 10 '20 at 18:06
  • View LogCat in Android Studio while running the game or standa-alone app. It will show the stack trace in the log. – Tenfour04 Dec 10 '20 at 18:09
  • Nothing is added to Logcat when i run the unity app but i added the stacktrace when i run the library and an error that came up when i plugged in my phone. – Dane Gillis Dec 11 '20 at 08:27

0 Answers0