How to make Android Expansion File using Android Studio?

groff07 picture groff07 · Mar 13, 2014 · Viewed 17.5k times · Source

I need to upload a .apk but it exceeds the 50 MB limit.

I read about this on documentation and some questions but I'm having difficulty making this work.

Does anyone have some tutorials that explain how to do this (using Android Studio) and if there is some way to use Gradle to do this?

Answer

SharkAlley picture SharkAlley · Mar 16, 2014

I've done this on a few projects, but I never figured out a simple way. The instructions at

http://developer.android.com/google/play/expansion-files.html

helped me get my head around the basics, but I found parts of the process (like "android update project") didn't work properly with Gradle.

The instructions below will help you set up your project with the required libraries. After that you can go back to the official docs and figure out what to do with all the stuff you just included.

Add these permissions to AndroidManifest.xml

<uses-permission android:name="com.android.vending.CHECK_LICENSE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

Add Play Services dependency to build.gradle

dependencies {

    compile 'com.google.android.gms:play-services:4.0.30'
}

Open SDK Manager and install Google Play APK Expansion Library and Google Play Licensing Library.

Copy java source files from these folders into your project's source/main/java folder:

YOUR-ANDROID-SDK-FOLDER\extras\google\play_apk_expansion\zip_file\src

YOUR-ANDROID-SDK-FOLDER\extras\google\play_apk_expansion\downloader_library\src

YOUR-ANDROID-SDK-FOLDER\extras\google\play_licensing\library\src

Open

YOUR-ANDROID-SDK-FOLDER\extras\google\play_apk_expansion\downloader_library\res

Copy drawable-hdpi, drawable-mdpi and layout into your project's source/main/res folder.

For all files in the values folders, merge content from the file into the matching file in your project.

Create a class which extends android.content.BroadcastReceiver

Add something like this to your manifest:

<receiver android:name="mypackage.MyReceiver"/>

Create a class which extends com.google.android.vending.expansion.downloader.impl.DownloaderService

Add something like this to your manifest:

<service android:name="mypackage.MyDownloaderService"/>

Compile the project and look for errors relating to

import com.android.vending.expansion.downloader.R;

Import your own project resources here instead.