Akash Kava
Akash Kava

Reputation: 39956

How to identify Processor Architecture in Xamarin.Android?

Lets say mostly all android processors are of type ARM but for testing, emulators are mostly of type x86. I native library that only runs on ARM and I just want to put dummy code for x86 in order to create Unit tests. I know simple try/catch will suffice, but problem is I wan to create interface with dummy code for unit tests.

I have tried,

        System.Reflection.PortableExecutableKinds peKind;
        System.Reflection.ImageFileMachine machine;
        typeof(object).Module.GetPEKind(out peKind, out machine);

And various answers I found for .net, but while in Android, I get x86 always, though I am running app on device, it does not give me correct answer.

  type(object).Assembly.GetName().ProcessorArchitecture 

Always returns x86.

Upvotes: 1

Views: 1066

Answers (1)

Plac3Hold3r
Plac3Hold3r

Reputation: 5192

You can use Android.OS.Build Class to help you confirm if the device is ARM or Intel x86 (Intel) armeabi-v7a or x86 etc.

IList<string> abis = Android.OS.Build.SupportedAbis;

Alternatively

You can use Java.Lang.JavaSystem.GetProperty Method to get the OS architecture, armv71 and i686 etc.

string osArchitecture = Java.Lang.JavaSystem.GetProperty("os.arch");

Upvotes: 4

Related Questions