Getting PCL, Mvvmcross, Nuget and Xamarin Studio to play "nice" on Mac - xamarin.ios

Looking at the MvvmCross.PortableSupport.3.0.1.nuspec
I noticed the there is the following line:
<file src="_._" target="lib\portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71\_._" />.
I understand that nuget is creating a list of supported frameworks from that list (win+...+sl40+wp71) and that the project to which this library is added must support one of those frameworks. Basically it enumerates the project types to which this can be added.
Now if I try to install this package into a portable project having Profile49 this will work on Windows since Profile49 on Windows is net45+wp80.
However on the Mac the Profile49 is net45+wp80+MonoAndroid10+MonoTouch10.
This means that a nuget package with the supported frameworks win+net45+MonoAndroid16+MonoTouch40+sl40+wp71 cannot be installed on a project of Profile49 on Mac since there are frameworks having a lower version (MonoTouch10 and MonoAndroid10).
Could the string portable-win+net45+MonoAndroid+MonoTouch+sl40+wp71 be used on the mvvmcross side instead? Any reason for the specific versions?
Why do the profiles shipped with Xamarin (e.g. /Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/v4.5/Profile/Profile49) include MonoTouch10 and MonoAndroid10?
Thank you for your insights.

Update: If you are using the Alpha channel of Xamarin Studio there is no longer a need to copy PCLs from Windows. You can use v4.0, Profile158, this also works out of the box with Async.
Update: I added instructions on how to get async to work in PCL in this article: Xamarin Studio Mac, Portable class library, Async and Android, so go there after this article if you want to work with async in your PCL.
A sort of working solution to the problem I had to get Mvvm+PCL+Xamarin Studio on Mac to work. See below for the details.
The steps below make things work for Android and PCL projects. For iOS projects Xamarin Studio on Mac is communicating a TargetFramework of MonoTouch,Version=v1.0 to Nuget. Since the mvvm packages contain +MonoTouch40 Nuget refuses to install the packages on the project. A workaround is to add
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
to the .csproj, add the packages with Nuget and set TargetFrameworkVersion back to v1.0.
I have verified the behaviour in Visual Studio. There a project with TargetFramework MonoTouch,Version=v4.0 is reported to the Nuget plugin. This is why the same packages work on Visual Studio an not on Xamarin Studio Mac. I guess this should be corrected to be consistent.
Steps
Xamarin Studio
Make sure to use the Beta or Alpha channel in Xamarin Studio under Mac
Install the Nuget package manager: Xamarin Studio / Add-In Manager
Install .NETPortable into Mono.Framework
Copy the .NETPortable (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable) folder from a Windows PC to your Mac
Place it under /Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/ (Make sure not to overwrite an already existing folder, in case this gets shipped with Xamarin Studio!!!) (see here also)
Patch Nuget
A patched fork can be found here: https://nuget.codeplex.com/SourceControl/network/forks/takoyakich/nuget/latest, take the 2.7 branch. If you want to patch yourself:
git clone https://git01.codeplex.com/nuget
cd nuget
git checkout -b 2.7 origin/2.7
patch -p1 < {patch file saved from below}
cd src/Core
xbuild
cp bin/Debug/NuGet.Core.dll ~/Library/Application\ Support/XamarinStudio-4.0/LocalInstall/Addins/MonoDevelop.PackageManagement.0.6/NuGet.Core.dll
Restart Xamarin Studio if you kept it open.
Test it!
Open Xamarin Studio
Create a new portable library
On the project, go to options, Build/General you should see a dialog letting you choose the Target Frameworks (e.g. .net45+wp8 corresponds to Profile49)
Goto references, Manage Nuget packages, Add Mvvmcross
Follow one of #slodge 's excellent n+1 mvvmcross tutorial videos from here ...
Patch to Nuget.Core.dll:
diff --git a/src/Core/NETPortable/NetPortableProfileTable.cs b/src/Core/NETPortable/NetPortableProfileTable.cs
index 6f6a9ff..edc710c 100644
--- a/src/Core/NETPortable/NetPortableProfileTable.cs
+++ b/src/Core/NETPortable/NetPortableProfileTable.cs
## -49,16 +49,12 ## namespace NuGet
private static NetPortableProfileCollection BuildPortableProfileCollection()
{
var profileCollection = new NetPortableProfileCollection();
- string portableRootDirectory =
- Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86, Environment.SpecialFolderOption.DoNotVerify),
- #"Reference Assemblies\Microsoft\Framework\.NETPortable");
-
+ string portableRootDirectory = GetPortableRootDirectory ();
if (Directory.Exists(portableRootDirectory))
{
foreach (string versionDir in Directory.EnumerateDirectories(portableRootDirectory, "v*", SearchOption.TopDirectoryOnly))
{
- string profileFilesPath = versionDir + #"\Profile\";
+ string profileFilesPath = Path.Combine(versionDir,"Profile");
profileCollection.AddRange(LoadProfilesFromFramework(profileFilesPath));
}
}
## -66,6 +62,22 ## namespace NuGet
return profileCollection;
}
+ private static string GetPortableRootDirectory()
+ {
+ if (IsMonoOnMac ()) {
+ return "/Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable";
+ }
+ return Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86, Environment.SpecialFolderOption.DoNotVerify),
+ #"Reference Assemblies\Microsoft\Framework\.NETPortable");
+ }
+
+ static bool IsMonoOnMac ()
+ {
+ // Environment.OSVersion.Platform returns UNIX, didn't find a better way :-(
+ return File.Exists ("/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder");
+ }
+
private static IEnumerable<NetPortableProfile> LoadProfilesFromFramework(string profileFilesPath)
{
if (Directory.Exists(profileFilesPath))

As of February 2014, the steps above are not needed. Using Xamarin Studio 4.3.2, Alpha channel, and nuget addin via adding mrward's addin repository first and then installing nuget addin, I was able to switch the target to p49 and add the HotTuna pack directly to a new PCL project.

Related

Android Studio stuck installing application to Device after add jar library

I'm setting up a SignalR client with Android. I'm using Android Studio 3.3 with Gradle v3.0.1.
I'm using two SignalR deprecated jar library in project.
- signalr-client-sdk.jar
- signalr-client-sdk-android.jar
The problem starts after adding these two jar dependencies to project.
After adding jar libs, Android Studio suck in installing application on device.
I did same thing in other project on my friend's PC and it works. I don't know whats wrong with this?
=====
UPDATE
I tried with an other device... I installed GenyMotion Emulator and Created several kind of Virtual Machines.
Android Studio is going to install the application on vm with api level 16 but when trying to install on vm with api level 27(8.1) it stuck again.
Screenshot :
I could generate signed apk and install on phone. but can't install directly from Android studio.
UPDATE
Add these lines to your build.gradle of app module, within the android { }:
android {
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
universalApk true
}
}
packagingOptions {
exclude 'lib/getLibs.ps1'
exclude 'lib/getLibs.sh'
exclude 'lib/gson-2.2.2.jar'
}
}
Old Answer
Try these steps:
Step One: Add this dependency to your build.gradle:
implementation 'com.microsoft.signalr:signalr:1.0.0'
Step Two: Add these lines to your activity:
private final String serverUrl = "put your server url";
private HubConnection hubConnection;
hubConnection = HubConnectionBuilder.create(serverUrl).build();
if (hubConnection.getConnectionState() == HubConnectionState.DISCONNECTED)
hubConnection.start();
if (hubConnection.getConnectionState() == HubConnectionState.CONNECTED)
hubConnection.send("your method name at server", your arguments);
else if (hubConnection.getConnectionState() == HubConnectionState.DISCONNECTED)
hubConnection.start();
As you see at above, you don't need to add two signalR deprecated jar library in project.

which cmake will Android plugin use?

With Android Studio 3.3 I use native (C++) library, which I built with CMake. The Android plugin (v. 3.2.1) will choose the 'builtin' or 'external' cmake, depending on the configuration of externalNativeBuild, as documented at developer.android.com.
I want to add an extra custom task (install) that should use the same cmake version as the Android Plugin. But even with the 'builtin' cmake, it's not clear what the path is. I can find android.sdkDirectory, but even there I have today sdk\cmake\3.6.4111459 and sdk\cmake\3.10.2.4988404, and for some strange reason, some of my projects choose 3.6, while others use 3.10. This contradicts the official the release notes for Android Studio that "Gradle still uses version 3.6.0 by default", but well…
How can I decide which to use, without reimplementing the Android Plugin's obscure logic?
One workaround that may help, parse the first line of the generated file .externalNativeBuild/cmake/debug/armeabi-v7a/cmake_build_command.txt:
Executable : C:\local\Android\sdk\cmake\3.10.2.4988404\bin\cmake.exe
This still needs some adjustments, because the later versions of build tools will use .cxx instead of .externalNativeBuild; the build variant names may be different too.
Android Studio will pick up the latest CMake version under sdk\cmake, but you can configure your particular version from
externalNativeBuild {
cmake {
...
version "cmake-version"
}
}
And specify our custom CMake director as below inside local.properties
cmake.dir="path-to-cmake"
Or, you can choose NOT to upgrade your CMake from SDK Manager (just to delete the sdk\cmake\<version to delete> folder will be fine) so that you can stick to the CMake version your project is comfortable with.

configure your forms app unable to select iOS on target platform

Hi all new to this but just downloaded and installed xamarin studio to my mac but iOS on the target platforms: section on the configure your forms app page is greyed out and cant be selected
any idea how to solve this please
The Xamarin studio don't install everything you need automatically.
1 - Install the latest iOS SDK.
2 - Install the latest version of Xcode.
3 - Install the Xamarin Studio.
Full Guide:
https://developer.xamarin.com/guides/ios/getting_started/installation/mac/
I had the same issue Visual Studio 7.2.2, the iOS box was disabled. There were couple of issues I had
I had the Xcode app named as XCode9.app in the application folder so VS was unable to find the location, so I fixed that one.
I then searched for installed components About VisualStudio--> ShowDetails and found that Xamarin.iOS10 was installed which seem to have incompatibility with XCode9 so I ran the VS installer once again and found that Xamarin.iOS11 was out and after installing the update and restarting, everything worked.
Download the visual studio for mac again and run the installer. It will show you the missing components and give you a way to install them correctly. Worked for me here. It will check what is already installed, you won't have to install everything again.

Xamarin ios unified version is not allowed to install Mvvmcross

I have updated xamarin ios from classic api to unified api.
When i trying to add Mvvmcross nuget package it shows following error
Could not install package 'MvvmCross.PortableSupport 3.2.2'. 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.
Please help.
The MvvmCross.PortableSupport 3.2.2 NuGet package contains an empty Portable Class Library folder and can be installed into a Xamarin.iOS project if you have the Portable Class Libraries installed for Xamarin and if you have the latest version of NuGet installed.
So you may not have the PCLs installed for Xamarin or, if you are using Visual Studio, then your NuGet version may be too old and need to be updated.
To get the Portable Class Libraries:
If you are on the Mac you should install the Mono Development Kit (MDK).
If you are on Windows then things are can be more complicated. The simplest way is to install Visual Studio 2013 (full or Express) Update 2 or higher. The more complicated way is to install the Portable Library Tools and the Portable Library Reference Assemblies 4.6. The Portable Library Reference assemblies installs a PortableReferenceAssemblies.zip file which contains three directories (4.0, 4.5 and 4.6). These three directories need to be extracted and copied into the PCLs directory:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable
Finally on Windows you would then need to reinstall Xamarin. The easiest way to do this is to find Xamarin in the Control panel's Programs and Features and select the option to Repair it.

cordova hybrid app build fail with vs2013 up2 (chinese traditional)

I build cordova project with vs2013 up2 for windows phone platform and receive some error as follow , but build for ios & android is ok .
(1)Non-whitespace before first tag.
I found the js file "C:\Users\xxx\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\node_modules\plugman\src\util\xml-helpers.js" in line 124 command
var contents = fs.readFileSync(filename, 'utf-8').replace("\ufeff", "");
...is failing in chinese traditional environment, when building for windows phone platform the WMAppManifest.xml file has BOM code , so will be error as 嚙踝蕭??xml version="1.0" encoding="utf-8"?>, it should be <?xml version="1.0" encoding="utf-8"?>
have any idea can fix it ?
Thanks.
The issue you are seeing (issues.apache.org/jira/browse/CB-5477) was fixed in Cordova 3.5
(I'm a new poster and haven't earned the reputation points to include more than 2 links in my response, so I'm saving those for the ones that matter below).
If you update to the latest CTP 2.0 for Multi-Device Hybrid Apps, you will pick up the fix.
Unfortunately, there is an other Cordova issue that still exists in version 3.5 which also impacts WP8 in localized environments (https://issues.apache.org/jira/browse/CB-6932).
It has been fixed in Cordova version 3.6 which hasn't yet been released, but here's how you can pick up the fix.
After installing the new MDD tools, create an MDD project and build for WP8. (It will fail under Chinese as it did before.)
Now go into c:\Users\<username>\cordova\lib\wp\cordova\3.5.0\wp8\bin
Replace the existing create.js with the version from here
(click "Raw" to view just the file contents)
https://github.com/MSOpenTech/cordova-wp8/blob/ac097f2801d4defe5e4d445e10b7102001631a54/wp8/bin/create.js
Create a new project and build again for wp8. It should work now and future projects should work as well.
For me, it worked by removing android and adding again.
remove:
ionic platform rm android
add:
ionic platform add android
You can execute these commands at your project directory.

Resources