Subscribed unsubscribe Subscribe Subscribe

clock-up-blog (en)

tech memo

Xamarin.Android error such as "$(_DeviceSdkVersion)" that evaluates to "" instead of a number

Xamarin Android

(If you prefer Japanese than English, you can see Japanese article.)

The environment in this situation

  • Windows 10 Home Edition
  • Visual Studio Enterprise 2015 Version 14.0.25123.00 Update 2
  • Xamarin 4.1.0.530 (2e39740)
  • Xamarin.Android 6.1.0.71 (4e27558)
  • Genymotion Version 2.7.2 Revision 20160613-d7856fb

Error details

When I tried to launch a Xamarin application from Visual Studio, I saw an error that contains "$(_DeviceSdkVersion)" message. The details are as follows.

1>------ Build started: Project: App11, Configuration: Debug Any CPU ------
...
...
3>C:\android-sdk-windows\build-tools\23.0.3\zipalign.exe 4 "c:\Projects\App11\App11\App11.Droid\bin\Debug\App11.Droid-Signed-Unaligned.apk" "bin\Debug\\App11.Droid-Signed.apk" 
3>C:\android-sdk-windows\platform-tools\adb.exe -s 192.168.44.101:5555  shell getprop ro.build.version.sdk 
3>"adb.exe" exited with code 1.
3>A numeric comparison was attempted on "$(_DeviceSdkVersion)" that evaluates to "" instead of a number, in condition "$(_DeviceSdkVersion) >= 21".
3>Build FAILED.
3>
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========

Seeking the cause of the problem

First, I tryied to find some tips by googling "_DeviceSdkVersion" keyword and I failed. Then I think this keyword would be only a private symbol name in Xamarin or other engine.

We should look not at "_DeviceSdkVersion" line but at the previous line "adb.exe exited with code 1."
This error tells us that adb command had failed by something bad. We can find the adb command line string above the line "adb.exe exited with code 1."


In this case, the adb command line is as follows. (It depends on each environment)

C:\android-sdk-windows\platform-tools\adb.exe -s 192.168.44.101:5555  shell getprop ro.build.version.sdk


I tried to run this command in command prompt manually. The result was as follows.

> C:\android-sdk-windows\platform-tools\adb.exe -s 192.168.44.101:5555  shell getprop ro.build.version.sdk
adb server version (32) doesn't match this client (36); killing...
* daemon started successfully *
error: device '192.168.44.101:5555' not found


This error tells me that there is adb protocol error.
In other words, there are different version of adb which are launched.
It's the actual cause of the problem I wanted to know.

One of the actual causes: Genymotion

The solution is simple. We must not use different version of adb. That's all.

Why do I or you use different version of adb???

One of the causes is Genymotion.
Genymotion includes adb in order to run itself without Android SDK.
f:id:kobake:20160626204431p:plain:w500
By default, Genymotion uses this adb.

Use same adb between Xamarin.Android and Genymotion

First, check your Android SDK path that Xamarin refers.
Visual Studio: [Tools] - [Options...] - [Xamarin] - [Android Settings] - [Android SDK Location]
f:id:kobake:20160626205416p:plain:w500
f:id:kobake:20160626205708p:plain:w500


Next, set the Android SDK path in Genymotion settings.
f:id:kobake:20160621105258p:plain:w500
f:id:kobake:20160621105306p:plain:w500


My problem was solved by this way. Good luck.

Last, dear English natives

I'm Japanese and my English sentences may often include bad expressions.
Please feel free to point out any mistakes in my articles if you notice.