dropbox-sdk-java icon indicating copy to clipboard operation
dropbox-sdk-java copied to clipboard

Error loading version from resource "sdk-version.txt": Not found.

Open saurabhit49 opened this issue 9 years ago • 25 comments

I am migrating Dropbox Android V2 API from V1 in my existing project. I have follow this documentation. I have existing project developed with Eclipse. So i have downloaded "dropbox-core-sdk-3.0.3.jar" and "jackson-core-2.9.0.pr3.jar" files and added under lib folder. The V2 dropbox login process works fine and also Auth.getOAuth2Token() method return correct token.

But i am getting issue on calling DropboxClient.getClient(ACCESS_TOKEN) method. I am receiving follwing error...

java.lang.RuntimeException: Error loading version from resource "sdk-version.txt": Not found.

Full Error Stack:

 FATAL EXCEPTION: AsyncTask #1
 Process: com.android.myapp, PID: 23428
 java.lang.RuntimeException: An error occured while executing doInBackground()
 	at android.os.AsyncTask$3.done(AsyncTask.java:304)
 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
 	at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
 	at java.util.concurrent.FutureTask.run(FutureTask.java:242)
 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 	at java.lang.Thread.run(Thread.java:818)
 Caused by: java.lang.ExceptionInInitializerError
 	at com.dropbox.core.DbxRequestUtil.buildUserAgentHeader(DbxRequestUtil.java:146)
 	at com.dropbox.core.DbxRequestUtil.addUserAgentHeader(DbxRequestUtil.java:131)
 	at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:228)
 	at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:100)
 	at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:256)
 	at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:97)
 	at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120)
 	at com.android.myapp.UserAccountTask.doInBackground(UserAccountTask.java:32)
 	at com.android.myapp.UserAccountTask.doInBackground(UserAccountTask.java:1)
 	at android.os.AsyncTask$2.call(AsyncTask.java:292)
 	at java.util.concurrent.FutureTask.run(FutureTask.java:237)
 	... 4 more
 Caused by: java.lang.RuntimeException: Error loading version from resource "sdk-version.txt": Not found.
 	at com.dropbox.core.DbxSdkVersion.loadVersion(DbxSdkVersion.java:66)
 	at com.dropbox.core.DbxSdkVersion.<clinit>(DbxSdkVersion.java:17)
 	... 15 more


saurabhit49 avatar Aug 30 '17 15:08 saurabhit49

[Cross-linking for reference: https://www.dropboxforum.com/t5/API-support/Error-loading-version-from-resource-quot-sdk-version-txt-quot/m-p/239258#M13288 ]

The Dropbox Java SDK contains a "sdk-version.txt" file with the version number for the SDK in it, e.g., for use in the User-Agent string. The error message you posted seems to indicate that this file wasn't found. I just verified that it is included in jar in the v3.0.3 release though.

Did you get the jars from the official dropbox-core-sdk-3.0.3 release here? If not, where did you download it from? I ask because the release includes "jackson-core-2.7.4.jar", but you mentioned "jackson-core-2.9.0.pr3.jar".

Also, can you make sure you added "dropbox-core-sdk-3.0.3.jar" and not "dropbox-core-sdk-3.0.3-sources.jar"?

greg-db avatar Aug 30 '17 19:08 greg-db

Yes, i have included jar from official dropbox release. Yes you are right previously I had added "jackson-core-2.7.4.jar" from release. But after that i have included latest one by searching from internet version "jackson-core-2.9.0.pr3.jar". BTW, error is also same with 2.7.4 version.

Yes, i am sure that i have added "dropbox-core-sdk-3.0.3.jar" and not "dropbox-core-sdk-3.0.3-sources.jar" version.

saurabhit49 avatar Aug 31 '17 04:08 saurabhit49

test_dropbox_2.0.zip I have spend some more time but no clue regarding error. So I have attached my sample project. It will be fine you will take a look with Eclipse IDE and let me know what is wrong with me.

I have replace my original key with "APP-KEY" keyword in Manifest and String.xml file.

saurabhit49 avatar Aug 31 '17 05:08 saurabhit49

I'm not set up for Android development in Eclipse unfortunately, as support for that ended some time ago, so I can't run that. Are you able to reproduce this with Android Studio?

(Also, we highly recommend using Gradle or Maven to manage your dependencies anyway. That's generally easier than manually managing the jar files, especial to keep them up to date over time. If you can, please try that instead and let us know if that helps.)

greg-db avatar Aug 31 '17 19:08 greg-db

I think there is a bug somewhere in Android Studio 3.0 (+ Android gradle plugin 3.0). The apk built by Android Studio when I hit "Run" does not have Java resource files merged correctly (Java resources, not Android res). I verified it by decompiling the apk. Java resource files, and not only those from Dropbox SDK lib, are not there. The apk file (both debug and release) built by running gradle on the command line is assembled correctly.

I haven't been able to pinpoint what exactly causes this bug in AS but I disabled both Instant Run and gradle daemon and that seems to make the problem go away.

tdtran avatar Nov 17 '17 21:11 tdtran

I experienced this as well, @tdtran. Build after build was made without any issues and all of a sudden the sdk-version.txt file was missing. Rebuilding and everything was fine again.

jacobras avatar Nov 19 '17 21:11 jacobras

This still occurs sometimes (once every 15 release builds I'd say), even when using the latest Dropbox SDK dependency from Gradle. The sdk-version.txt file simply isn't included in the APK upon inspection. @greg-db maybe you could look into this?

jacobras avatar Aug 25 '18 14:08 jacobras

@jacobras Based on what tdtran tried, and the fact that is only occurs sporadically, it sounds like this is an issue in the build system, so I'm not sure if we'd be able to fix this on our side.

I can ask the team to investigate anyway, but we still haven't seen it occur in our testing. Is there any chance you could provide a small test project for Android Studio that does reproduce it? Thanks!

greg-db avatar Aug 27 '18 16:08 greg-db

This is a serious issue though, since as far as our build system is concerned, we're doing what we've always done in the past - build an apk and deploy. It's only when these reports started coming in from every other user that we realised it's broken. Saving the version in a .txt file is strange though - txt files aren't supposed to be bundled any way (I'd have thought) and if they are, that's pretty clumsy. Can you not embed that into a static variable in the source code instead?

guidedways avatar Nov 28 '18 21:11 guidedways

I should add I'm not using a jar file, I'm instead using the gradle dependency.

guidedways avatar Nov 28 '18 21:11 guidedways

I wonder if this is because of multi-dex support? Note that with multi-dex enabled (which we do) the actual source code may be in a different dex file, so /sdk-version.txt may point to nothing! This is why it's sporadic. You need to either put it into /res (or /META-INF?) or use a static variable instead. This approach is problematic and buggy.

guidedways avatar Nov 28 '18 21:11 guidedways

For those looking for an immediate fix:

  1. Download the SDK sources
  2. Open DbxSdkVersion.java and change line 35 to:

if (in == null) return "3.0.10"; // throw new LoadException("Not found.");

  1. Open Terminal and install these python libraries:

sudo -H python -m pip install ply six typing

  1. Follow steps on building the Dropbox SDK from sources
  2. Copy the .jar file into your project.

guidedways avatar Nov 28 '18 22:11 guidedways

@guidedways Thanks a lot! I was thinking about the same thing. Can you submit a pull request?

jiuyangzhao avatar Nov 28 '18 22:11 jiuyangzhao

@jiuyangzhao would love to but I'd consider this a bit of a hack at this point, given you'd need to manually update the string each time you push a release. Could this not be automated to simply generate a string and update the version number in a .java file that gets included as part of the source code? At least then we'd certain be the SDK Version won't ever escape the code itself.

guidedways avatar Nov 28 '18 22:11 guidedways

I agree but this is strictly better than what we have right now. I don't have any bandwidth developing SDK but I can live with update the code each time.

jiuyangzhao avatar Nov 28 '18 23:11 jiuyangzhao

@jiuyangzhao done :)

guidedways avatar Nov 29 '18 00:11 guidedways

Any news about this? I got now also this problem after using multidex. Without multidex it is working.

chrisonline avatar Apr 13 '19 19:04 chrisonline

@chrisonline try my solution above

https://github.com/dropbox/dropbox-sdk-java/issues/140#issuecomment-442627875

guidedways avatar Apr 13 '19 20:04 guidedways

Thanks I have seen this. But I don't want to compile this myself. This should be fixed by Dropbox.

So I wonder why Dropbox does ignore this. They can simple fix this.

chrisonline avatar Apr 13 '19 20:04 chrisonline

Seems the last version of Dropbox fixes this problem: com.dropbox.core:dropbox-core-sdk:3.0.11

This version is not listed at the main page here. There is still 3.0.10

The commit who fixed this problem is: https://github.com/dropbox/dropbox-sdk-java/commit/b3a1e4fc34961db958d26bc58fa618c90d531ccc#diff-ec2dc95fa99e45aedc35e711a096a87e

chrisonline avatar Apr 14 '19 13:04 chrisonline