8

So I've copied the expansion package sample for Android and made it run based on the guide provided by google. I've successfully made it work by storing a local .obb file but I can't manage to get it to work with downloading the .obb file. The state is changed to IDownloaderClient.STATE_COMPLETED but no file it to be found.

Steps I've been through:

  1. Make sample run (updated with BASE64_PUBLIC_KEY, new package name, version number)
  2. Successfully test with local .obb file.
  3. Make apk and upload to Play together with expansion file.
  4. Install signed apk and run app. <-- here it says download was a success but without giving any progress updates during the download process.

Please help getting the expansion file downloaded.

Edit: At step 4 I now get Download failed because the resouces could not be found.

Edit 2: So after debugging I see that status changes to no download required but it fails to validate file as it is missing. So for some reason it thinks the file has been downloaded.

Edit 3: So inside DownloaderService.class we have a run() method which makes a getExpansionURLCount() which returns 0. Documentation says: this will return zero if there has been no LVL fetch in the current session. After more digging I see that the response I get from Google in processServerResponse() has the response code 256 and no keys with FILE_URL. So what is the cause for this?

Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • Are you able to download file by sampleDownloaderActivity? – T_V Aug 09 '13 at 11:04
  • @TarunDroid thats what I'm using, I'm able to verify my own local file but not download from play – Warpzit Aug 09 '13 at 12:29
  • I've been stuck with the same issue for days now, how did you fix this? – Amanni Feb 19 '14 at 22:38
  • @Amanni I didn't. But I'd suggest making a new test app and publish it then try for version 2 adding expansion file sample and see if that works. Please report back how that works out. – Warpzit Feb 20 '14 at 08:09
  • so just change version number in app and expansion file? The weird thing is I have done this before and my previous test works fine. I've duplicated the test and the new one doesn't seem to work. – Amanni Feb 20 '14 at 15:21
  • Did you fix your problem? – Dalinaum Mar 22 '14 at 01:59
  • 1
    @Dalinaum I ended up making a solution with a server instead. The google api does work but is very frustrating to work with ;) But I was planning to get back to it and make it work. – Warpzit Mar 22 '14 at 06:10
  • Thank you. @Warpzit. I solved my problem too. But I don't know how it wax fixed. – Dalinaum Mar 22 '14 at 10:59

3 Answers3

5

I know this answer doesn't address the underlying problem, but I thought this explanation might help others like me who have been confused by the responses from the downloader library:

The downloader service will (somewhat un-intuitively) pass STATE_COMPLETED to onDownloadStateChanged() when the Google Licensing server informs it that there are no expansion files associated with the app. Since it has to make an async call to the server to find this out, it can't just return NO_DOWNLOAD_REQUIRED directly from startDownloadServiceIfRequired(). It has to start the service to consult the server.

But it seems it will only do this the first time you call the download service after your app is installed - after that, it caches the response from the licensing server in a local database, and future calls to startDownloadServiceIfRequired() will immediately return NO_DOWNLOAD_REQUIRED.

Response code 256 corresponds to Policy.LICENSED, meaning the package name and public key are valid, but the lack of any FILE_URL suggests that Google Play thinks there is no expansion file for the app.

In my case, my expansion file worked when the app was in draft, but once published, it effectively disappeared from the store. I have not been able to determine why.

Glenn Schmidt
  • 623
  • 8
  • 9
  • 1
    heh now your case sounds more anoing. You've tested it worked and then you get screwed :) but thanks for the explanation. – Warpzit Apr 25 '14 at 06:13
  • 1
    The issue was fixed by re-uploading the APK (with an incremented version number) and then re-uploading the expansion file. Interestingly, the console showed that there were no existing expansion files, but when i re-uploaded, it gave it version number 2. My conclusion from all of this is that the Google Play Developer Console is buggy when it comes to handling expansion files. – Glenn Schmidt Apr 28 '14 at 04:54
  • This was the resolution for me. I saw the same issue as the OP with an app that had previously been published with no OBB. A later version uploaded with an OBB to beta returned STATE_COMPLETE for about two hours until the Google servers updated with the build. – zippycoder Jun 19 '14 at 12:10
1

It's probably because the file was found to be "incomplete" when doing checks after completion, and was then deleted.

One possibility is the downloaded file's length is different than the one you provided to android.vending/expansion/downloader.Helpers.deosFileExist(Context, String, long, boolean), so first check to see the provided value matches the actual value.

If this doesn't resolve the issue, then consider adding breakpoint to all File delete calls and see if any of them are triggered.

Kai
  • 15,284
  • 6
  • 51
  • 82
  • But it worked for the local one, so why would the local and the uploaded be different in size when I use the same file =/ doesn't make sense – Warpzit Aug 09 '13 at 11:43
  • Well it's either this or that the file wasn't downloaded in the first place, which from your description isn't likely. It also doesn't hurt to check the uploaded file to make sure its version number/size/content match that of what you have locally. – Kai Aug 09 '13 at 12:13
  • Ofcourse, I've tryed reupload the file multiple times with the same result: Some kind of error. – Warpzit Aug 09 '13 at 12:30
1

After few days searching by a solution, I found the error for my case.

Using LicenseChecker, I saw the listener callback an applicationError with code 3. Here code:

        aep = new APKExpansionPolicy(this,
            new AESObfuscator(ContentDownloaderService.SALT, getPackageName(), deviceId));

        aep.resetPolicy();    

        checker = new LicenseChecker(this, aep,
            BASE64_PUBLIC_KEY // Your public licensing key.
        );

        checker.checkAccess(new LicenseCheckerCallback() {
        @Override
        public void allow(int reason) {
            System.out.println("Allow Reason "+reason);
        }

        @Override
        public void dontAllow(int reason) {
            System.out.println("Don't Allow Reason "+reason);
            try {
                switch (reason) {
                    case Policy.NOT_LICENSED:
                        System.out.println("Not licensed");
                        break;
                    case Policy.RETRY:
                        System.out.println("Retry");
                        break;
                }
            } finally {
            }

        }

        @Override
        public void applicationError(int errorCode) {
            System.out.println("aplication error "+errorCode);
        }

    });

Error Code 3 is ERROR_NOT_MARKET_MANAGED, you can see complete list of error here https://developer.android.com/google/play/licensing/licensing-reference.html#server-response-codes, and here I can get information about that error mean How do you deal with LicenseCheckerCallback.ERROR_NOT_MARKET_MANAGED error code?

Summary, that happened because my local version is not the same version on google console, and happened to me because my versionCode is generated by a script like this:

def getBuildVersionCode() {
   def date = new Date()
   def formattedDate = date.format('yyMMddHHmm')

   return (formattedDate as int) + 221066279;    
}

def getBuildVersionName() {
return getBuildVersionCode().toString();
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
    applicationId "com.test.testing"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode getBuildVersionCode()
    versionName getBuildVersionName()
}

So every time than I compile I'm getting a new version and obviously that version it isn't on google console.

I changed my gradle script to:

    android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
    applicationId "com.test.testing"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1731227595 // My actual version number of apk in google developer console.
    versionName 1731227595 
}

And that saved my life, I hope this answer can be usefulness to anyone more..

Community
  • 1
  • 1
Ruben Flores
  • 331
  • 1
  • 3
  • 13