Essentials: The type or namespace name 'Platform' does not exist in the namespace 'Xamarin.Essentials'

Created on 17 Jan 2019  路  14Comments  路  Source: xamarin/Essentials

Description

The type or namespace name 'Platform' does not exist in the namespace 'Xamarin.Essentials'

Steps to Reproduce

  1. Added version 1.0.1 to Android, IOS, and shared project through NuGet package manager.
  2. Navigating to MainActivity.cs in the Android project, and selecting the OnCreate method.
  3. Typing Xamarin.Essentials. (and the intellisense completes with all but Platform method)

I麓m using some Essentials on iOS and works fine but adding to Android is not possible because I can't initialize.

Screenshots

image

All 14 comments

Ah, it may be because your target framework is too low. The target version needs to be 8.1, but minimum can be as low as 4.4:

Xamarin.Essentials supports a minimum Android version of 4.4, corresponding to API level 19, but the target Android version for compiling must be 8.1, corresponding to API level 27.

https://docs.microsoft.com/en-us/xamarin/essentials/get-started?context=xamarin%2Fxamarin-forms&tabs=windows%2Candroid

Ah, it may be because your target framework is too low. The target version needs to be 8.1, but minimum can be as low as 4.4:

Xamarin.Essentials supports a minimum Android version of 4.4, corresponding to API level 19, but the target Android version for compiling must be 8.1, corresponding to API level 27.

https://docs.microsoft.com/en-us/xamarin/essentials/get-started?context=xamarin%2Fxamarin-forms&tabs=windows%2Candroid

Ok, let me try that, I麓m sure 4.4 is the minimum, but unsure if 8 or 8.1 is, by the way, this is my .csproj file

I have Android version set to 8.0 but anyway updated to:
image
That doesn't work.

My csproj file:

 <ItemGroup>
    <PackageReference Include="AiForms.Layouts">
      <Version>1.0.4</Version>
    </PackageReference>
    <PackageReference Include="linqtotwitter">
      <Version>5.0.0-beta2</Version>
    </PackageReference>
    <PackageReference Include="Plugin.Share">
      <Version>7.1.1</Version>
    </PackageReference>
    <PackageReference Include="Xam.Plugins.Forms.ImageCircle">
      <Version>2.0.2</Version>
    </PackageReference>
    <PackageReference Include="Xam.Plugins.XamJam.Screen">
      <Version>1.0.7</Version>
    </PackageReference>
    <PackageReference Include="Xamarians.MediaPlayer">
      <Version>1.1.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Essentials">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
    <PackageReference Include="Xamarin.Android.Support.Design" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v4" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="25.4.0.2" />
  </ItemGroup>

Accordly to https://github.com/xamarin/Essentials/issues/262#issuecomment-390262996

I have the 25.4.0.2 support libraries. :(

I found this commit from pull #590 in Nov 2, 2018 from mattleibow

[Platform] Remove the Platform for .net standard since it does nothing
https://github.com/xamarin/Essentials/commit/d72bb6d31fa42ea5c67ba32c9628aa7e2e225e06

Maybe this is the problem ?

If this line have that problem:

Xamarin.Essentials.Platform.Init(this, savedInstanceState);

Wich one need to be used to Initialize in Android ?

What is in you AndroidManifest.xml and what is the value of <TargetFrameworkVersion> in your .csproj?

And, what I would also do after updating is to close VS and delete the obj/bin folders.

I am looking at your old version of Xamarin.Forms and I am thinking that it might be causing conflicts with the support libraries... See what happens after updating all the Xamarin.Android.Support versions to be 27.0.2.1 - it probably will go better if you do it in the csproj. And while you are in there, add entries for Xamarin.Android.Support.Core.Utils and Xamarin.Android.Support.CustomTabs

<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="27.0.2.1" />

As I look at this, I am sure that NuGet is giving you the wrong stuff as a result of the support version conflicts. Just copy that chunk over your existing support entries and see if you get Platform.

AndroidManifest.xml (I took the one in properties folder):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ILCE.apps.app" android:installLocation="auto" android:versionCode="222" android:versionName="2.2.2">
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="27" />
    <application android:label="ILCE Player">
    </application>
</manifest>

<TargetFrameworkVersion> in .csproj:
<TargetFrameworkVersion>v7.0</TargetFrameworkVersion>

Thanks man, I really appreciate, I gonna try that and return here the let you know the results. Since is an "old" project, some features can be a real pain to upgrade but I think I can get a run in another more VS updated PC.

I麓m not that experienced in VS but when you say: " it probably will go better if you do it in the csproj." you mean I only need to include that lines into file ? or I need to do something after that ? (like rerun nugget)

You should just be able to edit the file and then open it. VS will run a restore automatically.

  1. Delete all the < PackageReference> lines that have the Include="Xamarin.Android.Support...."
  2. Insert the ones from the comment above. https://github.com/xamarin/Essentials/issues/683#issuecomment-455412956 / or in the chunk below
  3. Set the number in the <TargetFrameworkVersion> element to be 8.1

To do this, just right click the project in the solution explorer and select "Unload". Then, right click it again and select "Edit .csproj". You can then just delete the lines, and add the new ones (make sure you just delete the Xamarin.Android.Support lines as you want the rest):

<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="27.0.2.1" />

All of this should move you to the Android 8.1 / API 27 versions, and things should start working. All of this can be done in the IDE, but you will have to deal with the packages being fussy about installing things.

Okidoki, gonna download the needed files (third world internet connection) and make the changes. I will update as soon as the changes are done.

It works !!!!
Now I gonna to analyze step by step the changes to figure the exact needed update/upgrade and learning for this experience.
Thanks a lot.

Great! It probably was the value in the <TargetFrameworkVersion> being to low. But, let us know what you find so that we can make it better - or write some docs. And, if anyone else finds this issue, they can know how to fix it.

I麓ll do it, thanks again.

After reviewing, looks like 2 changes where needed:

TargetFrameworkVersion must be 8.1
All Xamarin.Android.Support lines must be 27.0.2.1

So it works with old Xamarin Forms too.

Sweet! That is great news! We designed the API to not require any platform framework. Glad to know it work for you!

Thanks @mattleibow for the snippet

<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="27.0.2.1" />

I also had to add the following one to get all works
<PackageReference Include="Xamarin.Android.Support.Exif" Version="27.0.2.1" />

Was this page helpful?
0 / 5 - 0 ratings