-
Notifications
You must be signed in to change notification settings - Fork 742
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
Android GetFileFromApplicationUriAsync doesn't work #8618
Comments
Make sure to validate first with this sample application: https://github.com/unoplatform/Uno.Samples/tree/master/UI/PackageResources
|
Sample has no files in Assets folder, so it is not related. |
Thanks. This is likely this Visual Studio issue, as this has been working in Uno for a while. Apply the workaround, and make sure to upvote the VS issue so it gets fixed. Also, when you're creating issues, don't point to your full app repository, make sure to create a small sample to attach to the issue. |
One more check: files are present in .apk file: |
@pkar70 did you try with the workaround? Does it change anything? |
No... (After Build.VERSION_CODES#R, Resources must be obtained by Activity or Context created with Context.createWindowContext(int, Bundle). Application#getResources() may report wrong values in multi-window or on secondary displays. |
Thanks. Files are in the APK but with an invalid path / file name, which points to a similar shared project related issue. |
After trying workaround - same. Java.IO.FileNotFoundException. |
This reminds me that images are not handled the same way as other file types. If you want images to be read by |
I have workaround...
|
I don't know WHAT places files from Shared\Assets to Droid\res, and how to prevent it. |
There's currently no way to change this: uno/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs Lines 131 to 137 in da4338d
The only workaround to handle this is to add the items as <ItemGroup>
<AndroidAsset Include="../MyProject.Shared/Assets/**" />
</ItemGroup>
|
So, if I add this |
It should be yes, let us know if that helps. |
Hummmm
from 'Assets/myfile.jpeg' to only 'myfile.jpeg' and "voilà"! Android could load perfectly the image. I don't know why path has the 'Assets/' since we are using outputCachePath as well. |
@iury-kc yes, that's what it's supposed to be doing somehow, but the problem is the handling of conflicts in file names. We've been trying to adjust this for a while (#7328) but it's quite tricky. |
But what if I have such structure: similar to https://github.com/pkar70/ZegarSloneczny/tree/master/ZegarSloneczny/pic 'Flattening' dirtree is bad.
|
Flattening is what android does with resources, it's not something we can change. Assets don't have that problem, when using |
Still..
And I cannot use such code for Android. I can replace this code with "special code for Android", but code should work correctly (or show Uno0001 warning that it is unimplemented). Maybe, in this case, there should be e.g. "Uno0002 Limited implementation for Android, works only for non-picture files, and only for ms-appx (not ms-appdata)" ? And same in all other places where Uno's implementation is somehow limited (e.g., because target platform has limits). |
Can you add a simple repro for your scenario here please (not one from your github) ? We'll make modifications to it and see what's needed. |
Simple repro:
|
This is what I mean by adding a simple repro: Test8618.zip. The workaround for this is to add the following to the android project: <ItemGroup>
<AndroidAsset Include="..\Test8618.Shared\Assets\**" Link="Assets\Assets\%(RecursiveDir)\%(FileName)%(Extension)" />
</ItemGroup> Take a look at the repro to see it in action. |
Thanks. In next app version, I will use this. |
Current behavior
Exception
**Java.IO.FileNotFoundException:**
is thrown.Expected behavior
File should be 'openable'.
How to reproduce it (as minimally and precisely as possible)
Exception:
**Java.IO.FileNotFoundException:** 'Assets/__1950.gif'
Part of: https://github.com/pkar70/KrakTram
GIF files are present, e.g. X\KrakTram\KrakTram_Uno\KrakTram_Uno.Shared\Assets\1950.gif
On build, they are copied to X\KrakTram\KrakTram_Uno\KrakTram_Uno.Droid\obj\Debug\120\res\drawable-nodpi__1950.gif
Workaround
None known.
Works on UWP/WinUI
Yes
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
NuGet package version(s)
UnoUI 4.2.6
Affected platforms
Android
IDE
Visual Studio 2022
IDE version
17.0.5
Relevant plugins
No response
Anything else we need to know?
No response
The text was updated successfully, but these errors were encountered: