Android Question [SOLVED] Crash when I change package name

Sandman

Expert
Licensed User
Longtime User
I bit of background (not sure how relevant it is):

My app is using geofences, pretty much based on the example code by Erel. In that code there's this sub:
B4X:
Private Sub CreateGeofenceRequest (GeofenceBuilder As JavaObject) As JavaObject
    Dim builder As JavaObject
    builder.InitializeNewInstance("com.google.android.gms.location.GeofencingRequest$Builder", Null)
    builder.RunMethod("setInitialTrigger", Array(1)) 'INITIAL_TRIGGER_ENTER
    builder.RunMethod("addGeofence", Array(GeofenceBuilder.RunMethod("build", Null)))
    Return builder.RunMethod("build", Null)
End Sub

While developing I had the package name set to (something like)
B4X:
com.example.app15

Everything worked nicely. Then I changed the package name to the correct (sort of like)
B4X:
com.example.app

And all of a sudden I'm getting crashes in line #5 above. Specifically, it's this part causing the crash:
B4X:
GeofenceBuilder.RunMethod("build", Null)

And this is the unfiltered log:
B4X:
Error occurred on line: 109 (SRVC_GEOFENCE)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at io.hardhat.id06.srvc_geofence._creategeofencerequest(srvc_geofence.java:292)
    at io.hardhat.id06.srvc_geofence$ResumableSub_AddGeofence.resume(srvc_geofence.java:204)
    at io.hardhat.id06.srvc_geofence._addgeofence(srvc_geofence.java:169)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7664)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalArgumentException: invalid radius: 0.0
    at com.google.android.gms.internal.location.zzbh.<init>(Unknown Source:176)
    at com.google.android.gms.location.Geofence$Builder.build(Unknown Source:162)
    ... 26 more
null: 190
java.net.SocketException: Socket closed
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:144)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:248)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:267)
    at anywheresoftware.b4a.shell.ShellConnector.readControlData(ShellConnector.java:191)
    at anywheresoftware.b4a.shell.ShellConnector.connect(ShellConnector.java:186)
    at anywheresoftware.b4a.shell.ShellConnector.run(ShellConnector.java:119)
    at java.lang.Thread.run(Thread.java:923)

I want to stress that this is reproducible. I change the package name to com.example.app15, clean project and install - works great. I change the package name to com.example.app, clean project and install - crash. Repeated a dozen times until I started believing my eyes.

I find this super confusing, what could be causing this? And how do I solve it?

(I did find two other threads mentioning crashes, 1 and 2, related to package names, but they didn't seem relevant to this post. One post mention problems using uppercase characters in the package name, so I want to say that I only use lowercase characters.)
 
Solution
I had an out of bounds conversation with @JordiCP, who noticed this in the log:
B4X:
Caused by: java.lang.IllegalArgumentException: invalid radius: 0.0    at com.google.android.gms.internal.location.zzbh.<init>(Unknown Source:176)

The radius should never be 0, but apparently I was using that value in some edge-cases. So Jordi suggested to check for that and hardcode it to 100 in those cases. That solved the problem nicely.

I can't believe I didn't catch the message in the log. And I also can't understand how this connects to the package name!

Said Jordi:
I guess that it is not the package name itself. But some sort of setting (a token, an id, whatever) that the "good" on has and the new one not. If you delete and...

Sandman

Expert
Licensed User
Longtime User
I had an out of bounds conversation with @JordiCP, who noticed this in the log:
B4X:
Caused by: java.lang.IllegalArgumentException: invalid radius: 0.0    at com.google.android.gms.internal.location.zzbh.<init>(Unknown Source:176)

The radius should never be 0, but apparently I was using that value in some edge-cases. So Jordi suggested to check for that and hardcode it to 100 in those cases. That solved the problem nicely.

I can't believe I didn't catch the message in the log. And I also can't understand how this connects to the package name!

Said Jordi:
I guess that it is not the package name itself. But some sort of setting (a token, an id, whatever) that the "good" on has and the new one not. If you delete and reinstall a package, I think that Android manages to restore the settings.

It's hard to draw conclusions from this, other than perhaps that geofences are sensitive to package names so don't change that and expect them to work. Perhaps? Maybe? And also to make sure to read the whole error message in the log.

Thanks for the help, @JordiCP!
 
Upvote 0
Solution
Top