Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expansion file downloaded but not there

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?

like image 826
Warpzit Avatar asked Aug 09 '13 10:08

Warpzit


People also ask

How to use APK expansion files?

First, open the Android SDK Manager (Tools > SDK Manager), and under Appearance & Behavior > System Settings > Android SDK, select the SDK Tools tab to select and download: Google Play Licensing Library package. Google Play APK Expansion Library package.

What is the maximum size of APK file in Android?

Each expansion file can be up to 2GB in size. Users must run Play Store version 5.2 or higher to install 100MB APKs.


3 Answers

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.

like image 88
Glenn Schmidt Avatar answered Nov 08 '22 14:11

Glenn Schmidt


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.

like image 37
Kai Avatar answered Nov 08 '22 13:11

Kai


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..

like image 30
Ruben Flores Avatar answered Nov 08 '22 12:11

Ruben Flores