开发者

Problem of large size of .apk file in android?

I have a problem that arise due to large size and no. of images in app, my app stopped installing on emulator. It giv开发者_如何学运维es an error report " No Space Left". Size of .apk file is about 60MB. Now, I would like to ask the following questions:

  • What could be done in this situation, so that it gets installed and doesn't gives this error?

  • Does android market allow to install app of this size?

Thanks in advance


The limitation of android market now is 50MB. What you can do is out some resources on the server and download them on demand. You can promt the user that the app is going to download large amount of data, so that user can use wifi to do it.


At Present limit of android market is 50 MB. so you can compress your images with some image compression and if you have used video or audio then also you can compress so you can achieved 50 MB. many compression tool is available.


At the 24:10 mark in the video from Google IO, large apks in the market were announced, coming in June:

http://www.google.com/events/io/2011/sessions/android-market-for-developers.html


Google Play currently requires that your APK file be no more than 50MB. For most applications, this is plenty of space for all the application's code and assets. However, some apps need more space for high-fidelity graphics, media files, or other large assets. Previously, if your app exceeded 50MB, you had to host and download the additional resources yourself when the user opens the app. Hosting and serving the extra files can be costly, and the user experience is often less than ideal. To make this process easier for you and more pleasant for users, Google Play allows you to attach two large expansion files that supplement your APK.

Here are the steps required for setting up expansion files in Android:

  1. First, open the Android SDK Manager, expand Extras and download:

    • Google Play Licensing Library package
    • Google Play APK Expansion Library package
  2. Declare the following permissions in AndroidManifest.xml

    <!-- Required to access Google Play Licensing -->  
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
    
    <!-- Required to download files from Google Play -->  
    <uses-permission android:name="android.permission.INTERNET" />
    
    <!-- Required to keep CPU alive while downloading files (NOT to keep screen awake) -->  
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    
    <!-- Required to poll the state of the network connection  
        and respond to changes -->
    <uses-permission  
        android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <!-- Required to check whether Wi-Fi is enabled -->  
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    
    <!-- Required to read and write the expansion files on shared storage -->  
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
    
  3. Integrate libraries

    • Copy the source for the Downloader Library from <sdk>/extras/google/play_apk_expansion/downloader_library/src to your project.
    • Copy the sources from <sdk>/extras/google/play_licensing/library/src to your project.
    • Copy the sources from <sdk>/extras/google/google_market_apk_expansion/zip_file/ to your project.
  4. Now, create a new package named expansion and create DownloaderService.java inside the package.

    // DownloaderService.java
    public class DownloaderService extends com.google.android.vending.expansion.downloader.impl.DownloaderService {  
        public static final String BASE64_PUBLIC_KEY = "<<YOUR PUBLIC KEY HERE>>"; // TODO Add public key
        private static final byte[] SALT = new byte[]{1, 4, -1, -1, 14, 42, -79, -21, 13, 2, -8, -11, 62, 1, -10, -101, -19, 41, -12, 18}; // TODO Replace with random numbers of your choice
    
        @Override
        public String getPublicKey() {
            return BASE64_PUBLIC_KEY;
        }
    
        @Override
        public byte[] getSALT() {
            return SALT;
        }
    
        @Override
        public String getAlarmReceiverClassName() {
            return DownloaderServiceBroadcastReceiver.class.getName();
        }
    }
    
  5. Create DownloaderServiceBroadcastReceiver.java extending BoradcastReceiver which will start the download service if the files need to downloaded.

    // DownloaderServiceBroadcastReceiver.java
    public class DownloaderServiceBroadcastReceiver extends android.content.BroadcastReceiver {  
        @Override
        public void onReceive(Context context, Intent intent) {
            try {
                DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent, DownloaderService.class);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    
  6. Start the download from your activity if expansion files are not available

    Intent launchIntent = MainActivity.this.getIntent();
    Intent intentToLaunchThisActivityFromNotification = new Intent(MainActivity.this, MainActivity.this.getClass());
    intentToLaunchThisActivityFromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction());
    
    if (launchIntent.getCategories() != null) {
        for (String category : launchIntent.getCategories()) {
            intentToLaunchThisActivityFromNotification.addCategory(category);
        }
    }
    
    // Build PendingIntent used to open this activity from notification
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intentToLaunchThisActivityFromNotification, PendingIntent.FLAG_UPDATE_CURRENT);
    // Request to start the download
    int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent, DownloaderService.class);
    

For full details and code, take a look at How to Set Up Android App to Support Expansion Files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜