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.

Solution:

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:

System.IO.Directory.CreateDirectory (Applicationfolderpath);

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.SQLite3.Config (SQLite.SQLite3.ConfigOption.Serialized);

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?

Solution:   

  • Page
  1. It is a visual that occupies most or all of the screen and contains a single child.
  2. A Xamarin.Forms.Page represents a View Controller in iOS or a page in Windows iPhone.
  3. On Android each page takes up the screen like an Activity but Xamarin.Forms Pages are not Activity.
  • Activity
  1. Activity represents a screen in an application.
  2. 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

Solution:

developer.xamarin.com/guides/ios/getting_started/hello,_iOS/hello,iOS_quickstart/

Problem 8: Visual Studio for showing option to select an emulator to debug and run iOS simulator on Windows only

Solution:

  1. Build the application
  2. Select the emulator from Device Manager
  3. Start the Emulator
  4. Click on the Start button of the Visual Studio
  5. It will then display error as “deployment failed due to fast dev process”
  6. Go to Project=>Properties=>Android application then uncheck the “use FastDev process”
  7. Again click on start
  8. 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.

Solution:

Required Components

For Mac

  • Latest iOS SDK
  • XCode latest version
  • Mac OS X 10.9.4 + or 10.10 above

For Windows

  • 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.

Solution:

  1. Create the APK file of the application
  2. Navigate to Google Developer Site
  3. 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
  4. Click on the button Add New Application
  5. 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
  6. Click on Upload your first APK to Production button centered on your screen
  7. Select and upload APK file
  8. 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
  9. The next step in the store listing tab is to add screenshots
  10. Then add a store listing icon
  11. The final step on the “Store Listing” page is filling out the categorization, contact details, and privacy policy, located below the icon selection area. Fill out the required fields as you wish and hit save. The “store listing” tab should now have a green check-mark next to it
  12. 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
  13. 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\3.9.236.0\Packages'”:

Xamarin.Forms.1.3.1.6296: Could not install package ‘Xamarin.Forms 1.3.1.6296’. 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”.

Solution:

  1. 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
  2. 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”.

Solution:

  1. Add the xamarin.forms packages
  2. Install PCL libraries. Following is the link to download PCL libraries https://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-    00cb3caf4981/
  3. After this reinstall or repair xamarin
  4. 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

  1. You need the latest version of windows
  2. Microsoft Visual Studio: Microsoft Visual Studio 2013 helps you design, code, test, and debug your apps
  3. 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.

  1. Connect your phone to your PC.
  2. 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.

  1. To get a developer license, just launch Visual Studio. You’ll be prompted to get a developer license
  2. To get a developer account, go to the Signup

Steps to create a Project:

  1. Make sure you’ve downloaded and installed the Windows Phone SDK
  2. 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
  3. 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
  4. In the list of Windows Phone Apps templates, select the Blank App (Windows Phone)
  5. At the bottom of the New Project window, type MiniBrowser as the Name of the project
  6. Click OK. The new project is created and opens in Visual Studio
  7. https://dev.windows.com/en-us/getstarted#1

Notes

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.

Solution:

  1. 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
  2. Once the codebase is shared, select the main folder and uncheck read-only option if present by any chance
  3. Open the project in Xamarin Studio on Mac
  4. 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?

Solution:

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?

Solution:

  1. If you wish to go native, you can go for Xamarin.iOS, Xamarin.Android and Xamarin.Mac
  2. If you wish to go cross platform with UI sharing, you can go with Xamarin.Forms option
  3. If you wish to develop windows app which works on Windows Phone, Windows 10 then go with Xamarin UWP (Universal Windows Platform) app
  4. 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.

Thank you.

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s