Xamarin App Folder Structure
Folder Structure
Let us now see the folder structure of a Xamarin Project, understanding this gives us more access to project.
In this tutorial we are considering Android and iOS projects only, which means this is not included Windows Projects.
Project Folder Structure
Solution folder
The project is called the solution. This contains all the main folders of the project. Here we can also add other libraries folders.
Additional Libraries
The libraries are optional, assume you have working with multiple projects and you will have add/create few files that are common in every project. So we can create a library folder and add this common files in at and add this library to every project that you are working on., and then this folder is to be referenced in the folders where you want to use the library. I will be covering how to add and use a library in Advanced Xamarin tutorials so that we can avoid confusion for now.
This contains three primary folders
1) PCL
2) Droid
3) iOS
PCL
PCL is the acronym for Portable Class Library, Simply to understand this is this is a common library folder for both Android and iOS. We can design the UI and common logic here. This is created with the solution name itself.
PCL is the acronym for Portable Class Library, Simply to understand this is this is a common library folder for both Android and iOS. We can design the UI and common logic here. This is created with the solution name itself.
This main folder have predefined or default sub folders. They are
a) App.xaml and App.xaml.cs
This is the first page called from the respective folders(Droid, iOS).
b) Packages
This sub-folder contains nuget packages. By default we will be having Xamarin.Forms package installed, this package gives us access to different elements which helps us to design UI. Also we can add many other packages that helps in app development process. To add a package just right click on the packages folder and select “Add Packages”.
c) References
This sub-folder contains reference for other folders and the folders of the nuget packages that were added in packages folder.
This is more important because if you have any user defined libraries available(we discussed above), then to add them to project you can simply add to the solution by right clicking and add/edit reference.
d) Packages.config
All the packages added in the packages folders will be presented here in xml format that contains name, version and supported platforms of the added packages.
Along with the predefined folders, we also have to add few folders to keep seperate folders in separate folders. Some of them are
e) Views
This contains the UI part, which is visible and interacts with the user
f) CustomControls
This folder is also for UI designs, Here we create files which are UI designs and are repeatedly used for this project alone, also Xamarin.Forms in this common library dont provide all the UI functionality that are available in native projects (java.android, swift-iOS)
. So to use such kind of functionality we will be using this folders.
Here in this folders we call/request that required UI functionality.
g) DependencyServices
This folder contains local service which means similar to the CustomControls to access functionalities like emails, sms, etc,.. We have to access through dependency services. So those files will be placed here.
Droid:
This folder contains all the services that access the android device functionality like sending emails, smss, accessing contacts, etc,...
Similar to the PCL files and folders the functionalities will be same in this project folders also.
Few things that are distinct will be discussed here.
a) DependencyServices and CustomControls
The services called from PCL will be received, accessed, and returned from here.
b) MainActivity.cs
This is the main file/activity that is called in the application and from here App.cs file available in PCL will be called.
c) Properties Folder
AndroidManifest.cs
Open this file and at the bottom you find tabs, out of them click on Source. So here is where you add permissions and also request access to android services like reading external storages, accessing internet, accessing bluetooth, accessing wifi,...
Without adding the requests for required functionlities we cannot request for the services in dependencyservice.
In here we also set the launchScreen of the application and also the app Icon. We can set the application name here.
d) Assets Folder
This folder contains assets that are required for applications like fonts, …
The android project will provide some default fonts, if still you need any other custom fonts then the respective “ttf” has to be added here.
e) Resources Folder
i) layout folder
Here we can add xml files with ui designs. This will be discussed later tutorials
ii) values
This folder contains
colors.xml : this contains color codes to use in layout folder.
strings.xml to store repeatedly used strings in layout folder..
ii) drawable folders
Here we can add design styles that aids to UI designs similar to css for html.
Here also we will add image files with png format that required for application.
Drawable folders include drawable, drawable-hdpi, mdpi, -xhdpi, xxhdpi, -xxxxhdpi.
Here each folder represent a size of the android device.
All common images will be added in drawable folder irrespective of sizes.
If there is a image with different sizes, then each size will be added to each folder in increasing order of sizes as hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi.
iOS:
This folder contains all the services that access the iOS device functionality like sending emails, smss, accessing contacts, etc,...
Similar to the PCL files and folders the functionalities will be same in this project folders also.
Few things that are distinct will be discussed here.
a) DependencyServices and CustomControls
The services called from PCL will be received, accessed, and returned from here.
b) AppDelegate.cs
This is the main file/activity that is called in the application and from here App.cs file available in PCL will be called.
c) info.Plist
This is similar to AndroidManifest.cs file in android folders. Here we declare the user permissions requests to access his personal and other devices services like gallery, camera,...
In here we also set the launchScreen of the application and also the app Icon. We can set the application name here.
d) Resources folder
Unlike Android iOS have only one folder to declare all the assets that are required for application. Images, font families,... will be placed here.
Similar to Android, iOS also have 3 types of devices sizes. They are
1) 1x,
2) 2x,
3) 3x
If we add a image like image.png then this will be used for all the devices as a common asset.
To add different sizes of a same image or different images for different sizes of devices you have to add a suffix to the image names as
1) imagename@1x.png,
2) imagename@2x.png,
3) imagename@3x.png
Thus we can say the device to use particular size of image for particular sized device.
d) Assets.xcassets
This folder is where we declare the app icons and launch screens and then accessed from the Info.Plist
Here are the most important and possible folders and terms we will be using in the application development using Xamarin.Forms.
If you understand this then the app development will be so easy from here on.
Outstanding work author. Knowledgeable enough. We will surely share your work. Anyway, If you are interested and looking for website development you may visit this website
ReplyDeleteweb and app development company
hire xamarin developer
hire abp.io developer
hire .net developer