Android Question How can you test to see if Dropbox is installed?

Turbo3

Active Member
Licensed User
Longtime User
This is a B4A and B4i question. If Dropbox is not installed and my app tries to link to it the app crashes. A Try Catch around manager.LinkAccount does not work to catch the error and my app crashes. Error is:
B4X:
java.lang.ExceptionInInitializerError
    at com.dropbox.sync.android.CoreAccountManager.initNativeLib(CoreAccountManager.java:228)
    at com.dropbox.sync.android.CoreAccountManager.<init>(CoreAccountManager.java:141)
    at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:200)
    at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:160)
    at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:107)
    at anywheresoftware.b4a.dropbox.DbxAccountManagerWrapper.Initialize(DbxAccountManagerWrapper.java:53)
    at com.Turbo3.Leaf_Spy_Pro.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv7(main.java:14181)
    at com.Turbo3.Leaf_Spy_Pro.main._timer1_tick(main.java:17026)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:155)
    at android.app.ActivityThread.main(ActivityThread.java:5454)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load DropboxSync: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
    at java.lang.System.loadLibrary(System.java:535)
    at com.dropbox.sync.android.NativeLib.ensureLoaded(NativeLib.java:70)
    at com.dropbox.sync.android.NativeLib.<clinit>(NativeLib.java:32)
    ... 21 more

I need a way to know to skip the dropbox code if dropbox is not installed on the device.
 

Turbo3

Active Member
Licensed User
Longtime User
Erel, I think you are correct. When I went and installed Dropbox on that device the error did not go away. I have two other Android devices that have dropbox installed and my app runs fine. But I had a report for my iOS app that seems to indicate a problem if dropbox was not installed. Since I was working on the Android version today I decided to test with that version by taking a new device that did not have dropbox on it and found the app did crashed so I made a bad assumption it was the same problem as the iOS version. Now that I have installed Dropbox on this third device and the crash is still there I will need to do more analysis to see what is going on with it as well as look into the crash on the iOS version. In both cases enabling Dropbox in my app is the trigger for the crashes.

What should I expect to see if Dropbox is not installed on the device and my app tries to link to it? How should it be handled?

But the failing code is for dropbox and a Try/Catch did not help which seemed strange.
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
To test I uninstalled Dropbox and uninstalled my app that uses Dropbox. I then re-install my app and enable Dropbox support but did NOT install the Dropbox app on the device.

Using debug mode I can see my code execute the "manager.Initialize(key,secret, "manager")" instruction and then the "manager.LinkAccount(Page1)". (This is actually the iOS code I am testing but I don't think that should make a difference.) A Log message after the "manager.LinkAccount" shows it got executed without error.

On the screen I see my app screen go away and a new screen with the title "Dropbox" appear for a few seconds, contents is blank. That screen goes away and we are back at the Home screen. I would normally expect to see a Dropbox login screen but I just get this blank screen that closes after a few seconds.

My app is now in trouble because the "Use Dropbox flag" in my app is set and each time my app starts the users sees my app screen followed by the blank screen titled "Dropbox" that goes away in a few seconds and then is dumped back at the Home screen.

The only way out of this is to install the Dropbox app on the device or uninstall and re-install my app to clear the use Dropbox flag.

Is this what I should see happening if Dropbox is not installed?

It would be nice if my app could warn or not even give the option to use Dropbox if the Dropbox app has not been installed on the device if that is a prerequisite for B4x Dropbox support or at least needed to initially setup the link.

The strange part is once I have installed Dropbox and gotten the connection made so my app runs I can then delete the Dropbox app and my app continues to work uploading data to Dropbox. So it appears the Dropdbox app is only needed the first time to setup the link.
 
Last edited:
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
It should be as easy as using packagemanager to check if the dropbox package is installed.
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
Thanks, that will work for the B4A version but for my B4i version Apple does not allow that function.
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
Problem solved (at least for the B4i version).

After some more debugging it turns out the problem is with the way my app runs.

One major correction. The Dropbox app does not need to be installed for a B4x app to use Dropbox.

What caused my problem was the one second tick routine my app uses to control when things get executed. I did not set a flag to indicate the LinkAccount command had been executed. This caused a second series of commands to be sent if the first one did not get a response within the one second tick. Sending these commands a second time is what caused the app to terminate. But sometimes the response came back in time which allowed the Link to succeed. Once linked the response time to the LinkAccount command is very fast completing before the next timer tick.

Once the LinkAccount succeeded I needed to uninstall and reinstall the app to recreate the conditions that potential cause the problem.
 
Last edited:
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
I am still getting the crash on one phone an HTC running Android 4.1.1. Here is the crash data:
B4X:
** Activity (main) Create, isFirst = true **
Start Manager
java.lang.ExceptionInInitializerError
    at com.dropbox.sync.android.CoreAccountManager.initNativeLib(CoreAccountManager.java:228)
    at com.dropbox.sync.android.CoreAccountManager.<init>(CoreAccountManager.java:141)
    at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:200)
    at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:160)
    at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:107)
    at anywheresoftware.b4a.dropbox.DbxAccountManagerWrapper.Initialize(DbxAccountManagerWrapper.java:53)
    at com.Turbo3.Leaf_Spy_Pro.main._activity_create(main.java:1193)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at com.Turbo3.Leaf_Spy_Pro.main.afterFirstLayout(main.java:100)
    at com.Turbo3.Leaf_Spy_Pro.main.access$100(main.java:17)
    at com.Turbo3.Leaf_Spy_Pro.main$WaitForLayout.run(main.java:78)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:155)
    at android.app.ActivityThread.main(ActivityThread.java:5454)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load DropboxSync: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
    at java.lang.System.loadLibrary(System.java:535)
    at com.dropbox.sync.android.NativeLib.ensureLoaded(NativeLib.java:70)
    at com.dropbox.sync.android.NativeLib.<clinit>(NativeLib.java:32)
    ... 22 more
But only my app crashes on this phone. If I install a test Dropbox app that has only the Dropbox code it works fine. My app runs fine on the other four phones I have tried it on.

So, based on the crash dump information what could I be doing in my code to cause this one phone to fail?

I have placed the "manager.Initialize(key, secret, "manager")" code as the first instruction in Activity_Create. So it is the first instruction executed (other than the Log("Start Manager") statement. The manifest is the same between the Dropbox example that works on the HtC and my app which crashes. I have selected the same libraries in both apps and the Process_Globals and Globals are the same between the two. But still the Dropbox example works and my app crashes.

I am hoping Erel can shed some light on what would I could be doing to cause the crash on this one phone. My app has 23 libraries selected if that makes a difference. But I selected the same 23 in the Dropbox example code that runs fine on this phone.
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
I think it must be an ARM since the example Dropbox code works fine on that phone. But the same manager.Initialize() instruction fails when executed in my app.

A Try/Catch does not work. Still get the error and it never executes the Log("Failed") message I put under Catch.
 
Last edited:
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
Yes, basically that code. It works fine on the HTC. But when I put even the first line (manager.Initialiize()) in my app it crashes with the above trace dump but just on the HTC phone. Any of the other phones I have tried it one it works fine.
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
Yes, uninstalling then re-installing fixed the problem.

Do you have an idea why that made it work?
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
Erel thanks for your help in resolving my problem. It is working fine now on the HTC automatically uploading files when they change.

One side benefit is I have much better error handling so if my app can not connect to Dropbox and it crashes on the next restart it will automatically disable using Dropbox so it does not get into an endless loop and force my user to uninstall and re-install the app to clear it.
 
Upvote 0
Top