Why can't I copy/paste img assets from one project into new directories in second project's drawable folder? - android-studio

I downloaded a project from Github, trying to rebuild it myself for learning purposes. I'm new to Android Studio, developing on a Mac. Having trouble with what I think would be simple tasks.
The source project from Github I downloaded has several different sub directories containing image resources under the res/drawable folder. I was hoping I could just copy and paste these assets into my own project. It doesn't seem to work the way I'd expect and I don't understand what is going on.
I've tried right clicking and copy/pasting the directory I'd like to duplicate from the Github project (opened in Android Studio) into the drawable folder in my new project (Also opened in AS). Nothing seems to happen when I do this. Right clicking and selecting "reveal in finder" reveals a still unfortunately empty drawable folder.
I also tried right clicking on the specific directory I'd like to copy from the Github project and selecting "reveal in finder", thinking I'd try copying and pasting it from there into my new project. Oddly enough when I do this, the same directory isn't even the one that's opened. Instead, it opens a drawable-hdpi folder containing several assets, but it's definitely not the one I was attempting to open.
I've tried right clicking and "synchronizing" the drawable folder in my new project after copy/pasting, still no luck.

You can not copy android folders or directories directly into android studio. But you can copy individual files into there respective folders in your project.
If you want to copy folders/ directories you can open the android app folder in your MAC browser and go to Application/app/src/main and paste whatever you have in the respective folders.
The main folder conrains java and res folders and an AndroidManifest.xml file.
You can paste xml files , drawables and pngs etc in res and java classes will go into java folder.

Related

How to put files into Android/Data/com.mycomp.myapp?

I'm new to Android. Switched from .NET WPF/Windows Forms. I have some JSON files in my project. How to put them in the future /Android/data/[packagename]/
folder? In .NET WPF you just open properties for that file and select copy to application folder or so. Probably there is the same method in Android Studio, isn't it?
You put them in the assets folder if you just want them to be read accessible. If you need them to be writable, you'd put them in assets and then copy them to the filesystem on first run.

Can't create Sample Data Directory - Android Studio

I"m trying to Create a sample data directory, using Android Studio, by clicking on app in the project view and then right mouse click to find the menu item New > Sample Data Directory.
It is not working.
Creating the directory via android studio doesn't always work. You may need to create the directory manually in your directory structure (at /app/sampledata/) without using Android Studio. Once you create it (e.g., via Windows Explorer) it should show up in Android Studio. See the the following answer for more information about sample data in general: How to put new placeholder resources into Android Studio project ("tools:sample" resources)?
"Unlike resources like images, fonts, etc. The sample data does not go in /res/ (they are not compiled with the app, hence. It is probably easier to filter them out by putting them in a totally separate directory). They go in /app/sampledata/, for example: /app/sampledata/image.png."
You can create a sample data directory in Android Studio itself by following the below steps:
Change the view of directory structure from Android to Project as follows
Right click app folder and select New->Directory
Finally, give a name to your directory, in your case, it should be sampledata
I have already created sampledata directory that's why it says "Directory already exists".
That's it. You have done it. Remember that Android Studio also supports loading sample data from a json file. All you have to give is fully qualified name of the key residing in the json file.
Ex- if your json file contains key name inside a Json Array student, then you have to specify it as "#sample/your_student_file.json/student/name" to use values present in key name.
Unless your issue happens to be different, this is a known issue that only affects Windows. As I've found, it has something to do with 'C:\' in the file path.
https://issuetracker.google.com/issues/124553391
As Shawn mentioned, you need to manually create the directory.
I've been unable to get the images to actually display in the previewer, which I suspect may also be caused by the file path bug.
Inside the app folder in file explorer, You can create a new folder (sample data) which will be reflected in your android studio.

How to create a directory folder in Android Studio?

I'm using Android Studio and I want to create a directory folder inside the lib folder. I right-clicked on the lib folder but the directory option is not showing.
Can anyone suggest to me how to create a directory folder inside a folder?
You need to go File -> Project structure.
Select lib folder and unmark as source
Right click on the package then "Mark Directory as" -> Unmark as Sources Root. All child packages will be seen as folders.
Try to create package instead of a directory. Seems like Create New Package and Create New Directory will both just create a folder under lib directory.
I found a solution that worked for me In Mac OS,
1- Click over file and select project structure
2 - After, you should click on the lib folder, then unselect the "Source" from top
3- Then, click on Apply then Ok Buttons
4- Now when you try to create a directory on lib you will found the Directory option appears.
Hopefully, that's what you need.
Yeah I had the same problem, so you just have to follow these steps:
1) Go to project structure
Here:
2) Go to Modules and find "Sources" tab
Click here
3) Uncheck Sources and click "Apply"!
(at the beginning it was unchecked and it didn't work, but when I checked "Sources", my folders changed as it was at the beginning(like packages), so I unchecked again and folders changed, and now I can create directories, not packages, hope it helped you!)
Like this:
This was reported here
It's an IntelliJ issue in how they deal with folders marked as source. The lib folder needs to be a source folder for internal flutter purposes. The best way is to use your file manager or terminal to create the folder.
Step 1: There is no pre featured option in Android for adding raw folder unlike Assets folder. Open App folder and select res folder
Step 2: Right click on res folder, select New> Directory, then studio will open a dialog box and it will ask you to enter the name.
Step 3: Write “raw” and click OK. Open res folder and you will find your raw folder under it.
Now you have created raw folder in your project.
You can use the in-built IDE terminal to create the folders.
Here is complete solution that works. Click the link to see images.
Issue
Problem- Cannot create Directory
1)Cannot Create Directory
Click the Gear icon and Untick Compact Middle Package
2)Click Gear icon and Untick Compact Middle Package
Package Structure gets expanded
3)Now Expanded Package View can be seen
Still Not possible to create Directory
4)Still cannot create package
Do as shown in the image
5)Right click Package COM->Mark Directory as->Unmark as Source root
Packages are expanded and now you can create Directory
6)Now the packages are expanded and now Directory can be created
For creating the folder in case of flutter framework in Android studio, follow the steps as shown below:-
Right click on the folder with the name of your app i.e. the root folder.
In the drop down menu click on the new option.
After this a drop down menu opens here you will see directory option just click on that.
After this enter the name of your directory / folder and press enter this will create a new folder / directory inside your root folder.
If you want to make the directory inside the lib folder then just drag the directory from the root folder into the lib folder.
After this a dialog box will open in this dialog box check if search for references is tick marked or not if not then tick mark it.
Now click ok this will create your directory inside the lib folder.
Hope this may help.

MonoDevelop's Images directory does not seen on XCode(IB)

In my project files marshalling shown below ,Mono Develop doesn't show Images directory(group) in XCode and they are not seen on xib interfaces,also crashes on runtime. But when I put images under Project's root directory works fine!
Fine! But seeing dozens of images on root directory make things confusing.
Here goes details;
My images built actions are content.
I have tried adding them to Xcode by creating a group named Images then this time all images copied to Mono Develop's root again.
Am I missing something?
Project
--Images
---- FaceOff.Png
---- icons
---------CandyButton32x.png
I think you are experiencing a limitation of the XCode integration with MonoDevelop.
Images only show up in XCode if they are in the root directory of your project. To combat this, there are two ways you can setup your image folders for MonoTouch projects:
Use build action Content, put your images anywhere, but they will only show up in XCode if they are in the root of the project
Use the build action BundleResource and put all your images in the Resources folder, this is the same as putting your images in the root of the project, but you get to package them nicely in a subfolder
I have not experimented with BundleResource and XCode to see if subfolders work via that method or not.
This is from my experience, someone from Xamarin, feel free to chime in.
Further to Jonathan's great answer, I have a nice organised setup for my images using BundleResource and the Resources Folder.
On the filesystem I have all my images in a nice directory structure, for example: img/common/title.png.
I then add all the image files (not directories) into the iOS project Resources folder, using the 'Add Files' option and selecting BundleResource for the files I select.
When given the copy, move or link option, because my files are outside the target directory, I select the 'Add a link to the file' option.
This procedure allows me to:
Happily keep all my images in an organised directory structure on the file system
Have access to them in XCode Interface Builder
Access them as root when in code, such as Image.FromFile("title.png")
Easily update them in the filesystem and have them automatically change in Xamarin Studio

How to remove a folder from a MonoTouch project?

In MonoDevelop I can right click a file in a MonoTouch project and select "Remove" and it then gives me an option of removing the file from the project. However, if I right click a folder, the only option available is "Delete" which brings up a confirmation box saying that the entire folder will be deleted. How do I remove a folder from a MonoTouch project? Does this functionality exist somewhere or has it not been built yet?
I think the easiest way to do this is to handle all the files outside of monodevelop. Just move it to wherever you like and then delete the folder from inside monodevelop.

Resources