Скачать книгу

Select Marshmallow and make sure the target column (see Figure 2.20) includes “(with Google APIs).” In this step, you are free to choose either the ARM or Intel-based Android images listed in Figure 2.20.

System Image selection for AVD screen.

Figure 2.20 System Image selection for AVD

      Nexus 5X is an ARM-based device. Although selecting ARM will provide more accurate device/virtual device testing, emulating ARM on an x86-based laptop will require additional memory and processing power and will result in performance issues. By installing HAXM, you can have your virtual device run an Intel image to provide better performance.

      5. Click the Next button shown in Figure 2.20 to tweak final settings of your virtual device.

      6. Make the final configurations, as shown in Figure 2.21, and click Finish.

AVD configuration screen.

Figure 2.21 AVD configuration window

That is it – you created a virtual device that can run your sample project. To run the emulator, open AVD Manager and click the Play icon shown in the Actions column of the virtual device, as shown in Figure 2.22.

Display of List of created virtual devices.

Figure 2.22 List of created virtual devices

      TIP

      Make sure the Use Host GPU option shown in Figure 2.21 is selected. You can also select the Store a snapshot for faster startup option, which will save the last state of the virtual device and load it from disk when it is launched again.

      Depending on your hardware configuration, the emulator may take a while to boot up. The initial bootup will take longer than subsequent launches, which might be close to instantaneous if you have chosen the Store a snapshot for faster startup option.

      You now have a new Android device to play with and it didn't cost you a penny.

      Using ADB

      You have now imported and built your project and created a new Android virtual device. In this section, you learn how to deploy the binary to the virtual device. To do that, you need to know how to connect the two.

Luckily, you won't need to do much; Android Debug Bridge (ADB) will handle all the heavy lifting here. ADB works almost seamlessly to deploy and run your app in a virtual or real device. However, you can always access ADB through your OS's shell and execute commands manually. ADB bridges between your computer and the connected device whether it is a real or a virtual device. Most of the time, you won't need to interact with ADB manually. To use ADB, open a console and type adb. You should see something similar to Listing 2.2 followed by the usage and option details.

LISTING 2.2 : ADB Launch Command

      $ adb

      Android Debug Bridge version 1.0.32

      Revision eac51f2bb6a8-android…

      NOTE

      If the adb command isn't found, you'll have to add it to your system's path. The adb executable is located in the sdk/platform-tools folder.

      Given that the emulator you just created is still running, if you execute adb devices you'll see a list of the devices available over ADB. You can use adb install <apk path> to install a packaged apk to the connected device. However, because the IDE performs this for you, you won't be using the install option extensively.

      Other useful adb options are push and pull. These commands are used to access the device's file system. The following commands will copy a file from your computer to the device and from your device to the computer:

      $ adb push <local> <remote>

      $ adb pull <remote> <local>

MIGRATING PROJECTS FROM ECLIPSE

      Eclipse ADT and Android Studio have very different project structures and configurations, but importing projects from Eclipse to Android Studio is very straightforward in most cases.

      The first option for migrating your Eclipse project to IntelliJ is to import the project into Android Studio.

      1. Select File ⇨ New ⇨ Import Project as shown in Figure 2.23.

Start migrating from Eclipse screenshot.

Figure 2.23 Start migrating from Eclipse

      2. Navigate through your Eclipse project folder and click OK, as shown in Figure 2.24.

Select project path to import screenshot.

Figure 2.24 Select project path to import

      The IDE will create the necessary files, including Gradle files, and set up your project.

      Once the import is complete, import-summary.txt will be shown, which displays the results of the migration.

      Another way to migrate your project is to export the project from Eclipse. To export from Eclipse, your ADT plugins should be up-to-date.

      Конец ознакомительного фрагмента.

      Текст предоставлен ООО «ЛитРес».

      Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.

      Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.

iVBORw0KGgoAAAANSUhEUgAAAFQAAABeCAMAAACKLsOVAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmN

Скачать книгу