I have a Xamarin.Forms app that needs to read data from a json file. I placed the file into the Android assets folder and selected the build action AndroidAssets
Then I try to load the file in MainActivity with Assets.Open(filename) and I get a FileNotFoundException. I deleted the Android and PCL bin folders and tried to build the project again but got the same result. Then I opened the .apk file in WinRar and when I go to the assets folder, the files that I added to the project are not there.
Does anyone have any idea what's the problem here?
Did you set the files as embedded resources from the file properties?
If you not, right click on the file -> Properties -> set as Embedded Resources in Build Action
The problem was with using the "-" character in resource file names. Changed it as suggested by York Shen and it started working as it was supposed to.
Related
I made a UI layout using adobe XD and wanted to export it to use in android studio.
I achieved this by using the Export-kit plugin, which conveniently exported all my required assets for one page into a folder.
Exported assets folder
the readme.txt then directs me to copy all these assets to the folder for the noactivity project folder for android studio.
after doing so , I still don't get any response.
So, I try it with a basic activity and manually add all the required XML codes (activity_main,colours,styles,e.t.c) , but still don't see anything.
I know that the skins exported from xd are in the project folder
(Copied values in the projects folder)
but I cant seem to view them on android studio.
Android Studio Window
any help in this issue will be really appreciated.
You have to put those files in the drawables folder inside the res folder, and keep the colors, string into their respective folder in the values folder inside res.
Today Android Studio started to behave strange. Source java files opens
as png files something. I can build and run the app and if I look in the file system the java files looks ok. I do Invalidate cache and restart, I delete .idea and build folders but no change. The strange thing is I can debug run the app. If I want to change java files I have to open like Notepad and save then build project again
There must be some file/setting in Android studio that control this. I delete the project ide and build folded but no change, where in Android Studio can I reset this to start working normal?
I found a solution that worked for me.
I hade to open every java source file and all xml files into a text editor(Notepad++) and change something then save the file back to origin.
Now Android Studio detect all files as normal
Another way to solve this:
Close Android Studio and delete the caches folder:
C:\Users\user_name\.AndroidStudio4.0\system\caches
When you save a file at notepad and open it in Android Studio, it will happen because notepad use a different encoding (ANSI).
You can set your project file encodings at Settings->Editor->File Encodings
You can also edit a unique file encoding at File->File Encoding
Make sure your project file encoding is UTF-8 (default)
Another important setting is File Types that you can take a look too. Here is mine .java file setting to you as example.
I create a folder in android package path (in this path: app\build\generated\source\r\debug\android\ ) named "print" to put my files.
Application works well but after a while it removes automatically and must create and copy my files again.
I unchecked "Optimize imports on fly" in Settings>Editor>General>AutoImport but again deleted my file (same as checked).
I don't understand why it deletes that file and folder, You have any solution?
You have to put the file inside the src folder ,not the build folder.
screenShot showing where the file should be
You are putting your folder inside an Android generated folder. That will get regenerated every time you rebuild. You will have to put your files elsewhere. If they are media files, put them in a resource folder. Otherwise, assets works too.
I am using Android Studio 2.1.1 (currently the most updated stable version).
I created new directory inside 'res' by name "values-21"
and it don't shows up.
But if I go to the physical location of 'res' on the hard drive I can see that its exist.
and of course I checked using both Android and Project Files structure but either way its not showing it.
I wanted to check where is the problem so I created another directory by name "menu", and the last one was shown.
just to be sure I tried to create the same directory again ("values-21") but Android studio didn't allowed it because this directory allready exist's.
any ideas how to fix it?
Update - the solution is to create new directory using the "Android resource Directory" option and not by "Directory" option.
all you values xml files stored in values, values-21, values-mdpi or other physical folder in AndroidStudio displayed in one res/values folder.
It will not show until you copy a XML file into values-21, android studio consider all values folders to be of same family and it shows only one folder and the files with post script of the family in which it lies.
copy some layout file from resource directory and through windows explorer paste in that the folder that you have created i.e values-21 and now come back to android studio and check the folder should be there.
Happy coding
Recently I installed Android Studio, before I used Eclipse. While using Eclipse I could put all the files in Assets directory and access it using getassets method. For example:
InputStream ims = getAssets().open("textnew.txt");
Can you please advise:
Where to store files in Android Studio? Should I create folders in /res directory myself and put files there. For example: res/raw/textnew.txt
How to access those files? For example I need to open txt file in order to place its content to TextView. How to do it?
Thanks!
You can still use an asset folder in Android Studio.
Create manually a folder asset in your app directory.
Using the menus : File / New / Folder / Assets Folder
I think that the only difference with Eclispe is that in Android Studio the folder is not created by default.
Android Studio has a nice assistant to create an asset-folder. This way it will be created in the correct location.
Right Click on your project
Click "New" -> "Folder" -> "Assets-Folder"
Follow the assistant
Your folder should be created and will be added to your main-sourceset.