Coder Social home page Coder Social logo

padsameple-android's Introduction

PADSameple-Android

配置工程

创建资源包

  1. 在项目的根目录下(跟App模块平级目录下)创建资源包文件夹,此文件夹名即为资源包名。注意:名字只能是字母开通,仅能包含字母、数字、下划线,如:base_assets
  2. base_assets目录下创建src/main/assets目录,在此目录中存放我们的资源文件,此目录里可以有子目录
  3. base_asssets目录下创建build.gradle文件并填入内容如下:
// In the asset pack’s build.gradle file:
apply plugin: 'com.android.asset-pack'

assetPack {
    packName = "base_assets" // Directory name for the asset pack
    dynamicDelivery {
        deliveryType = "install-time" // 根据自己需求可填后面三种类型中的一种[ install-time | fast-follow | on-demand ]
    }
}
  1. 在App(主入口)模块的 build.gradle中添加如下代码:
// In the app build.gradle file:
android {
    ...
    assetPacks = [":base_assets"]
}
  1. 在工程的根目录下有个settings.gradle文件,在此文件中添加自己建的 资源包如下:
// In the settings.gradle file:
include ':app'
include ':base_assets'

使用资源包

  1. 在项目的app(主入口) 模块下的 build.gradle 文件添加 Google Play Core 库,如下:
// In your app’s build.gradle file:
...
dependencies {
    // This dependency is downloaded from the Google’s Maven repository.
    // So, make sure you also include that repository in your project's build.gradle file.
    implementation 'com.google.android.play:core:1.7.3'
    ...
}
  1. 获取资源包中的资源

    • Install-time 类型的资源包,就跟在 App(主入口)模块中的assets目录下资源一样使用

    • Fast-follow 类型的资源包,会在应用安装完成后立即下载

    • On-demand 类型的资源包,是可以按需下载

      在使用上 fast-follow和on-demand类型的资源包需要通过下面方法找到资源包路径,进而读取资源(读取先要检查本地是否下载完成,检查过程参考https://developer.android.com/guide/playcore/asset-delivery/integrate-java)

       AssetPackLocation assetPackPath = assetPackManager.getPackLocation(assetPack);
       String assetsFolderPath = assetPackPath.assetsPath();// 此目录就是资源包目录了

生成Android App Bundle

  1. 通过Android Studio 的Build-->genrate Signed Bundle/APK 一步步导出生成Android App Bundle,即.aab文件

测试

  1. 生成 带有测试标签的apks文件

    java -jar bundletool-all.jar build-apks --bundle=path/to/your/bundle.aab \
      --output=output.apks --local-testing
  2. 连接设备并通过bundletool来安装apks文件

    java -jar bundletool.jar install-apks --apks=output.apks
  3. 打开安装的 apks,查看资源是否都能正常获取到

padsameple-android's People

Contributors

changcsw avatar

Stargazers

baebae avatar Murat Öter avatar he110world avatar donocianrbar avatar  avatar Elroy avatar  avatar Neil Chan avatar  avatar 이서현(Seohyun Lee)/Android_M&F avatar Karthik Kompelli avatar  avatar

Watchers

James Cloos avatar

padsameple-android's Issues

assets pack not loaded on my Samsung A-50

When the application is installed by Android Studio on my Samsung A50, the 3 asset packs should be in the "file" folder of the smartPhone but they do not load.
Can you please help me as I have been trying to fix for a week now.
Thank you in advance.
2022-03-29_17-35-03

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.