Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Bundled assets won't load in release builds #4278

Closed
mathieupost opened this issue Nov 7, 2024 · 7 comments
Closed

[BUG]: Bundled assets won't load in release builds #4278

mathieupost opened this issue Nov 7, 2024 · 7 comments

Comments

@mathieupost
Copy link

mathieupost commented Nov 7, 2024

Version

6.7.0

What platforms are you having the problem on?

Android

System Version

API 34

On what device are you experiencing the issue?

Real device, Simulator

Architecture

Old architecture

What happened?

When passing a number in the source property the video won't load on Android release builds. On debug builds it does work, and on iOS it always works.

I've retrieved the number value like this (I've also tried require('./asset.mp4')):

import VideoAsset from './asset.mp4';

Unfortunately, it won't show a video in my app and using Android Studio I'm seeing the following error:

Playback error
    androidx.media3.exoplayer.ExoPlaybackException: Source error
        at androidx.media3.exoplayer.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:736)
        at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:708)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at android.os.HandlerThread.run(HandlerThread.java:67)
    Caused by: androidx.media3.datasource.HttpDataSource$HttpDataSourceException: Malformed URL
        at androidx.media3.datasource.okhttp.OkHttpDataSource.makeRequest(OkHttpDataSource.java:369)
        at androidx.media3.datasource.okhttp.OkHttpDataSource.open(OkHttpDataSource.java:262)
        at androidx.media3.datasource.TeeDataSource.open(TeeDataSource.java:54)
        at androidx.media3.datasource.cache.CacheDataSource.openNextSource(CacheDataSource.java:802)
        at androidx.media3.datasource.cache.CacheDataSource.open(CacheDataSource.java:615)
        at androidx.media3.datasource.StatsDataSource.open(StatsDataSource.java:86)
        at androidx.media3.exoplayer.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1045)
        at androidx.media3.exoplayer.upstream.Loader$LoadTask.run(Loader.java:421)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
        at java.lang.Thread.run(Thread.java:1012)

Adding logs in the getUriFromAssetId function in Source.kt does indicate that it found an identifier:

identifier: 2131820554

The result of getUriFromAssetId is:

android.resource:/2131820554

Unfortunately, I'm not proficient in Kotlin or Android native stuff, so I don't know how to continue from here.

I'm 100% sure that the assets are actually bundled with the app, because when passing the VideoAsset to the source of an Image element from expo-image it actually shows the first frame as image.

Reproduction Link

No response

Reproduction

Step to reproduce this bug are:

  1. Add an mp4 asset.
  2. Import or require the asset by relative path.
  3. Use the result of the import or require as source parameter.
  4. Create an Android Release build (Debug works fine)
  5. No video is displayed on Android
@mathieupost mathieupost added the bug label Nov 7, 2024
Copy link

github-actions bot commented Nov 7, 2024

Previous bot comment (click to expand)
Previous bot comment (click to expand)

Thank you for your bug report. We will review it and get back to you if we need more information.

There is a newer version of the library available. You are using version 6.6.3, while the latest stable version is 6.7.0. Please update to the latest version and check if the issue still exists.

Note: If the issue still exists, please update the issue report with the latest information.

@mathieupost
Copy link
Author

Updated to 6.7.0, but the issue persists

Copy link

github-actions bot commented Nov 7, 2024

Previous bot comment (click to expand)

Thank you for your bug report. We will review it and get back to you if we need more information.

There is a newer version of the library available. You are using version 6.6.3, while the latest stable version is 6.7.0. Please update to the latest version and check if the issue still exists.

Note: If the issue still exists, please update the issue report with the latest information.

Copy link

github-actions bot commented Nov 7, 2024

Thank you for your bug report. We will review it and get back to you if we need more information.

@mathieupost
Copy link
Author

mathieupost commented Nov 7, 2024

Changed the return of getUriFromAssetId to

return Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE).authority(packageName).path(identifier.toString()).build()

as in the Android documentation the package name is also added optionally, resulting in android.resource://com.myapp.android/2131820552, which does look like a more valid URI, but unfortunately it doesn't result in a playing video.

Also tried

return Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE).authority(packageName).path(uriString).build()

resulting in android.resource://com.myapp.android/src_assetcache_asset_10, but this also doesn't work.

@lovegaoshi
Copy link
Contributor

ur encountering this. its loading ur source as an httpDataSourceFactory and that happens when cache is enabled.

@mathieupost
Copy link
Author

Ahaa! Thanks, disabling the cache for local assets fixed it indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants