如何使用 Android Studio 制作 Android 扩展文件? [英] How to make Android Expansion File using Android Studio?

查看:30
本文介绍了如何使用 Android Studio 制作 Android 扩展文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要上传 .apk 但它超过了 50 MB 的限制.

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.

有没有人有一些教程来解释如何做到这一点(使用 Android Studio),以及是否有某种方法可以使用 Gradle 来做到这一点?

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?

推荐答案

我已经在一些项目中做到了这一点,但我从来没有想出一个简单的方法.

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

帮助我了解了基础知识,但我发现该过程的某些部分(例如android 更新项目")在 Gradle 中无法正常工作.

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.

将这些权限添加到 AndroidManifest.xml

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"/>

将 Play 服务依赖添加到 build.gradle

Add Play Services dependency to build.gradle

dependencies {

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

打开 SDK 管理器并安装 Google Play APK 扩展库Google Play 许可库.

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

将这些文件夹中的 java 源文件复制到您项目的 source/main/java 文件夹中:

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

打开

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

drawable-hdpidrawable-mdpilayout 复制到您项目的source/main/res 文件夹中.

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

对于 values 文件夹中的所有文件,将文件中的内容合并到项目中的匹配文件中.

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

创建一个扩展 android.content.BroadcastReceiver

将类似的内容添加到您的清单中:

Add something like this to your manifest:

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

创建一个扩展 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.

这篇关于如何使用 Android Studio 制作 Android 扩展文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆