{"id":1577,"date":"2024-03-04T21:55:42","date_gmt":"2024-03-04T21:55:42","guid":{"rendered":"https:\/\/editjournal.redakt.eu\/faxmodem\/?p=1577"},"modified":"2024-05-13T09:12:40","modified_gmt":"2024-05-13T08:12:40","slug":"android-7-virtual-device-gotchas","status":"publish","type":"post","link":"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/experimental\/android-7-virtual-device-gotchas\/","title":{"rendered":"Android Studio Virtual Device: Installing and Gotchas, pre-Android 7"},"content":{"rendered":"<p>Android 7+ introduces <a href=\"https:\/\/httptoolkit.com\/blog\/frida-certificate-pinning\/\">certificate pinning<\/a> that makes it more difficult to debug the requests the device makes. This covers the pre-certificate-pinning Android versions.<\/p>\n<h2>Install<\/h2>\n<p>Download and install. Here's the archive with all available versions: <a href=\"https:\/\/developer.android.com\/studio\/archive\">https:\/\/developer.android.com\/studio\/archive<\/a>. I will be installing 2023.2.1.25.<\/p>\n<h2>First Launch; Choosing SDK<\/h2>\n<p>If Android Studio crashes every time you try to open it, check your available disk space. The unpacked app itself takes about 2,5-3 GB and then it needs quite a lot of space when you launch it, even if it claims otherwise. I got it to work only after I freed up about 15-20 GB. It may depend on the Android Studio version and the SDK you chose.<\/p>\n<p><strong>In case you want to choose your SDK version<\/strong>: when you launch Android Studio for the first time, you are greeted with Setup Wizard which suggests you install the latest SDK. Agree and let it be downloaded and installed. Then go to Android Studio Preferences -&gt; Languages and Frameworks -&gt; Android SDK. There you will see the list of all available SDKs. (If you skip installing the suggested SDK, all options will be grayed out. It seems you have to install the newest one first.)<\/p>\n<p>Basically, what you're choosing here is how recent Android APIs you will be working with. The newer SDKs are normally larger. Older SDKs are smaller, sometimes significantly.<\/p>\n<h2>Create an Android Virtual Device<\/h2>\n<p>When Android Studio is launched, you will be presented with the <em>Welcome to Android Studio<\/em> screen. Under <em>More Actions<\/em> click <em>Virtual Device Manager<\/em>. There you can create a new Android Virtual Device (AVD). This will be the actual emulated phone you will be working with.<\/p>\n<p>I selected Pixel (just the old Pixel) with the API 24 and Google Play enabled. Internally my AVD ID is &quot;Pixel_API_24&quot;.<\/p>\n<h2>MITMProxy<\/h2>\n<p><strong>Install<\/strong> on your computer by <a href=\"https:\/\/mitmproxy.org\/downloads\">downloading<\/a> the binaries.<\/p>\n<p><strong>Launch<\/strong> (on a Mac) by going to Terminal and running <code>\/Applications\/mitmproxy.app\/Contents\/MacOS\/mitmweb<\/code>. This starts MITM Proxy and opens the browser UI.<\/p>\n<p>Remember to <strong>install the MITM Proxy certificate<\/strong> on your AVD. If you don't, the HTTPs connections made on your device will fail. A good sign you forgot this step is you start MITM Proxy and all it's intercepting is:<\/p>\n<pre><code>http:\/\/connectivitycheck.gstatic.com\/generate_204   GET 204 0   39ms    \n\nhttp:\/\/www.google.com\/gen_204   GET 204 0   57ms    <\/code><\/pre>\n<p>The command line will be complaining as well:<\/p>\n<blockquote>\n<p>Client TLS handshake failed. The client does not trust the proxy's certificate for www.google.com (OpenSSL Error([('SSL routines', '', 'sslv3 alert certificate unknown')]))<\/p>\n<\/blockquote>\n<p>Add the certificate by transferring it to the device:<\/p>\n<ul>\n<li>go to <a href=\"http:\/\/mitm.it\">http:\/\/mitm.it<\/a> and download it from there (choose Android)<\/li>\n<li>drag and drop it from the host machine onto the emulator<\/li>\n<li>try <code>~\/Library\/Android\/sdk\/platform-tools\/adb push ~\/.mitmproxy\/mitmproxy-ca-cert.cer \/storage\/emulated\/0\/Download<\/code><\/li>\n<li>you can always either e-mail the file to yourself, or upload it to some URL and then download it using the built-in Androind browser<\/li>\n<\/ul>\n<p><strong>Gotcha<\/strong>: if you don't see the file in your Downloads folder, do not worry and waste hours trying to debug it; chances are the certificate is actually there. Try installing it first.<\/p>\n<p><strong>Install<\/strong> the certificate. If you download it from the browser, you will be prompted right away, otherwise go to Settings -&gt; Wi-Fi -&gt; (\u2026) -&gt; Advanced -&gt; Install Certificates, and browse and select the certificate file. When prompted for <em>Credential use<\/em>, choose <em>Wi-Fi<\/em>. You may have to install again for <em>VPN and apps<\/em> too. You may have to enable PIN on the device.<\/p>\n<p>Configure your Android Virtual Device to use MITM Proxy either <em>internally<\/em> on the actual AVD, or <em>externally<\/em> in the emulator settings.<\/p>\n<ul>\n<li><strong>Internally \u2013 on AVD itself<\/strong>.\n<ul>\n<li>Go to Wi-Fi settings and under Advanced options for the default &quot;<em>AndroidWifi<\/em>&quot; network, configure the proxy for <code>10.0.2.2<\/code> on port <code>8080<\/code>. We're using <code>10.0.2.2<\/code> to access the host machine from within the emulated device.<\/li>\n<li>If your AVD does not have Wi-Fi at all, go to Settings -&gt; Wireless &amp; networks -&gt; (More) -&gt; Cellular networks -&gt; Access Point Names -&gt; T-Mobile US -&gt; (Enter the same proxy settings as above) -&gt; (\u2026) -&gt; Save<\/li>\n<\/ul>\n<\/li>\n<li><strong>Externally \u2013 in Emulator<\/strong>. With AVD running, click (\u2026) -&gt; Settings -&gt; Proxy. Disable <em>Use Android Studio HTTP proxy settings<\/em>. Check <em>Manual proxy configuration<\/em>. Use <em>Host name<\/em> = <code>127.0.0.1<\/code>, <em>Port number<\/em> = <code>8080<\/code>. Click Apply.<\/li>\n<\/ul>\n<p>We're using <code>10.0.2.2<\/code> because that's and <code>127.0.0.1<\/code> <\/p>\n<p><strong>Gotcha<\/strong>: if using the latter, turn off Wi-Fi on the AVD and switch to Mobile data. (<a href=\"https:\/\/rifqimfahmi.dev\/blog\/mitmproxy-part-1-inspect-network-traffic-on-android\/\">source<\/a>)<\/p>\n<p>Once configured, connect (or re-connect) to the network.<\/p>\n<h2>Gotchas<\/h2>\n<ol>\n<li>Enable play store by editing the ini file<\/li>\n<li>Make sure your SDK has play store in it<\/li>\n<\/ol>\n<p>Navigating to the SDK folder: <code>cd ~\/Library\/Android\/sdk<\/code><\/p>\n<p>If the AVD doesn't start, debug by using command line:<\/p>\n<pre><code>emulator\/emulator -list-avds\nemulator\/emulator -avd My_Pixel_Example -verbose<\/code><\/pre>\n<p>If the emulator is slow, consider choosing older APIs (25) and using <em>Desktop Native OpenGL<\/em>.<\/p>\n<p>If you need to install a specific app, get it from e.g. <a href=\"https:\/\/www.apkmirror.com\/\">apkmirror.com<\/a> or <a href=\"https:\/\/www.apkpure.com\/\">apkpure.com<\/a> and install by calling <code>platform-tools\/adb install &quot;\/private\/tmp\/example.apk&quot;<\/code>. You don't have to shut down the device, you can install while it's running and the app will appear in the menu automatically.<\/p>\n<p>Choosing API that's <a href=\"https:\/\/github.com\/shroudedcode\/apk-mitm\">pre Android 7<\/a> will make MITM easier:<\/p>\n<blockquote>\n<p>However, with the Network Security Configuration introduced in Android 7 and app developers trying to prevent MITM attacks using certificate pinning, getting an app to work with an HTTPS proxy has become quite tedious.<\/p>\n<\/blockquote>\n<p>If you're trying to add your MITM proxy and it's <a href=\"https:\/\/stackoverflow.com\/questions\/70972106\/how-to-configure-proxy-in-emulators-in-new-versions-of-android-studio\">not working via Settings -&gt; Proxy<\/a> and you don't have <a href=\"https:\/\/stackoverflow.com\/questions\/59266688\/android-emulator-unreachable-proxy-on-host-windows\/63996877#63996877\">Wi-Fi to try the alternative way<\/a>, do it <a href=\"https:\/\/medium.com\/@indaniram\/run-android-emulator-with-proxy-configurations-6586ecb5461d\">via APN settings<\/a>. Put <code>10.0.2.2<\/code> (<a href=\"https:\/\/developer.android.com\/studio\/run\/emulator-networking\">source<\/a>) as server and <code>8080<\/code> as port.<\/p>\n<p>Remember to turn the Airplane Mode on and off after you boot your device. Until you do, your traffic won't be routed through the proxy you configured.<\/p>\n<p>Links:<\/p>\n<ul>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/42848328\/android-emulator-not-working-on-mac\">https:\/\/stackoverflow.com\/questions\/42848328\/android-emulator-not-working-on-mac<\/a><\/li>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/52600963\/why-android-studio-emulator-is-extremely-slow\">https:\/\/stackoverflow.com\/questions\/52600963\/why-android-studio-emulator-is-extremely-slow<\/a><\/li>\n<li><a href=\"https:\/\/earthly.dev\/blog\/mitmproxy\/\">https:\/\/earthly.dev\/blog\/mitmproxy\/<\/a><\/li>\n<li><a href=\"https:\/\/medium.com\/@williamxyz\/monitoring-network-on-android-with-mitmproxy-bfb8722191ee\">https:\/\/medium.com\/@williamxyz\/monitoring-network-on-android-with-mitmproxy-bfb8722191ee<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Android 7+ introduces certificate pinning that makes it more difficult to debug the requests the device makes. This covers the pre-certificate-pinning Android versions. Install Download and install. Here&#8217;s the archive with all available versions: https:\/\/developer.android.com\/studio\/archive. I will be installing 2023.2.1.25. First Launch; Choosing SDK If Android Studio crashes every time you try to open it,&hellip; <a class=\"more-link\" href=\"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/experimental\/android-7-virtual-device-gotchas\/\">Continue reading <span class=\"screen-reader-text\">Android Studio Virtual Device: Installing and Gotchas, pre-Android 7<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[811],"tags":[1214,1228],"class_list":["post-1577","post","type-post","status-publish","format-standard","hentry","category-experimental","tag-android","tag-android-studio","entry"],"_links":{"self":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/comments?post=1577"}],"version-history":[{"count":5,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1577\/revisions"}],"predecessor-version":[{"id":1602,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1577\/revisions\/1602"}],"wp:attachment":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/media?parent=1577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/categories?post=1577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/tags?post=1577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}