Hi everyone, I have been thinking to write this article for quite a while now. Being continuously working on Xamarin in-depth and proposing solutions to the clients, you face some common problems. This article focuses on the resolving these issues faced by Xamarin developers and help them for smooth Xamarin Solution.
You may find some problems related to core development and some related to the solution proposal. If you feel anything is missing and needs to be present in this list, feel free to drop a comment and I would be really happy to add it to this list with mentioner’s name.
Problem 1: It may happen that you are unable to access Android SDK as it was installed in the administrator folder and was not having required permission to access it.
Solution: User must have Admin rights to access that folder.
Problem 2: Unable to provide internet access to emulator even after changing the proxy settings.
Solution: You can try to increase the target API level and install the ARM EABI v7a system image for it and then change the proxy settings of the emulator.
Problem 3: Emulator starts and stops immediately. Failed to create Context 0x3005 for an emulator.
Solution: It requires to update the Intel GPU driver.
Problem 4: Unable to use the local database in Xamarin app as it cannot find the physical path of the database file.
Xamarin creates its own database in its APK file as follows:
Set absolute path for folder creation like:
String path = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
String Applicationfolderpath = System.IO.Path.Combine (path,”Database1”);
Where Database1 is the name of the newly created database
Create the folder path like below:
Create database in set path like below:
String databasefilename = System.IO.Path.Combine (Applicationfolderpath,”User.db3”);
Where User.db3 is the name of the database file.
SQLite.SQLiteConnection Db = null;
Db = new SQLite.SQLiteConnection (databasefilename);
Var res = db.CreateTable<Classname> ();
Problem 5: Unable to provide WCF service on another machine
Solution: Provide service on other machine using IIS manager.
Problem 6: What is the difference between Page and Activity?
- It is a visual that occupies most or all of the screen and contains a single child.
- A Xamarin.Forms.Page represents a View Controller in iOS or a page in Windows iPhone.
- On Android each page takes up the screen like an Activity but Xamarin.Forms Pages are not Activity.
- Activity represents a screen in an application.
- Android Application Architecture doesn’t have a single application instance so there is an aggregation of one or more activities.
Problem 7: Mac machine is required to develop iOS app on Xamarin
Problem 8: Visual Studio for showing option to select an emulator to debug and run iOS simulator on Windows only
- Build the application
- Select the emulator from Device Manager
- Start the Emulator
- Click on the Start button of the Visual Studio
- It will then display error as “deployment failed due to fast dev process”
- Go to Project=>Properties=>Android application then uncheck the “use FastDev process”
- Again click on start
- With the latest updates for Xamarin.iOS, you can run iOS simulator on Windows Machine only. To enable this, go to settings and check run emulator on windows option
Problem 9: How to develop iOS app using Visual Studio.
- Latest iOS SDK
- XCode latest version
- Mac OS X 10.9.4 + or 10.10 above
- Windows 7 or higher
- Visual Studio 2012 Professional or higher
- Xamarin’s plugin for Visual Studio
Create Xamarin.forms blank project in Visual Studio. It will then ask for Mac IP or Mac name. Provide the required information and connect it to the Mac machine.
Problem 10: How to add an application on Google Play Store.
- Create the APK file of the application
- Navigate to Google Developer Site
- Logging into Google Developer Console. If you do not have an account create a new account. The last step in the process of creating a developer account is paying a one-time $25 developer fee using a credit or debit card
- Click on the button Add New Application
- Initialize APK Upload. Select correct language and write the name of the app as you wish it to appear in the google play store. Then select upload APK button
- Click on Upload your first APK to Production button centered on your screen
- Select and upload APK file
- Navigate to the store listing tab on the left side and write the description in the description box which will appear on the google play store
- The next step in the store listing tab is to add screenshots
- Then add a store listing icon
- Click on Price and Distribution tab where you will select paid or free, distribution countries, and check the boxes saying that your app complies with the guidelines and the US export laws. Click on save button
- Once all the three tab at the left have a green mark you are then able to select “Publish this app” from the “Ready to Publish” drop-down menu in the top right corner of the developer console. A confirmation bar should appear at the top, stating that your app will appear in the Google Play store in just a few hours
Problem 11: On creating new Xamarin.forms project in Visual Studio it is giving the error “Could not add all required packages to the project.
The following packages failed to install from ‘C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\EXTENSIONS\XAMARIN\XAMARIN\188.8.131.52\Packages'”:
Xamarin.Forms.184.108.40.20696: Could not install package ‘Xamarin.Forms 220.127.116.1196’. You are trying to install this package into a project that targets ‘Xamarin.iOS,Version=v1.0’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author”.
- To solve this issue open your visual studio go to tools -> Extensions & Updates -> select updates -> select visual studio gallery then update your NuGet package manager
- Update the Visual Studio Version if the updates for it are available. Update it using the same above procedure as for updating NuGet manager
Problem 12: On creating new Xamarin.forms project in Xamarin Studio it is giving the error “Could not add all the required packages to the project”.
- Add the xamarin.forms packages
- Install PCL libraries. Following is the link to download PCL libraries https://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10- 00cb3caf4981/
- After this reinstall or repair xamarin
- In Xamarin Studio, right click on the project select options=>build=>general then change the target framework to that profile which is installed.
Problem 13: Windows application prerequisites and steps.
Solution: Prerequisites for Windows app
- You need the latest version of windows
- Microsoft Visual Studio: Microsoft Visual Studio 2013 helps you design, code, test, and debug your apps
- If you don’t already have Visual Studio 2013, install the free Visual Studio Express 2013 for Windows
If you already have Visual Studio Professional 2013 or a higher edition, get Update 3 for Visual Studio 2013 to add the Windows Phone development tools and other enhancements to your existing installation:
(Optional) Register your Windows phone device for development:
It’s important to test your Windows Phone Store apps on a real phone. Before you can deploy apps to your Windows Phone, you have to register the phone for development.
- Connect your phone to your PC.
- Run the Developer Phone Registration tool (phonereg.exe).
Register as an app developer:
Now that you’ve installed the tools you need, you need a developer license or a developer account. A developer license is free and lets you develop Store apps, but you need a developer account to sell your apps in the Windows Store and the Windows Phone Store.
- To get a developer license, just launch Visual Studio. You’ll be prompted to get a developer license
- To get a developer account, go to the Signup
Steps to create a Project:
- Make sure you’ve downloaded and installed the Windows Phone SDK
- Launch Visual Studio from the Windows Start screen. If the Registration window appears, you can register the product, or you can temporarily dismiss the prompt
- Create a new project by selecting the FILE | New | Project menu commandIn the New Project window, expand the installed Visual C# or Visual Basic templates, and then expand Store Apps. Select the Windows Phone Apps
- In the list of Windows Phone Apps templates, select the Blank App (Windows Phone)
- At the bottom of the New Project window, type MiniBrowser as the Name of the project
- Click OK. The new project is created and opens in Visual Studio
Installation instructions for Xamarin
- Install Java JDK
- Install Android SDK (Including all API levels)
- Visual Studio 2012 Professional
- Install Xamarin Studio
If Xamarin Studio is installed before Visual Studio then Xamarin needs to be reinstalled
Problem 13: When your codebase is on TFS and linked with the local workspace present on Windows machine. How to design UI for iOS apps easily.
- It is recommended that you must connect with Mac agent and share your codebase for mac machine user. This will enable that same codebase is present on both machines
- Once the codebase is shared, select the main folder and uncheck read-only option if present by any chance
- Open the project in Xamarin Studio on Mac
- Right click on the Storyboard file inside Xamarin Studio and open it with XCode
The support by iOS designer in Xamarin is not much fast yet and you are always recommended to use XCode to design your iOS app. Once the changes in XCode are done, they are reflected in your Xamarin project
Problem 14: How do I share code in Xamarin Native apps?
You can create .NET class library if you want to share code between iOS and Android apps. It is recommended for a normal mobile app to consume to class libraries like Common Code and Service Connection Code.
If you wish to extend support to Windows Phone as well, then .NET class library does not work there. You are advised to use Portable Class Library (PCL). This library can be used in iOS, Android and Windows Phone Xamarin apps.
Problem 15: What are different types of Xamarin apps and which one should I propose to my client?
- If you wish to go native, you can go for Xamarin.iOS, Xamarin.Android and Xamarin.Mac
- If you wish to go cross platform with UI sharing, you can go with Xamarin.Forms option
- If you wish to develop windows app which works on Windows Phone, Windows 10 then go with Xamarin UWP (Universal Windows Platform) app
- Still there are lot of different templates being created as the new versions of Xamarin.Studio are coming up
These were some common problems faced by developers. I am working on Xamarin in depth and would keep on posting some interesting information on this blog regularly. If you have any questions, you can post in comments section.