locked
Switching to cross platform RRS feed

  • Question

  • User307738 posted

    Hi

    I successfully created my first actual android application using VS2017. I now want to convert it to a "cross platform" so I can publish it to ios also.

    Can i just create a new app and add all the layout's and classes to it? Or is there some other method to use?

    Regards

    Meir

    Thursday, March 30, 2017 5:05 AM

Answers

  • User2157 posted

    There's multiple methods, I'm assuming that your current Android app is in Xamarin Android as opposed to Xamarin Forms? (If it is in Forms, or you want to port to Forms then a bit different and not my expertise). But generally read this first - https://developer.xamarin.com/guides/cross-platform/application_fundamentals/code-sharing/

    Pros and Cons to each, I normally use the shared files / shared extensions method (although I actually take it a stage further which is more complicated to visualise!), if all the core libs and extensions you use can be built into a PCL then that might be easier. Broadly you have to split off UI / Front End code off and backend code that can be share into another

    My method, assuming iOS and Android actually has two visual studio solutions, one for each platform, but you can probably do it without.

    Starting point is to create a plain, platform independent, C# class library project, this contains all your common files, eg models, viewmodels etc.

    Then create another project that's a platform specific class library (eg an iOS class library, and an Android Class library), and add a link (not import) to every file that's in the original class library. If there are and 3rd party libraries that are platform independent you add them here, eg if you're using Restsharp in your common code and there's a difference between the Restsharp iOS nuget and the Android then you add the relevant nuget to the the relevant platform project. End result is you have two platform specific class libraries with identical code, identical functionality, and single code base to manage.

    Finally you create a front end project for each platform, ie a Xamarin iOS and a Xamarin Android project, and the platform version of the class library as a reference to gain that functionality, and then build out all the platform specific UI, resources etc in these projects.

    Bingo, it's probably a bit old school, and tough to visualise, but works, always! Freely admit the PCL approach is much, much neater, all depends on what 3rd party extensions you need.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, March 30, 2017 7:53 AM

All replies

  • User2157 posted

    There's multiple methods, I'm assuming that your current Android app is in Xamarin Android as opposed to Xamarin Forms? (If it is in Forms, or you want to port to Forms then a bit different and not my expertise). But generally read this first - https://developer.xamarin.com/guides/cross-platform/application_fundamentals/code-sharing/

    Pros and Cons to each, I normally use the shared files / shared extensions method (although I actually take it a stage further which is more complicated to visualise!), if all the core libs and extensions you use can be built into a PCL then that might be easier. Broadly you have to split off UI / Front End code off and backend code that can be share into another

    My method, assuming iOS and Android actually has two visual studio solutions, one for each platform, but you can probably do it without.

    Starting point is to create a plain, platform independent, C# class library project, this contains all your common files, eg models, viewmodels etc.

    Then create another project that's a platform specific class library (eg an iOS class library, and an Android Class library), and add a link (not import) to every file that's in the original class library. If there are and 3rd party libraries that are platform independent you add them here, eg if you're using Restsharp in your common code and there's a difference between the Restsharp iOS nuget and the Android then you add the relevant nuget to the the relevant platform project. End result is you have two platform specific class libraries with identical code, identical functionality, and single code base to manage.

    Finally you create a front end project for each platform, ie a Xamarin iOS and a Xamarin Android project, and the platform version of the class library as a reference to gain that functionality, and then build out all the platform specific UI, resources etc in these projects.

    Bingo, it's probably a bit old school, and tough to visualise, but works, always! Freely admit the PCL approach is much, much neater, all depends on what 3rd party extensions you need.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, March 30, 2017 7:53 AM
  • User307738 posted

    Thanks.. I'll follow your advice :)

    Thursday, April 6, 2017 9:50 AM