Skip to content Skip to sidebar Skip to footer

Android Expansion File

I am trying to do an application which contain ~80mo of PNG (It's an offline app so I have to store them on the phone). The application works perfectly in local but I can't uploa

Solution 1:

You don't need to unzip your package. You can read all your PNGs within Expansion ZIP file with this:

// Get a ZipResourceFile representing a merger of both the main and patch filesZipResourceFileexpansionFile= APKExpansionSupport.getAPKExpansionZipFile(appContext,
        mainVersion, patchVersion);

// Get an input stream for a known file inside the expansion file ZIPsInputStreamfileStream= expansionFile.getInputStream(pathToFileInsideZip);

**EDIT**

Notice that in the code above, InputStream will point to the file inside your ZIP archive and not the ZIP file itself. For example, if you placed flower.png under a directory called background inside your ZIP archive, you can have an InputStream to that file as follows:

InputStreamfileStream= expansionFile.getInputStream("background/flower.png");

**EDIT**

I think the location in which you placed your ZIP file is incorrect. According to Developer's Guide:

If your package name is com.example.android, you need to create the directory Android/obb/com.example.android/ on the shared storage space.

After successful testing, you can upload your Expansion ZIP along with your APK through Developer's Console.

Have you read through the APK Expansion Files? It's pretty straightforward.

Solution 2:

Some helfull information for people that end up here in this post since there are some things that changed in the way apk expansions work and also if you are using Android Studio to make the libraries work.

NOTE 1

You can't use draft anymore as the link to get the expansion file won't be active yet. You have to upload a version to Alpha or Beta first with expansion file. (adding an expansion file is only possible from the second apk you upload and up) So make sure you see the apk expansion file listed when you click the details in the developer publish section under APK.

NOTE 2

If you are using android studio and want to make use of the downloader library don't just copy the package name and java files into your own app src directory. Import the downloader library in eclipse and choose export => gradle build files. Afterwards you can import the library as a module in android studio.

NOTE 3

Not sure of this but I also think it's neccesary to download the app atleast once through the play store and have access to it with the account on your test device. So if you are working with alpha create a google+ test group and add yourself or other test devices to it.

BTW

With these libraries it's pretty easy to implement the apk expansion download just make sure:

  1. your activity (the one where you want to implement the downloading of the expansion pack when the downloading has not been done automatically) implements IDownloaderClient.

  2. you set up the service & receiver and set them up in your manifest.

  3. The BASE64_PUBLIC_KEY in the service class is correct. Upload the first apk => look in Services and API's in the developer console under your app => License code for this app.

This code is used to see if the expansion file can be found on the device:

boolean expansionFilesDelivered() {
    for (XAPKFile xf : xAPKS) {
        String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
        Log.i(TAG, "Expansion filename " +fileName);
        if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false))
            returnfalse;
    }
    returntrue;
}

It uses the class XAPKS wich represents an expansion file, be it either a main or patch file, having a certain filesize(bytes) and associated with a apk version (the one it was first added in).

privatestaticclassXAPKFile {
        publicfinalboolean mIsMain; // truepublicfinalint mFileVersion; //example 4publicfinallong mFileSize; //example 126515695L// example => main expansion that was first introduced in apk version 4 and is 126515695 bytes in size

        XAPKFile(boolean isMain, int fileVersion, long fileSize) {
            mIsMain = isMain;
            mFileVersion = fileVersion;
            mFileSize = fileSize;
        }
    }

Its also quite easy to read movie files and other stuff directly from the expansion file using the zip tools that google has provided (com.android.vending.zipfile).

First get the expansionfile using the methods provided in the library, the paremeters are integers that represent your main expansion apk version (the apk version where the expansion pack you need was first added) and the patch apk version.

ZipResourceFileexpansionFile= APKExpansionSupport.getAPKExpansionZipFile(context, APKX_MAIN_APK, APKX_PATCH_APK);

Video

For playing video directly from this zipresourcefile:

AssetFileDescriptora= expansionFile.getAssetFileDescriptor(pathToFileInsideZip);

Now from this assetFileDescriptor you can get a FileDescriptor and use this in your mediaplayer, the correct syntax to get your mediaplayer to play the video also needs the second and third parameter.. Be it the startoffset and length you can get from the AssetFileDescriptor.

player.setDataSource(a.getFileDescriptor(), a.getStartOffset(), a.getLength());

Other

For all the other stuff (like images) you can just get an inputstream of the zipresourcefile:

expansionFile.getInputStream(pathToFileInsideZip);`

ALSO make sure you don't compress the videos in the zip for this to work! for example not to compress .mp4 files:

zip -n .mp4 -r zipfile.zip . -x ".*" -x "*/.*"

Solution 3:

Even, if it is a zip file, it still needs to be stored in obb folder.

Post a Comment for "Android Expansion File"