Giter Club home page Giter Club logo

expo-play-asset-delivery's Introduction

expo-play-asset-delivery

Play Asset Delivery integration for Expo

npm

Installation

  • Install the package expo-play-asset-delivery from NPM

  • Configure Expo Plugin in app.config.js

    module.exports = {
        // ...
        plugins: [
            // ...
            [
                'expo-play-asset-delivery',
                [
                    {
                        // Internal name of the asset pack
                        name: 'asset-pack',
                        // Path of the assets directory relative to the (Expo) project root folder
                        path: 'assets',
                        // Delivery mode (see https://developer.android.com/guide/playcore/asset-delivery#delivery-modes)
                        deliveryMode: 'fast-follow',
                    },
                ],
            ],
        ],
    };
  • ⚠️ If you are using bare workflow (if you don't know what it is you aren't):

    • Run npx expo prebuild --clean to regenerate the build files (this must be done after every change to the plugin configuration)
  • ⚠️ If you are using expo-dev-client (if you don't know what it is you aren't):

    • The dev client must be rebuilt every time the plugin configuration changes or the assets are changed

Usage

If you are using fast-follow or on-demand delivery modes, you must check the status of the asset pack before trying to access the assets:

import { getAssetPackStates, requestAssetPackFetch, AssetPackStatus } from 'expo-play-asset-delivery';

const state = await getAssetPackStates(['asset-pack'])['asset-pack']
if (state.status !== AssetPackStatus.COMPLETED) {
    await requestAssetPackFetch(['asset-pack']);
    // ...
}

After requesting the download of the asset pack, you can add an event listener to monitor the download progress:

import { addAssetPackProgressListener, AssetPackState } from 'expo-play-asset-delivery';

addAssetPackProgressListener((state: AssetPackState) => {
    // ...
});

Regardless of the delivery mode, you can load the assets by their filename:

import { loadPackedAssetAsBase64 } from 'expo-play-asset-delivery';

const base64 = await loadPackedAssetAsBase64('asset-pack', 'assets/image.png');
const uri = `data:image/png;base64,${base64}`;

// ...

return (
  <Image source={{ uri }} />
)

If you have issues loading larger files, see this issue.

Development

In order to access the asset packs during development, you must install expo-dev-client and configure it to build as AAB:

{
  "build": {
    "development": {
      "android": {
        "gradleCommand": ":app:bundleDebug"
      }
    }
  }
}

You can then use bundletool to create and install the APK including the asset packs (you can download the keystore with the alias/passwords from Expo):

java -jar bundletool-all-*.jar build-apks --bundle=build-1674208169858.aab --output output.apks --local-testing --ks=keystore.jks --ks-key-alias=<keyalias>
java -jar bundletool-all-*.jar install-apks --apks=output.apks

expo-play-asset-delivery's People

Contributors

chris54721 avatar phil-hudson avatar

Stargazers

 avatar  avatar

Watchers

Andrea Ruggiero avatar  avatar

expo-play-asset-delivery's Issues

Another way to load assets

Hi,

First of all thanks for making this repo. I think many people including me have problems in implementing Play Asset Delivery with React Native / expo, and this repo provides a solution.

I just want to mention that there is another way to load the assets (at least when the delivery mode is "install-time" - I haven't checked the others). As suggested in
https://stackoverflow.com/questions/73389621/play-asset-delivery-in-react-native
facebook/react-native#21309 (comment)
we can load the assets like this:
<Image source={{ uri: "asset:/trees.jpeg" }} style={{ height: 100, width: 100 }}></Image>.
In fact, when I follow the provided example and use loadPackedAssetAsBase64 from the package, I only succeed in showing small images and fail to show large (~2 MB) images.

Could not set unknown property 'classifier' for task ':expo-play-asset-delivery:androidSourcesJar'

Seeing failures on Android build. Might need some Gradle 8 compatibility updates.

› Building app...
Configuration on demand is an incubating feature.

> Configure project :app
 ℹ️  Applying gradle plugin 'expo-dev-launcher-gradle-plugin' ([email protected])
 ℹ️  Applying gradle plugin 'expo-updates-gradle-plugin' ([email protected])

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/a/Programming/a/node_modules/expo-play-asset-delivery/android/build.gradle' line: 40

* What went wrong:
A problem occurred evaluating project ':expo-play-asset-delivery'.
> Could not set unknown property 'classifier' for task ':expo-play-asset-delivery:androidSourcesJar' of type org.gradle.api.tasks.bundling.Jar.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 20s
15 actionable tasks: 15 up-to-date

Cannot find native module 'ExpoPlayAssetDelivery' iOS

Any idea where I'm going wrong? On iOS, after clean rebuild, I get the following error:

Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Error: Cannot find native module 'ExpoPlayAssetDelivery', js engine: hermes', reason: 'Unhandled JS Exception: Error: Cannot find native module 'ExpoPlayAssetDelivery'

The plugin is correctly configured in app.json.

I noticed in the expo-module.config.json file, support platforms is only Android. PAD is of course only available on Android, but I wonder if I'm missing some setup steps that allow the plugin to work seamlessly?

I've followed the exact workflow on the readme and cannot work out why it's not working - specifically, it looks like the Module for iOS isn't being copied over.

Thanks in advance!

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.