The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Xamarin Virtual Machine Configuration"
(Created page with "I (Daniel Robbins) sometimes use Xamarin for mobile development. This page serves as documentation on how to configure an Android Virtual Machine from the command-line, as thi...") |
|||
Line 72: | Line 72: | ||
=== The ABI Mess === | === The ABI Mess === | ||
Unfortunately for me, some of the XML (shipped with the Android SDK?) was invalid which prevented me from creating an x86 image. The symptom was that only a 'default' ABI was | Unfortunately for me, some of the XML (shipped with the Android SDK?) was invalid which prevented me from creating an x86 image. The symptom was that only a 'default' ABI was defined in the XML, but this 'default' ABI was not part of the system-images, creating a catch-22. To fix this, I first got my avdmanager command ready, and then I ran it with {{c|-b default}} and {{c|-b x86}}, and saw a bunch of Java tracebacks saying things like {{c|The value 'default' (or x86) of element 'abi' is not valid.}}. But I did notice some debug output going to the console that said {{c|Parsing }} followed by a long list of XML files. (The list actually looks like {{c|Parsing foo.xmlParsing bar.xml}}, etc., all stuck together. '''BUT, if you find the proper XML file that corresponds to the system image you are trying to install, you can edit it, like so:'' | ||
{{console|body= | {{console|body= |
Revision as of 23:29, October 3, 2017
I (Daniel Robbins) sometimes use Xamarin for mobile development. This page serves as documentation on how to configure an Android Virtual Machine from the command-line, as this documentation is not widely available. This works for me as of October 3rd, 2017, but may change in the future as the Android SDK is updated.
I have been using the Alpha channel for Xamarin/Visual Studio releases and have found that everything now wants you to target API Level 25. However, I didn't have any API Level 25 virtual machines available, and the virtual machine creator GUI for Xamarin is currently being overhauled so I had no way to create them except via the command-line. Here's how I did it.
First, in Visual Studio for Mac 7.2 Preview, I went to Tools -> SDK Command Prompt. This opened a Terminal window in the Android SDK directory. This actually isn't the right directory to be in. Change to:
user $ cd tools/bin
You can now run avdmanager
as follows:
user $ ./avdmanager
The use of AVDManager is non-intuitive and has changed a lot over various Android releases so the next steps can be tricky. Manual edits of XML files may be required! But the command we will eventually use, and after some tweaking should work, is this:
user $ ./avdmanager create avd -f -n drobbins_vm_x86 -k 'system-images;android-25;google-apis_playstore;x86' -b x86 -d 31
This command will likely not work just yet and may need customization for your environment. But I'm including it above because maybe you're lucky and it will work as-is, and if not, we will go through the steps below to make it work :)
The various options used above are as follows:
option | meaning |
---|---|
-f | Replace existing AVD if it already exists |
-n drobbins_vm_x86 | Name the AVD image drobbins_vm_x86 |
-d 31 | Use Device ID 31 |
-k 'system-images;android-25;google_apis_playstore;x86' | Use the specified 'Package path' |
-b x86 | Specify ABI to use -- note that some hackery may be required for this 'x86' option to work. |
Getting AVDManager to Actually Work
It's likely that the command will not work as-is on your system. We'll go through all the trickery used to get avdmanager to work for you. First, to see all the possible Devices you can emulate, use the following command:
root # ./avdmanager list device
You will see a lot of debug output followed by a list of devices, identified by integer ID. You should pick the one you want to use.
Next, you'll need to pick a valid "Package Path". To see all available ones, type:
root # ./avdmanager -n bogus -k nonexisting ... java tracebacks ... Error: Package path is not valid. Valid system image paths are:ository... system-images;android-21;google_apis;x86 system-images;android-25;google_apis;x86_64 system-images;android-25;google_apis_playstore;x86 system-images;android-25;android-tv;x86 system-images;android-23;google_apis;x86 system-images;android-23;google_apis;armeabi-v7a system-images;android-21;default;x86_64 system-images;android-25;google_apis;x86 system-images;android-25;google_apis;armeabi-v7a system-images;android-21;android-tv;armeabi-v7a system-images;android-21;google_apis;armeabi-v7a system-images;android-21;android-tv;x86 system-images;android-21;default;x86 system-images;android-25;google_apis;arm64-v8a system-images;android-21;google_apis;x86_64 system-images;android-21;default;armeabi-v7a null
Yes, exactly as typed, avdmanager will output a lot of debug output and then show you a list of system images beginning with "system-images;". There you go -- there's your list of available system images :) Ones with "playstore" in them are especially handy, as it allows you to launch the Google Play Store and update a bunch of stuff.
The ABI Mess
Unfortunately for me, some of the XML (shipped with the Android SDK?) was invalid which prevented me from creating an x86 image. The symptom was that only a 'default' ABI was defined in the XML, but this 'default' ABI was not part of the system-images, creating a catch-22. To fix this, I first got my avdmanager command ready, and then I ran it with -b default
and -b x86
, and saw a bunch of Java tracebacks saying things like The value 'default' (or x86) of element 'abi' is not valid.
. But I did notice some debug output going to the console that said Parsing
followed by a long list of XML files. (The list actually looks like Parsing foo.xmlParsing bar.xml
, etc., all stuck together. 'BUT, if you find the proper XML file that corresponds to the system image you are trying to install, you can edit it, like so:
user $ vim /Users/drobbins/Library/Developer/Xamarin/android-sdk-macosx/system-images/android-25/google_apis_playstore/x86/package.xml
And then, search for the text <abi>
, and you will likely see <abi>default</abi>
. You have found the bug in the XML. Make sure you are modifying the "x86 Atom System Image" part of the XML and change default
to x86
, save, and then run the command with the -b x86
option and it should work!
You're Not Done Yet
At this point, the avdmanager
command specified initially (maybe with some tweaks made by you) should complete successfully. You will find the created AVD image in ~/.android/avd:
user $ ls ~/.android/avd Android_ARMv7a.avd Android_Accelerated_x86.avd drobbins_vm_x86.avd Android_ARMv7a.ini Android_Accelerated_x86.ini drobbins_vm_x86.ini
it will also show up immediately in the Visual Studio for Mac VM drop-down. But you're not done yet! If you just start your VM from Visual Studio, the resolution will be too small. So you will need to start your VM from the command-line, as follows:
user $ cd ../../emulator (or just cd emulator if from a new SDK terminal) user $ ./emulator -avd drobbins_vm_x86 -accel auto -skin 1080x1920
The key above is the -skin
option. This used to be baked into the AVD image but now needs to be specified on the emulator command-line. You can pick any XxY resolution you'd like to use or specify a standard (imo confusing) ?VGA string. There you go! Visual Studio will now 'hook in' to the running emulator and use it for debugging and launching your apps.
Quick Tip -- to update Google Play Services, use a play_services image, go to the Play Store and update all the apps in your image, and then launch Chrome -- this should immediately prompt you to update Google Play Services to the latest version. Proceed, and now you have Google Play Services in your VM, all updated and ready to go! :)