11

Have been having a little issue for the last couple of days now where I will create a new Xamarin Forms project on Visual Studio 2017 and add a Xamarin.UITest Cross-Platform Test Project for unit testing I recieve a series of NU1201 Errors when I reference the .Android App in the UITest Project.

Here is the exact error i get:

Error NU1201    Project App1.Android is not compatible with net461 (.NETFramework,Version=v4.6.1) / win-x64. Project App1.Android supports: monoandroid81 (MonoAndroid,Version=v8.1)    

I have played around with the Android version numbers to see if the UITesting package doesnt support the latest android but no matter what version of android i target the problem remains the same.

Here is a screenshot of the project. enter image description here All the code is unchanged from the default project and runs in the simulator fine but only produces these errors when the Android app is referenced to the UITest project.

Ibo
  • 4,081
  • 6
  • 45
  • 65
Fakelzaman
  • 261
  • 2
  • 9

2 Answers2

15

Solved it after many more hours of testing and trialling. Instead of adding the Android project to the references, Within the AppInitializer I added another method to the StartApp() call like so:

public class AppInitializer
{
    public static IApp StartApp(Platform platform)
    {
        if (platform == Platform.Android)
        {
            return ConfigureApp.Android.InstalledApp("com.companyname.App1").StartApp();
        }

        return ConfigureApp.iOS.StartApp();
    }
}

Therefore once I had already run the app via the emulator for the first time and installed on the device, the UITest simply uses the installed APK on the emulator instead of the project.

Fakelzaman
  • 261
  • 2
  • 9
  • 1
    Thank you for sharing. @Fakelzaman, so in the end of the day you still kept your UITests DLL using .NET v4.6.1, correct? – Damian Jul 20 '18 at 22:20
  • 1
    Yes that version remained the same @Damian – Fakelzaman Jul 21 '18 at 02:05
  • 4
    Doesn't this cause problems when trying to run the test in AppCenter? – PaulVrugt Sep 10 '18 at 11:42
  • Calling by app name didn't work for me, the following code did. Don't forget the apk needs to be in the bin folder which requires a Deploy, not just a build. IApp app = ConfigureApp.Android.ApkFile("../../../AndroidProject/bin/Debug/android.apk").StartApp(); return app; – JimSTAT Dec 24 '20 at 19:10
0

For those who ran into error NU1201, you might have come to the right place. This may not apply to the question asked but I ran into error NU1201 the other day and the reason for that is the nuproj configuration file for our nuget project has target configuration wrong. It should have been

<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>

instead of

<TargetFramework>net462</TargetFramework>

because the project is not of "SDK-style."

References: https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-target-framework-and-target-platform?view=vs-2019

Bruce
  • 181
  • 4
  • 11