No reference to Xamarin.Android.Support libraries in VS 2019

Rajesh M 21 Reputation points
2020-11-23T10:01:06.163+00:00

Hi,

I opened a solution of Xamarin forms created in VS 2017 in Visual Studio Community Edition 2019.

I noticed that the references to Xamarin.Android.Support libraries are not added automatically in Nuget when the solution is created for the first time.

When using the namespace in the Forms project

using Android.Graphics;
using Java.IO;

for saving image files in Android phones this shows a complication error "The type or namespace name 'Android' could not be found (are you missing a using directive or an assembly reference?)"

What is the reason for this error in a .Net Standard 2.1 project for Xamarin forms.

Kindly assist.

Thanks,

Rajesh.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nicole Lu-MSFT 96 Reputation points
    2020-11-26T08:18:12.017+00:00

    Checked the project, the ISignature.cs is in the Shared Project, actually we can't use Android libraries in the Shared Project, you might just put in the wrong place, it should go to the Hello_Xamarin.Android project.

    Or, if you do need to use Bitmap in Shared Project, try a different namespace like:

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Hello_Xamarin
    {
        public interface ISignature
        {
            bool SaveSignatureImage(Bitmap BitmapImage);
    
           // Android.Graphics.Drawables.BitmapDrawable LoadSignatureImage(byte[] strByte);
    
            void SavePictureToDisk(string filename, byte[] imageData);
    
            bool GetImageFromDB(string CitationNo,string Filename);
    
            byte[] ReadImageFile(string imageLocation);
    
            bool ReadImageFileExists(string StrPathLocation);
    
            bool DeleteImageFile(string strPathLocation);
    
        }
    }
    
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,386 Reputation points Microsoft Vendor
    2020-11-23T11:29:27.567+00:00

    First of all, update all of your nuget packages to the latest and change the minimun Android target to 6.0 or later, then rebuild your project.

    please open your project folder and close your VS, delete the bin and obj folders in all of your project(xxx, xxx.android, xxx.iOS), then reopen your project, rebuild your project, if is worked as normal.

    And check if you added Mono.Android.dll reference. please right click your xxx.Android project, select add reference
    41867-image.png

    Check the Mono.Android.dll reference like following screenshot.

    41884-image.png

    0 comments No comments

  2. Rajesh M 21 Reputation points
    2020-11-24T05:12:43.85+00:00

    Hi,

    I already have the Mono.Android.dll in my project when i created it in VS 2019 and updated the version of Xamarin.forms to 4.8.0.167.

    In my case, I do not want to migrate/update an existing Xamarin.Forms project that was created in VS 2017 because some libraries are no longer supported or some features are removed and also some nuget packages cannot be updated.

    What I did was the following steps.

    1. Created a new project in VS 2019. I selected the template (Mobile App - Xamarin Forms - A multi project template for building apps with iOS and Android with Xamarin and Xamarin Forms.)
    2. Created the forms from scratch and adding the nuget packages one by one when needed. Not adding the existing (.xaml and .cs) files.
    3. Copied the inline XAML and c# code behind in both the xaml and cs files.
    4. Added the necessary files in both the Forms and Android project required for database handling, screen rendering (custom renderers etc for the controls and forms)
    5. Adding each form one by one till all the compilation errors are fixed.

    The only compilation error seen is "The type or namespace name 'Android' could not be found (are you missing a using directive or an assembly reference?)"

    Please refer to these links to understand it clearly.

    https://stackoverflow.com/questions/54591881/xamarin-forms-platform-android-does-not-exist-after-xamarin-update-from-2-5-to-3

    https://forums.xamarin.com/discussion/150321/the-type-or-namespace-name-android-does-not-exist-in-the-namespace-xamarin-forms-platform

    My question is how can we add this namespace Xamarin.Forms.Platform.Android to a Xamarin.Forms 4.8.0.167 version so that the existing code works.

    private Stream GetImageStream(Android.Graphics.ImageFormatType imgFormat)
    
    
    bool SaveSignatureImage(Android.Graphics.Bitmap BitmapImage);
    

    Hope that I have explained it clearly what is missing in the latest version of Xamarin.Forms.

    The above mentioned 2 threads talk about reverting to an earlier version of Xamarin.Forms but we are already in 4.8.0.167 now and reverting back to an earlier version is out of the question.

    Thanks,

    Rajesh.


  3. Rajesh M 21 Reputation points
    2020-11-26T16:27:33.247+00:00

    Thank you. I am clear now. I went through some samples related to dependency injection and still i wonder how did that code work fro me earlier in VS 2017.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.