How do I change MonoDevelop Target Framework to iPhone for imported .Net library project - xamarin.ios

I've imported an existing C# library project into a MonoDevelop Solution targeted for iPhone. My original project has a target Framework selection of Mono for iPhone but my newly added project only has Mono/.Net choices. How do I get the iphone targets to show up so I can properly reference it from my existing iPhone targeted projects?

Easiest way I've found is to make a new MonoTouch Library project and either "link" or "copy" the files from the existing project.
This is usually necessary anyway, as usually you will have to add #if MONOTOUCH preprocessor statements in a couple places.

Related

Importing LIBGDX library gdx-backend-android.jar into Android Studio Project

After a hiatus of a couple of years I'm picking up Android development again.
I installed the newest Android Studio(4.1.1) with the latest Android SDK version (Android 11, API 30). After that I created a new project with gdx-setup.
If I add the old java source to my newly generated project I get this error:
error: package com.badlogic.gdx.backends.android does not exist
I'm not sure how to add this jar into the new project. In the Gradle configuration I see mentions of the backend, but it's not available.
I also downloaded the 'gdx-backend-android.jar' from the nightly build and put the jar in the Android library folder, all to no avail.
Does anyone actually know how to correctly add this dependency into my project?
I added the jar but still have an error, don't mind the other errors, I first need to fix the GDX import.
The project dependencies are managed by Gradle, so there is no need for you to directly touch any .jar files at all.
The most likely issue you're facing is that you are trying to use Android-specific classes from the core module, which is platform agnostic.
In a typical libGDX project, you do almost all your game code in the core module so it can easily be compiled for any platform. The code you showed above would be in the android module, but your LiveWallpaperStarter class would be part of core.
Some might say there's no reason to use core at all if you're making a Live Wallpaper, since it can't run on any other platforms besides Android. But there is some advantage in keeping the rendering in core so you can test in a desktop game window, because you can more rapidly compile and run on the desktop. This library has some tools that make it easy to wrap your rendering code in a class that lets you simulate a live wallpaper on desktop, for testing.

Code works on Android and iOS - why can't I move it into a PCL?

I have a static class that uses
System.IO.Path
System.IO.Directory
System.IO.File.
Currently, the class is in my iOS project and unchanged also in my Android project.
I created a PCL that targets Android and iOS only.
However, neither one of the namespaces is available.
I presume that is because iOS and Android alone are not suitable for a PCL profile and that's why Windows Store 8 or Silverlight 5 gets added and that removes the System.IO.* namespaces.
Is this working as designed? Is file linking my only chance in this case?
Yes, for now this is the way it's supposed to work. You can use something like my PCL Storage library to access the file system from a PCL, or you can simply use file linking.
As a side note, I'd recommend choosing Windows Store and .NET 4.5 along with the Xamarin targets. That profile is going to give you more APIs than the one which targets Silverlight 5 which you get by default when you just choose Xamarin platforms in that dialog.
System.IO.Path, System.IO.Directory and System.IO.File are partially supported in PCL profile EXCLUDING silverlight 5: WP8 + NET4.5 + Xamarin + iOS.
Path.Combine works perfectly in this targeted PCL.

Sharing projects with MonoTouch

I have a class library project (developed in VS) which I want to share with a MonoTouch project I'm working on. The problem is that when I try to add a reference to the library project in MonoDevelop an error is displayed saying 'Incompatible target framework: v.NETFramework,Version=v3.5)'.
From what I've read on the web I have to create another class library project in MonoDevelop and then link all the project files from the original into it...I'll do this if I have to but i'd rather have a cleaner solution to this, if not a simple project file fix then maybe a script I can run...
Regards
Lee
A Portable Class Library would be the way to go, but unfortunately not yet properly supported in the current version of MonoDevelop with MonoTouch. Work seems to be in progress though.
You do have to create a class library project in MonoDevelop. The library has to be compiled with the MonoTouch version of the framework.
The reason for this is MonoTouch framework is based on the Silverlight lightweight version of the .NET framework.
See here http://docs.xamarin.com/ios/about/assemblies for more info.

Does monotouch support multi-file assemblies through modules?

I'm creating a cross platform set of applications, and some of the assemblies are constructed as multi-file assemblies using a set of modules compiled under visual studio 2010. Does the monotouch compiler support multi-file assemblies like these?
You can create a MonoTouch Library project to do this, however you will have to compile the library for MonoTouch.
To do this properly, here is an example:
On Windows create 2 projects MyApp and MyApp.Code (a class library project)
On iOS create 2 projects MyApp and MyApp.Code (a MonoTouch library project), in a different folder in your source control, of course
Put all the code into MyApp.Code (Windows version), on iOS "Link-In" every file you want to add the to the project from the Windows copy. This keeps one copy of the file, but allows you to compile for multiple platforms
MyApp will just contain UI-specific code on both platforms and is completely different on both platforms
Add #if IPHONE or #if WINDOWS preprocessor directives anywhere you might need them throughout the MyApp.Code project
Rinse and repeat if you want to do the same for Mono for Android, Windows Phone, etc.

Is it possible to create a stand-alone Monotouch class library?

I'm all about code reuse. One of the best ways in .NET/Mono is to create a class library. I have a few custom UIViews that I would like to place in a class library (.dll) so that I can redistribute it but for some reason I am not able to create a project that references monotouch from a stand-alone library. The only way to reference it is to create a full blown iPhone project -- not what I want.
Any help would be appreciated.
Under MonoDevelop project types C#->iPhone and iPad, I have
iPhone Window-based Project
iPhone OpenGL Project
iPhone Navigation-based Project
iPhone Utility Project
MonoTouch Library Project
Empty MonoTouch Project
iPad Window-based Project
Universal Window-based Project
You want MonoTouch Library Project. This will compile a DLL that can be referenced in another MonoTouch project.
I know this works because I have 2 projects that reference a DLL I created just for the benefit of reusing code.

Resources