snowplow / snowplow-android-tracker

Snowplow event tracker for Android. Add analytics to your Android apps and games
http://snowplowanalytics.com
Apache License 2.0
110 stars 63 forks source link

Handle more generic exceptions when using InstallReferrer #647

Closed corbella83 closed 6 months ago

corbella83 commented 11 months ago

Describe the bug Currently The SnowPlow library is using this library as "compileOnly".

compileOnly "com.android.installreferrer:installreferrer:2.2"

compileOnly means that it's mandatory for the library, but is not shipped with the artifact. This currently means that the SnowPlow library cannot be used in a project that doesn't have the installreferrer. And currently makes a crash:

java.lang.NoSuchMethodError: No virtual method getGooglePlayInstantParam()Z in class Lcom/android/installreferrer/api/ReferrerDetails; or its super classes (declaration of 'com.android.installreferrer.api.ReferrerDetails' appears in /data/app/~~PHQ96RItx6M1UppnjKIAiQ==/com.inditex.zara-kj-XCASo7_iDxnet0B7pkw==/base.apk) at pj1.f.onInstallReferrerSetupFinished(InstallReferrerDetails.kt:88) at l8.a$a.onServiceConnected(InstallReferrerClientImpl.java:37) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2313) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2350) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:230) at android.os.Looper.loop(Looper.java:319) at android.app.ActivityThread.main(ActivityThread.java:8893) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

The crash happens in InstallReferrerDetails.kt line 72. There is a try/catch protecting it. But the catch is only handling RemoteException, while the system throws a NoSuchMethodError. NoSuchMethodError is not a subclass of RemoteException.

In order to allow using the library without installreferrer library, I would capture all possible exceptions (throwable: Throwable) in the try/catch.

To Reproduce Use the last version of SnowPlow library in a project that doesn't have installreferrer library. Then send some events.

Expected behavior Should not crash when the app using the SnowPlow library doesn't have the installreferrer library

Screenshots Not applicable

Device informatoin (please complete the following information):

matus-tomlein commented 11 months ago

Hi @corbella83, thank you for reporting this!

To be honest, I am a little confused about this error. In case the installreferrer library is not present in the project, the code should never reach line 72 of the InstallReferrerDetails.kt file. It should stop at this condition on line 54 which checks for the presence of the InstallReferrerStateListener class. Do you have any ideas how come that condition evaluates to true despite the library not being present?

corbella83 commented 11 months ago

Yes, I thought about that but indeed it reaches this line. I will download the library code and try to debug it to have more info. Also, I'll try to make a simple project that reproduces the crash

corbella83 commented 11 months ago

@matus-tomlein I have some news about this.

This happens when using an old version of installreferrer (1.0). When using this version, the condition on line 54 is letting the code pass through because really is included, but the function on line 72 was introduced in version 1.1 (according to the installreferrer changelog) and can't be found, throwing a NoSuchMethodError

matus-tomlein commented 11 months ago

That makes sense, thanks for investigating that! So we should detect the version of the package and only add that property if install referrer version 1.1 is used.

dpgmedia-gbero commented 7 months ago

We're facing the same issue with an app using Facebook applinks which relies on InstallReferer 1.0

Is this still being implemented ?

mscwilson commented 7 months ago

Sorry for the delay! I've made a PR, this fix will be out in the next patch release, once one other bug report has been addressed