{"id":43,"date":"2011-09-25T05:23:13","date_gmt":"2011-09-25T10:23:13","guid":{"rendered":"https:\/\/www.falatic.com\/?p=43"},"modified":"2011-09-25T23:15:57","modified_gmt":"2011-09-26T04:15:57","slug":"building-the-android-emulator-for-windows","status":"publish","type":"post","link":"https:\/\/www.falatic.com\/index.php\/43\/building-the-android-emulator-for-windows","title":{"rendered":"Building the Android emulator for Windows"},"content":{"rendered":"<p>Today I&#8217;ve been investigating an argument parsing bug in Android&#8217;s emulator on Windows (a bug that <em>may<\/em> affect all platforms). The version I&#8217;m seeing the bug was in the Android SDK r12 version of the emulator [Yep, r13&#8217;s out &#8211; see note below.]<\/p>\n<p>As part of this, I needed to rebuild the emulator. It was not as straightforward as I&#8217;d hoped so I decided to write up a little howto here in case others decide to try rebuilding it on Windows. It&#8217;s really not hard at all once you install a few prerequisites! [Note: You&#8217;ll also find info here about building this via Linux.]<\/p>\n<p><!--more--><\/p>\n<p><em>[<strong>Edit:<\/strong> As of this post the HEAD is 6e2f62&#8230;599648 <em>for platform_external_qemu<\/em>. While this post-r12 work WILL build in Windows with these procedures, I just found out that the older r12 code (tagged as <\/em>android-sdk-tools_r12<em>) will NOT build in Windows! You&#8217;d need to do r12-based builds in Linux with MinGW installed. It&#8217;s interesting to see just how much was fixed since SDK r12&#8230; including, evidently, the very issue I discovered today! <del>Hopefully SDK r13 gets released soon.<\/del> Oh look, it&#8217;s out! Interestingly, unlike r12 there is no corresponding r13 tag for this one&#8230; which is part of why I didn&#8217;t notice it in the Git log (I saw the tools_r13 branch though there are lots of changes after that).]<\/em><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Note:<\/strong><\/span> If you choose other install dirs, adjust the values below accordingly!<\/p>\n<p><strong>Install Python 2.6 or 2.7:<\/strong><\/p>\n<ul>\n<li>I used ActivePython 2.7.2.5 x64 (x86 should be equally good)<\/li>\n<li>Download: <a href=\"http:\/\/www.activestate.com\/activepython\/downloads\" target=\"_blank\">http:\/\/www.activestate.com\/activepython\/downloads<\/a><\/li>\n<li>Default bin dir for Python = C:\\Python27<\/li>\n<\/ul>\n<p><strong>Install MinGW (it includes msys now):<\/strong><\/p>\n<ul>\n<li>Information: <a href=\"http:\/\/www.mingw.org\/wiki\/MinGW\" target=\"_blank\">http:\/\/www.mingw.org\/wiki\/MinGW<\/a><\/li>\n<li>Download: <a href=\"http:\/\/sourceforge.net\/projects\/mingw\/\" target=\"_blank\">http:\/\/sourceforge.net\/projects\/mingw\/<\/a><\/li>\n<li>Default bin dir for MinGW = C:\\MinGW\\bin<\/li>\n<li>Default bin dir for msys = C:\\MinGW\\msys\\1.0\\bin<\/li>\n<\/ul>\n<p><strong>Install Git:<\/strong> I use <em>msysgit<\/em> because I also use (and happily recommend!) <a href=\"http:\/\/code.google.com\/p\/tortoisegit\/\" target=\"_blank\">TortoiseGit 1.7.3.0<\/a>:<\/p>\n<ul>\n<li>Information: <a href=\"http:\/\/code.google.com\/p\/msysgit\/\" target=\"_blank\">http:\/\/code.google.com\/p\/msysgit\/<\/a><\/li>\n<li>Download: <a href=\"http:\/\/code.google.com\/p\/msysgit\/downloads\/list\" target=\"_blank\">http:\/\/code.google.com\/p\/msysgit\/downloads\/list<\/a><\/li>\n<ul>\n<li>Git-1.7.4-preview20110204.exe works, 1.7.6 may as well<\/li>\n<\/ul>\n<li>Default bin dir for Git = C:\\Git\\bin<\/li>\n<\/ul>\n<p><strong>Open a command prompt and ensure your path is set correctly (omit duplicates as necessary, but ensure such entries weren&#8217;t eclipsed by other things you&#8217;ve installed, like Cygwin):<\/strong><\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\nset PATH=C:\\MinGW\\msys\\1.0\\bin;C:\\MinGW\\bin;C:\\Python27;C:\\Git\\bin;%PATH%\r\n<\/pre>\n<p><strong>Clone the repository! (Because of the kernel.org outage we&#8217;re using <a href=\"https:\/\/github.com\/android\/platform_external_qemu\" target=\"_blank\">the github mirror<\/a>):<\/strong><\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\nmkdir H:\\temp_repo\r\ncd \/D H:\\temp_repo\r\ngit clone https:\/\/github.com\/android\/platform_external_qemu.git\r\n<\/pre>\n<p><strong>Start bash in the folder with the emulator sources (from this point on commands run at the bash prompt):<\/strong><\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\ncd \/D H:\\temp_repo\\platform_external_qemu\r\nbash\r\n<\/pre>\n<p><strong>Setting PS1 makes the prompt more verbose than the default <em>&#8220;bash-3.1$&#8221;<\/em> prompt:<\/strong><\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\nPS1='\\&#x5B;\\e]0;\\w\\a\\]\\n\\&#x5B;\\e&#x5B;36m\\]\\u@\\h \\&#x5B;\\e&#x5B;32m\\]\\w\\&#x5B;\\e&#x5B;0m\\]\\n\\$ '\r\n<\/pre>\n<p><strong>There&#8217;s a small problem if you want the version string in the emulator to be fully formed:<\/strong><\/p>\n<ul>\n<li>In <em>Makefile.common<\/em>, ANDROID_BUILD_ID get set <em>only<\/em> if <em>BUILD_STANDALONE_EMULATOR == &#8220;&#8221;<\/em> &#8211; never if <em>BUILD_STANDALONE_EMULATOR == &#8216;true&#8217;<\/em> (which is what we&#8217;re building here). Here&#8217;s a fix for that, at least for the 13.x line of the emulator (line numbers may vary!):<\/li>\n<ul>\n<li>Broken: line 66: <em>ifeq ($(BUILD_STANDALONE_EMULATOR),)<\/em><\/li>\n<li>Patched: line 66: <em>ifneq ($(BUILD_STANDALONE_EMULATOR),false)<\/em><\/li>\n<\/ul>\n<li><strong>If in doubt, ignore this tweak<\/strong>! Understand your -version output will not be very informative. That can quickly get annoying if you are building multiple versions&#8230;<\/li>\n<\/ul>\n<p><strong>Set some variables and run the build:<\/strong><\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\n# Customize this as desired\r\nexport ANDROID_SDK_TOOLS_REVISION=42\r\nexport ANDROID_BUILD_ID=custom\r\n\r\n# Inserts your username and the timestamp in the build name\r\nexport MY_BUILD_TIMESTAMP=`date +%Y%m%d_%H%M%S`\r\nexport BUILD_ID=${USERNAME}\r\nexport BUILD_NUMBER=${MY_BUILD_TIMESTAMP}\r\n\r\n# Executes the build\r\n.\/android-rebuild.sh --static 2&gt;&amp;1 | \\\r\n   tee build_${USERNAME}-${MY_BUILD_TIMESTAMP}.log\r\n<\/pre>\n<p><strong>Check the version string of the emulator you just built:<\/strong><\/p>\n<ul>\n<li>Run this:<\/li>\n<ul>\n<li><em>objs\/emulator.exe -version<\/em><\/li>\n<\/ul>\n<li>See output like this:<\/li>\n<ul>\n<li>Android emulator version 13.0 (build_id Marty-20110925_042430)<\/li>\n<\/ul>\n<\/ul>\n<p><strong>Using the newly-built emulator:<\/strong><\/p>\n<ul>\n<li><strong><\/strong>The objects of interest in objs are:<em><\/em><\/li>\n<ul>\n<li><em>emulator.exe<\/em>, <em>emulator-arm.exe, <\/em><em>emulator-x86.exe<\/em><\/li>\n<\/ul>\n<li>You may need to copy them to <em>android-sdk-windows\/tools<\/em> folder to use them (<strong>back up the originals first before replacing them!<\/strong>)<\/li>\n<\/ul>\n<p><strong>Notes on building via Linux:<\/strong><\/p>\n<p style=\"padding-left: 30px;\">As mentioned above, I managed to get all this to work on Windows just fine&#8230; technically, no source edits are necessary at this point to make it work. However, when I switched to the <em>android-sdk-tools_r12<\/em> tag it failed with:<em><\/em><\/p>\n<p style=\"padding-left: 60px;\"><em>cc1: error: unrecognized command line option &#8220;-mno-cygwin&#8221;<\/em><\/p>\n<p style=\"padding-left: 30px;\">Turns out this is a <a href=\"http:\/\/code.google.com\/p\/android\/issues\/detail?id=18949\" target=\"_blank\">known issue<\/a>&#8230; and in fact it was fixed in a later commit to the emulator code base! (I saw it as I was browsing the overall delta between r12 and the latest.) But, even with that fixed I couldn&#8217;t get r12 to build within Windows, so I went to Linux. I was already configured to build CyanogenMod, so everything was in place except MinGW. I installed <em>mingw32<\/em>, made that one fix to <em>android-rebuild.sh<\/em> and ran:<\/p>\n<p style=\"padding-left: 60px;\">.\/android-rebuild.sh &#8211;static &#8211;mingw<\/p>\n<p style=\"padding-left: 30px;\">And it worked just fine!<\/p>\n<p style=\"padding-left: 30px;\">(<strong>Note:<\/strong> the &#8211;mingw option is NOT used when building this within Windows&#8230; it&#8217;s a little confusing because of course we&#8217;re using MinGW <em>in<\/em> Windows, but that&#8217;s how it&#8217;s coded in their build system.)<\/p>\n<!-- wpsso rrssb get buttons: buttons on archive option not enabled -->\n","protected":false},"excerpt":{"rendered":"<p>Today I&#8217;ve been investigating an argument parsing bug in Android&#8217;s emulator on Windows (a bug that may affect all platforms). The version I&#8217;m seeing the bug was in the Android <a href=\"https:\/\/www.falatic.com\/index.php\/43\/building-the-android-emulator-for-windows\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[1],"tags":[116,76,31,74,78,77,75,117],"class_list":["entry","author-marty","has-more-link","post-43","post","type-post","status-publish","format-standard","category-uncategorized","tag-android","tag-build","tag-cygwin","tag-emulator","tag-git","tag-mingw","tag-qemu","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":0,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}