Xamarin Android Assets.Open throws FileNotFound exception - android

It seems to be very easy, but don't know why I can't use Assets.open method without getting FileNotFound exception.
I followed an example in xamrain.com
http://docs.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_6_-_using_android_assets/
and still not getting it to work.
I added a txt file under Assets folder
Set the Build Action to "AndroidAsset"
I tried with also setting COpy to Output Diretory to "Always Copy" and "Do not Copy".
No matter what the combination, I always get FileNotFound exception.
Looked like many of fellow developers also see the problem and I don't see the answer that I can try.
Appreciate if someone could shed a light on this easy subject.
Thanks in advance

Firstly, without seeing your code, it's impossible to see any mistakes you may have missed. It's easy to miss a filename issue, or other problem that may not be so obvious.
Speculatively though, I will try to give you some pointers.
The 'Copy to Output Directory' setting is not important for Android resources. The build action of AndroidAsset will ensure that the file is included in the app package, allowing you to load it using Assets.Open().
To confirm this, have a look for the compiled .apk file in the bin/debug or bin/release folder. The .apk file is simply an archive, so you can open it up with with winrar, or 7-zip, or rename it to .zip and windows will open it.
If the file is in the assets folder, then there is probably a problem with your code. You should post it in your question. If the file isn't there, try cleaning your project, or deleting the bin folder to force a fresh build and re-package.

Check properties of the file. I had to set "Build Action" to AndroidAsset and after this it works fine.

I got this problem before, and I finally found a image file in my directory assets/ was named by Chinese characters so the images in the assets are not loaded in correct way.
I guess you should check out the filenames if it was badly coded.

You should try name files only in lowercase. Sometimes android convert names to lower even file contains uppercase.

Related

React Native. Error: The file name must end with .xml or .png

I know that there were similar questions, but all of them didn't help.
I generate signed apk for the first time, and I get error:
/android/app/build/generated/res/react/release/drawable-mdpi/src_images_cancel.svg: Error: The file name must end with .xml or .png
As I understand, Android doesn't support svg. I didn't put any svg to drawable-mdpi.
I suppose that some library did it. Moreover, when I remove those svgs from the folder, those files are generated again when I generate apk (I do it using android studio).
As I do it in the first time, I can't understand what to do. When I use emulator, I haven't got the same error, I do not get any errors at all.
It seems, that some package uses those files, but how to understand which one?
you need to store them into drawable-nodpi and use filename-suffix .xml.
it's alike a common drawable with vector and path.

Unity Android patch.obb file creation and use

We are currently working on a Unity Android project that has to have localised mp4 streaming Videos. In order to achieve this I was hoping to put the video files in an expansion obb file, then we can have the same apk and submit it with different obb files according to language.
Unfortunately our application without the videos is still over 50Mb so we need to use the first "main.1.name.obb" for the application.
However we are allowed to also submit a second obb under the name "patch.1.name.obb". However I am having trouble making this and using it. Has anyone tried this with unity before?
The application builds and runs with the first obb file absolutely fine (i.e. the game works without videos) the problem is just in the patch obb creation.
I have tried to create the obb by using a linux zip command with 0% compression then renaming it to a .obb file with no luck. (e.g. patch.1.packname.zip to patch.1.packname.obb)
I have tried to create the obb using jobb tool, and it adds the videos fine but still in game they are not found/played.
The videos are definitely in an "assets" folder inside the obb files made (where I believe streaming assets have to be)
I have fudged the streaming Assets Path ( Application.streamingAssetsPath ) to replace "main" with "patch" and have seen through logcat that it is indeed trying to get the videos from the patch obb file.
(e.g. "jar:file:///[storagelocation]/Android/obb/packname/patch.1.packname.obb!/vid01.mp4 )
Our version code in the AndroidManifest.xml if definitely 1.
Can anyone suggest anything else to try or point out an clear errors I am making in trying to do this?
Let me know any more information you may need to help as well and thanks in advance.
I haven't worked with Unity before, but from my experience I can point out a few things I have found from working with '.obb' files:
Simply renaming the '.zip' file to a '.obb' file will not work. You will need to make a folder named '.obb'. Then add all the needed resource files to this folder and then zip this folder, using 0% compression of course. Make sure that the zipped file contains only the resource files in the root and not a sub folder (the folder you made previously). Now you have a zip file named '.obb.zip'. At this point you can rename the file to '.obb'. Of course, the files may be in a sub folder inside the obb file (the assets folder in your case), but I am not sure about the consequences of this.
In regards to the statement you made concerning the files that are not found after using the jobb tool, this is most likely due to a miss-spelling somewhere or in one of my cases, forgetting to rename the package after copying it from a previous app. I know this seems foolish and maybe insulting (in which case I deeply apologize), but it happens.
This answer is based on my personal experience and may be slightly off center, but here are some links I used:
http://developer.android.com/google/play/expansion-files.html
http://developer.android.com/google/play/publishing/multiple-apks.html
http://developer.android.com/tools/help/jobb.html

Is there a way to add such folder in Android project that do no get compiled up to **apk**

I was looking for a way to add some such folder in my Android Project that do no get compiled up to my apk file.
Why I need it :-
We need to maintain proper documentation for project (that actually
everybody needs to ;) nothing new),
but I find it very irritating to look out for that documentation
folder again and again.
.
I am open for any way i can make dcocumentain folder easily one
click accessible (I am already doing it thru taskbar sortcut. ) But
I want it to get the ease of version control thru Eclipse likewise we
do it for our project
IDE :- Eclipse
I got a way myself :-
I had an idea that if I create a folder in my application project with
some anonymous name that actually android has not listed in its
directories ("I am talking about the default one like "res", "src",
"anim"......)
Then either it should "raise an error" or should "ignore" it while compiling to form apk file
luckily it ignores any such folder. now i can put all the documentation in my project.
NOTE:-
My answer empirically driven
I had tested it by creating a "Docs" folder and then copied 1 GB of
random data (includes almost all type of files we came across from
multimedia to zipped ones).
Then I build the apk and the size of the apk was in-effective of all
this..
but when i copied the same data to assets it was showing a huge change
in size of my apk file..
Consider using Javadoc in addition or, if possible, instead of any other documentation.

Trouble adding raw resource

I'm walking through a small example to hit https web services. It requires building a keystore and placing the resulting bks file into the /res/raw directory. Simple enough. However, I can not access the file through R.raw...
I placed the file into the /res/raw directory, refreshed my project in Eclipse, navigated to the /res/raw directory in Eclipse and confirmed that it showed up in the project. However, when I type R.raw. in my file, the resulting list of possible filenames is empty.
I've tried cleaning and rebuilding, but the project still has no clue what R.raw.mycert is.
What am I doing wrong?
The answer to this question can be found here:
R.raw.anything cannot be resolved
When Eclispe is starting to behave weirdly, my last trick is to remove the project from the workspace and add it again... Try also to quit and restart eclispe
Good luck!
Try this -- find your EclipseWorkspace.
There should be a 'res' directory. So open it.
You will likely NOT find a 'raw' subdirectory.
So create a 'raw' directory, and drop your file into it. (I suppose these have to follow the rwx permissions under Linux that the others follow. I did this in Windows.)
Close the project, then open it again. See if 'res.raw.yourfile' shows up in the package explorer (it should).
I also discovered that 'R.raw.yourfile' is now noticed, and you should find an entry in 'gen/*/R.java' for this.
I think there's a bug in the gen compiler, or maybe Eclipse configuration. gen seems to be very picky about just what kind of resource it wants to look at, and is also doing some name mashing. For example, R.string.xxx finds a string by name xxx, even though the string resources are under 'res.values.string.xml'. So there's clearly a lot of magic going on, maybe special kludges known only to the gods in Mountain View.
Why this fix broke it loose I have no idea.

how we can remove a file from the assets folder at runtime in android?

how we can remove a file from the assets folder at runtime? Is it even possible?
Here is a discussion about it:
http://www.mail-archive.com/android-developers#googlegroups.com/msg16172.html
Seems like the apk is read only and you wont be able to modify it.
Edit:
Check commonswares answer here:
Security of Android assets folder
He is saying the same thing, you can't modify it at runtime.

Categories

Resources