Search code examples
androidgoogle-playexpansion-files

Creating an application that uses Expansion Files without publisher account


I'm just starting to develop for Android and I don't have license of Google Play developer. For my application I have to use APK Expansion Files.

I tried to apply code of downloader_sample that contained at play_apk_expansion, but get InvalidKeySpecException thrown by this method

private static PublicKey generatePublicKey(String encodedPublicKey) {
    try {
        byte[] decodedKey = Base64.decode(encodedPublicKey);
        KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
        return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
    } catch (NoSuchAlgorithmException e) {
        // This won't happen in an Android-compatible environment.
        throw new RuntimeException(e);
    } catch (Base64DecoderException e) {
        Log.e(TAG, "Could not decode from Base64.");
        throw new IllegalArgumentException(e);
    } catch (InvalidKeySpecException e) {
        Log.e(TAG, "Invalid key specification.");
        throw new IllegalArgumentException(e);
    }
}

Also I have

public class SampleDownloaderService extends DownloaderService {
// You must use the public key belonging to your publisher account
public static final String BASE64_PUBLIC_KEY = "MyLVLKey";
// You should also modify this salt
public static final byte[] SALT = new byte[] { 1, 42, -12, -1, 54, 98,
        -100, -12, 43, 2, -8, -4, 9, 5, -106, -107, -33, 45, -1, 84
};

How can I to test my application without real publisher account?


Solution

  • The sample code for the APK Expansion project has a specific check for the file being in place before calling the downloader functions. Make sure that your file is in place on the SD card and access it directly.

    To use the built-in downloader as-is, you will need a publisher account, because the files are hosted on Google Play. With minor changes, you can use the downloader to download from wherever you would like, such as a local server.