ebandersen
ebandersen

Reputation: 2352

Xamarin.UITests Android Device Not Detected or Not Working

I can't run Xamarin.UITests on any Android simulator/emulator. Any suggestions? I get the following errors when I try:

Google Emulator:

SetUp: System.Exception: Unable to run on a physical device without activation. The full version is available for Xamarin Test Cloud customers, for more information contact [email protected] If you are already a Xamarin Test Cloud customer, you can provide your api in one of the following ways: * Adding it ConfigureApp using the ApiKey method * Setting the XTC_API_KEY environment variable * Adding the following attribute to your Properties/AssemblyInfo.cs file: [assembly: Xamarin.UITest.TestCloudApiKey(YOUR_API_KEY)] * Place an xtc_api-key file containing your api key in an upstream directory from the test assembly

Xamarin Android Player:

SetUp: System.Exception: No devices connected

GenyMotion:

SetUp : System.Exception : Failed to execute: /users/erikandersen/Library/Developer/Xamarin/android-sdk-macosx/platform-tools/adb devices - exit code: 1 cannot bind 'tcp:5037' ADB server didn't ACK * failed to start daemon * error: adb server is out of date. Killing…

After updated GenyMotion to 2.3.1, I now get the following error:

SetUp: System.Exception: App Installation failed with output: 12050 KB/s (11199602 bytes in 0.907s) pkg: /data/local/tmp/final-xxxxxx.apk Failure [INSTALL_FAILED_CPU_ABI_INCOMPATIBLE]

NUnit Code

    AndroidApp _app;
    public string PathToAPK { get; set; }

    [TestFixtureSetUp]
    public void BeforeAll ()
    {
        var path = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
        var info = new FileInfo(path);
        var directory = info.Directory.Parent.Parent.Parent.FullName;

        PathToAPK = Path.Combine(directory, "Android", "bin", "Debug", "Demo.Android.apk");
    }

    [SetUp]
    public void BeforeEach ()
    {
        _app = ConfigureApp.Android.ApkFile (PathToAPK).StartApp ();
    }

    [Test]
    public void TestInvalidEmail ()
    {
        _app.EnterText (c => c.Class ("UITextField"), "");
    }

TestInvalidEmail() is never called because NUnit fails on

_app = ConfigureApp.Android.ApkFile (PathToAPK).StartApp ();

Background:

I'm using Xamarin.UITests for an iOS/Android application I'm developing and we're having issues with the Android side of things. iOS works fine. I've written each test twice, once in C# and once in Ruby using calabash, in order to isolate the issue. Calabash works fine, but any C# NUnit Test Project fails to connect to any emulator I try launching.

What I've tried:

  1. Making sure an emulator is already running before I run the tests
  2. Making sure only 1 emulator is running
  3. Restarting the adb server
  4. Trying multiple types of emulators (i.e. Xamarin Android Player, Gennymotion, and the Google Emulator)

Upvotes: 3

Views: 5250

Answers (2)

Alex Botelho
Alex Botelho

Reputation: 11

I had the same problem and fixed by setting the ApiKey when setting ConfigureApp.

    [SetUp]
    public void SetUp()
    {
            _app = ConfigureApp.iOS.AppBundle(PathToIPA).ApiKey("YOUR_API_KEY_HERE").StartApp();
    }

As in here. Just put your ApiKey there.

Note: I didn't have this problem with Xamarin Android Player. I didn't have this problem with AVD running an Android 5.0 emulator. I only had this problem with AVD running an Android 4.0.3 emulator.

Upvotes: 0

ebandersen
ebandersen

Reputation: 2352

So, after several hours of working on this, this fixed it:

  1. Upgrade GennyMotion to 2.3.1
  2. Delete my old GenyMotion Simulator (Nexus 4) and create a new one
  3. Add support for all ABIs in my Android Build settings

Android Project > Options > Android Build > Advanced Tab > Supported ABIs > Check "armeabi, armeabi-v7a, x86" > OK

  1. Generate a new .apk file via the terminal (while inside the Android project directory)

/usr/bin/xbuild /t:Package /p:Configuration=Release .csproj

  1. Resigned the .apk via calabash-android

calabash-android resign ./bin/Release/.apk

  1. In Xamarin Studio, set my Startup Project as the my UITest project
  2. Launch GenyMotion simulator
  3. Ran the tests under the Debug configuration with only the GenyMotion simulator active

And it worked! I still can't run UI tests with the Google Emulator or the Xamarin Android Player. Funny thing is, I also can't debug my Android project using GenyMotion. It's only good for UITests. SO here's my current setup:

Xamarin Android Player - Normal debug

GenyMotion - UITests

Upvotes: 2

Related Questions