Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install Microsoft.Azure.Devices in a Xamarin Forms android project #106

Closed
albaek75 opened this issue May 13, 2017 · 15 comments
Closed
Labels
bug Something isn't working.

Comments

@albaek75
Copy link

Hi

I am getting this error when trying to install Microsoft.Azure.Devices to Xamarin Forms android project.

Error Could not install package 'Microsoft.Azure.Devices 1.2.4'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1', 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.

Is there any plans to add this support?

@tameraw
Copy link
Contributor

tameraw commented May 24, 2017

@albaek75 - Microsoft.Azure.Devices 1.2.6 is our first package that supports .NetStandard (version 1.3 is what we have).
Please try with this package and let us know if still having issues.

@tameraw tameraw added enhancement New feature or request. question Further information is requested. and removed enhancement New feature or request. labels May 24, 2017
@sarsijravi
Copy link

@tameraw -
Is this only for MonoAndroid? Beacause I tried installing for the portable class in Xamarin forms and got the following error:
Could not install package 'Microsoft.Azure.Devices 1.2.6'. You are trying to install this package into a project that targets
'.NETPortable,Version=v4.5,Profile=Profile259'

Any Solutions?

@tameraw
Copy link
Contributor

tameraw commented Jun 5, 2017

@sarsijravi - Please try with a Profile 7 and let us know if still having issues.

@sarsijravi
Copy link

@tameraw
Already tried. Doesn't work.
Got the following error again:
Could not install package 'Microsoft.Azure.Devices 1.2.7'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile7', but the package does not contain any assembly references or content files that are compatible with that framework

@tameraw tameraw added investigation-required Requires further investigation to root cause this. and removed question Further information is requested. labels Jul 18, 2017
@tameraw
Copy link
Contributor

tameraw commented Jul 19, 2017

@albaek75 - we'll investigate the issue. Thanks.

@tameraw tameraw added build issue and removed investigation-required Requires further investigation to root cause this. labels Jul 19, 2017
@tameraw tameraw added bug Something isn't working. and removed build issue labels Oct 18, 2017
@ryan-z-johnson
Copy link

ryan-z-johnson commented Oct 18, 2017

@sarsijravi sorry for the long delay. I have been able to reproduce your issue. The way we are encouraging people who are using a mono based platform is to create a .NetStandard 1.3 class library and add the nugget package to that, and reference the library in your Xamarian.Android application. Here is a GitHub Repo with the structure I am talking about. https://github.com/ryan-z-johnson/AzureIoTXamarin

If you have any more questions please let me know.

@CIPop
Copy link
Member

CIPop commented Oct 19, 2017

We're tracking multiple issues caused by the PCL libraries. The decision was to remove the PCL binary from our next release.
Please follow the above workaround until we complete this work.

Tentatively closing this as a duplicate of #138 .

@CIPop CIPop closed this as completed Oct 19, 2017
@coltonf93
Copy link

@ryan-z-johnson
This workaround successfully builds the Android application with the device client dependency but breaks when you actually try to use it.
e.g. add this constructor to the SharedLibrary class1 file and try building the android project.

public Class1()
{
    var _deviceClient = DeviceClient.Create("", new DeviceAuthenticationWithRegistrySymmetricKey("", ""), TransportType.Mqtt);
}

It throws:
Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Azure.Devices.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Perhaps it doesn't exist in the Mono for Android profile?
Any ideas?

@CIPop
Copy link
Member

CIPop commented Feb 22, 2018

@coltonf93 I've seen issues when either Xamarin or Visual Studio are not up to date.
Also, can you confirm you're using the latest release of our SDK?

@coltonf93
Copy link

coltonf93 commented Feb 23, 2018

@CIPop I'm modifying/building the recommended workaround referenced above with all the latest released versions. Still no luck.

  • The reason the library can't be included in the android project directly seems to be an incompatibility with the Device.Client dependency System.Threading.Overlapped.

  • The Device Client PCL works with Android but doesn't support MQTT and will soon be unsupported.

  • If we're unable to get the android application working using the SDK with MQTT, we may be forced to use the PCL and switch our protocol to HTTPS.

Do you know if anyone has been able to build a functioning android application with an implementation of the device client library, not just the reference? I could be missing something, but as soon as you implement the DeviceClient class in the shared library, the build fails.

@CIPop
Copy link
Member

CIPop commented Feb 26, 2018

@coltonf93 We're not supporting PCL at all in either LTS or master.
This issue was due to the fact that we were shipping a PCL target within the NuGet package. The last releases do not have such PCL target.

After upgrading VS and Xamarin, you will need to also switch to the latest Xamarin.Forms template:
image

Select the ".NET Standard" Code Sharing Strategy:
image

Reference the latest non-preview Azure SDK DeviceClient within the shared project.
You should not use any of the workarounds presented here as they are not applicable to the new SDK versions.

A Debug build should work for Android.
Release builds for Android are still blocked by multiple issues within the Xamarin platform. Please use https://github.com/azure/azure-iot-sdk-csharp/projects/1 to track these issues.

If this doesn't work, please create a new issue with the details.

@coltonf93
Copy link

I followed your recommendation, and it leads to this exact issue. I'll just follow up there.

@CIPop
Copy link
Member

CIPop commented Mar 1, 2018

Thanks @coltonf93 ! Let's continue in #373.
I'm currently working on adding netstandard2.0 and removing the UAP builds to simplify the investigation and pick up more dependencies not available in netstandard1.3. Hopefully that will solve some of the Xamarin and UWP issues caused by some of the dependencies.

@MujasSam
Copy link

MujasSam commented Mar 19, 2018

@CIPop

I am facing the same issue. Any solution for this. (Microsoft.Azure.Devices.Client.PCL)

Severity Code Description Project File Line Suppression State
Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Azure.Devices.Shared.PCL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Microsoft.Azure.Devices.Shared.PCL.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) BlueBox.Android C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1413

@CIPop
Copy link
Member

CIPop commented Mar 19, 2018

@MujasSam We don't support the PCL binary anymore.
Please try with 1.7.0 which added netstandard2.0 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

8 participants