The question was how to check the version at runtime. However. Please use the search function how to use the phone library or search for "p.sdkversion" to see examples.
If errors occur, we need to see the exception message (via logs). And yes... There are always messages in the logs. Get used to check those messages to know what went wrong. If you get online with your app, you get exactly those messages from Google. So no magic here.