3

We recently started making use of the new Google Expansion APK mechanism. Overall it works well, but it seems somewhat flakey for us. Some questions:

  1. Some users get the expansion app downloaded along with the app while others don't and our app has to download it itself. Does anyone know what governs when it works automatically and when not?

  2. Sometimes when we need to download the expansion file ourselves, Google Play returns -1 for the file size and null for the URL, indicating the expansion file doesn't exist. If I run the app again, the second time it will generally return a valid size and URL. Does anyone else see this flakiness?

Here are the basics of the code:

This is how we set up the call to verify licensing via a callback

    policy = new APKExpansionPolicy( context, new AESObfuscator( SALT, context.getPackageName(), deviceId ) );
    mChecker = new LicenseChecker( context, policy, BASE64_PUBLIC_KEY );
    mLicenseCheckerCallback = new MyLicenseCheckerCallback();
    mChecker.checkAccess( mLicenseCheckerCallback );

Then in the callback we have this for the allow() method (when the license is valid).

    public void allow( int reason )
    {
        String expansionFileName = policy.getExpansionFileName( APKExpansionPolicy.MAIN_FILE_URL_INDEX );
        String expansionURL = policy.getExpansionURL( APKExpansionPolicy.MAIN_FILE_URL_INDEX );
        long expansionFileSize = policy.getExpansionFileSize( APKExpansionPolicy.MAIN_FILE_URL_INDEX );
    }

We just released the app with this new code, but a significant number of users are getting -1 back as the expansionFileSize and null as the url. This causes the user to not get the expansion file installed. Generally if they run the app again, it will work on the second (or third) time.

Anyone have any thoughts on what could be going on?

btschumy
  • 1,435
  • 1
  • 18
  • 35

3 Answers3

2

You are getting -1 because the APKExpansionPolicy responds with a local cached result if you try to contact the licensing server again - but the URL, filesize and filename are not cached and are lost after the first real response. APKExpansionPolicy does not cache these results, here is a comment from the APKExpansionPolicy source code which explains it:

Expansion URL's are not committed to preferences, but are instead intended to be stored when the license response is processed by the front-end.

So you need to store these values in the preferences right after you get the first successful response (in allow callback method);

Daniel Novak
  • 2,746
  • 3
  • 28
  • 37
1

The blog post on Android Developers addresses #1:

On most newer devices, when users download your app from Android Market, the expansion files will be downloaded automatically, and the refund period won’t start until the expansion files are downloaded. On older devices, your app will download the expansion files the first time it runs

kabuko
  • 36,028
  • 10
  • 80
  • 93
  • That is not what we're seeing. We have gotten reports of it not working on Android 3.2 and 4.X. It does work on some 2.2 devices. Seems to follow no rhyme or reason. I would love to download the file when it doesn't automatically, but it is telling me the file doesn't exist. – btschumy Apr 05 '12 at 19:38
  • 1
    If you can check the version of the Android Market/Google Play app, I suspect that's probably more relevant than the version of the OS. – kabuko Apr 05 '12 at 19:39
1

To add to Daniel Novak's answer, if you reset the policy before the call to checkAccess(), this will force it to make a new license request, and therefore retrieve the URL:

policy.resetPolicy();

You probably only want to do this if you're sure you need the URL (ie, if you've already checked that the expansion file is missing).

Community
  • 1
  • 1
Saxon Druce
  • 17,406
  • 5
  • 50
  • 71