Android Studio + Genymotion Emulator

The Android emulator is dog slow. The x86 intel emulators only work with certain versions of OSX, otherwise they crash miserably.

Genymotion is apparently pretty good, so I’m giving that a shot.

Here’s how to do it.

Download and Install VirtualBox

Download VirtualBox + follow instructions to install.

Signup with Genymotion + Download installer

  • Go to genymotion.com and signup
  • Click the “Get Genymotion” button and download the appropriate version for your OS.

Run the Genymotion application

It will install Genymotion and Genmotion shell — run the Genymotion application (not the shell).

When you run it, you will see:

Screenshot

Click add new virtual device. It will ask you to login, then show you a list:

Screenshot

Pick the virtual device you want and it will download it.

Try starting a virtual device

Here’s what happened on my system:

  • Hit Play to run virtual device
  • It asked me to configure the Android SDK location, I said “No”
  • Then it gave me an error that VirtualBox was not installed
  • I started VirtualBox manually
  • I retried running the virtual device, this time it worked and I saw

Screenshot

Configure Android Studio plugin

Go to Preferences / Plugins and click “Browse Repositories”, then search for Genymotion. Right click and choose “Download and Install”.

Screenshot

Restart Android Studio and you should see a new icon in your IDE.

Screenshot

Click the icon and it will bring up Preferences, and choose the path to the Genymotion application.

Screenshot

Now if you click the Genymotion icon again, you will see the list of devices available:

Screenshot

Start an emulator

Click the Genymotion icon within Android studio, select a virtual device, and hit start.

It will ask you to choose the location of the SDK:

Screenshot

On Mac OSX, I was not able to brows to the path since the application was greyed out in the chooser dialog, so I went onto the shell and found it (/Applications/Android Studio.app/sdk) and just copied and pasted it:

Screenshot

Select a virtual device, and hit start (again). It should come up now.

Deploy an application/test to that emulator

In Android Studio, hit the “Play” or “Debug” button, and you should see the dialog that asks you to choose an emulator:

Screenshot

and one of the emulators will be the Genymotion emulator. After you choose that emulator and hit “OK”, it will run your application in the Genymotion emulator (this is showing the Grocery Sync demo app for Couchbase Lite):

Screenshot

Android Studio vs. Eclipse: What You Need To Know

What you need to know before switching to Android Studio

I have written this guide to cover the basics of what you need to know before migrating your Eclipse projects over the Android Studio. If you have a large and gnarly project to migrate from Eclipse over to Android Studio, consider saving time by booking an hour or two with an AirPair expert who has done it before. Otherwise, read on!

Say Good-bye To Work Spaces And Sub-Projects

Eclipse

In Eclipse, you are probably familiar with the concept of a “Workspace.” You likely even have an Android project currently which includes multiple component projects and libraries which are compiled into “.jar” files and included in the final resulting application.In Android Studio, projects are replaced with a new concept called “Modules” and “Library Modules.”

Hello Modules

Modules are a “discrete unit of functionality that can be run, tested, and debugged independently” and are somewhat similar to an Eclipse project with a few key differences.

Each Module needs to have it’s own Gradle build file (generally automatically generated for you when you create a new one, otherwise you can generate them if you are exporting a project from Eclipse). These Gradle files contain important details such as supported Android version ranges, dependencies and other meta-data about your Android project.

Just like in Eclipse, some Modules may be “Library Modules” which are conceptually the same as “Library projects.”

Hello Improved Interface Designer

Interface Designer

Android Studio features a new and improved interface design perspective where you can view the interface you are working on and its related components.Eclipse also has a similar design perspective so it shouldn’t be too big of a shock for you. In Eclipse, a “perspective” is used for providing views and visible actions, as well as delivering mechanisms for interaction with resources, multi-tasking and information filtering.

Including Jar Dependencies

Jar Dependencies

Like Eclipse, you will often need to link to JAR files created by 3rd parties. However, you will now need to get used to adding these .jar dependencies to your Gradle build file. Just like Eclipse, you will keep these .jar files in a “libs” folder at the root of your module (e.g. project) directory.

Simply “Right-Click” .jar files in your “libs” directory and select “Add As Library” and your selected JAR files will automatically be added as Gradle dependencies in the relevant build.gradle file for your Module. Make sure to always click “Sync Gradle” to ensure the project has been properly notified of the new dependency on these modules.

Adding Module Dependencies

Just like in Eclipse, one Module may depend on another Module. Follow these instructions to establish a dependency between two modules and Android Studio will automatically generate the necessary Gradle entries you will need.

Manifest Destiny

One major change you will need to get used to with Android Studio is that several common items and settings which once lived in the Android Manifest now are either automatically added (as in the case of the “debuggable=true” flag indicating an Android application may be debugged) or have been moved to build.gradle such as version codes and  API min / max specifications. Feature and permission requirements, however, must still be declared in the Manifest as before (e.g. “permission: camera” and so on).

Get Help From An Android Expert

One thing that may be helpful is to enlist the help of a seasoned Android Studio expert to walk you through the nuances of the new IDE. Put in a request on AirPair to get paired with an expert – You will likely be surprised by how much ground you can cover in a short period of time talking to a real person.

Migrating From Android Studio

Read my guide on how to migrate from Android Studio to Eclipse to get specifics on the mechanics of exporting and importing an existing Eclipse project over to Android Studio. There are a number of potential issues that can occur along the way which I won’t go into extensive detail on here.

Gradle Basics

The addition of Gradle is going to be your largest hurdle during your transition over to Android Studio. Here are the basics of what you need to know:

  • Your Android Studio project will have a settings.gradle for the whole project
  • The settings.gradle file includes references to all modules which are included in the project and is generally updated automatically when you import or create a new module
  • Each Android Studio module will have its own build.gradle file
  • If one module depends upon another module, you will need to add that dependency in the build.gradle under the dependencies section
  • If your Module requries a jar file, it must be listed in that Module’s build.gradle file
  • You may add remote dependencies to your project by listing them in a module’s build.gradle file
  • From time to time, you *will* need to manually edit these gradle files

Unit Testing

Android Studio comes complete with support for JUnit unit and Android tests. Setting up and running Unit Tests involves creating a few test classes and adding them to your project’s run configuration. Follow the linked guide for more specifics. Popular testing frameworks such as Roboguice are not quite supported at this time but it wouldn’t surprise me if they are in the near future.

Importing Remote Dependencies With Maven

Android Studio allows you to import remote library files from Maven Central. Browse Maven Central for remote libraries you might be interested in and follow these instructions to ensure these dependencies are automatically downloaded at compile time.

So those are the basics of what you need to know. Android Studio is under rapid development and seems to be getting better every week so go check it out.

Make Android Studio work with AndroVM (VirtualBox)

After playing around for a little while with Android on a real device, I thought I’d post on how I got my AndroidVM to work with the new Android Studio.

  1. In VirtualBox Settings for the Device, enable Port Forwarding, using 5555 as the Host Port and 5555 as the Guest Port.
    Virtual Box Port Forwarding Setup
  2. Open a Console/Command Prompt and go to your Android Studio installation and run adb connect 127.0.0.1
    running ADB to connect to Virtual Box
  3. Now setup your project in Android Studio and Run It when it Pops the user interface, select the Emulator Null.
    Select the Device to Connect To
  4. You should now see in the output the following information
    Waiting for device.
    Target device: emulator-5554
    Uploading file
    local path: C:\Users\paul\AndroidStudioProjects\VMConnectProject\VMConnect\build\apk\VMConnect-debug-unaligned.apk
    remote path: /data/local/tmp/com.example.vmconnect
    Installing com.example.vmconnect
    DEVICE SHELL COMMAND: pm install -r “/data/local/tmp/com.example.vmconnect”
    pkg: /data/local/tmp/com.example.vmconnect
    Success

    Launching application: com.example.vmconnect/com.example.vmconnect.MainActivity.
    DEVICE SHELL COMMAND: am start -n “com.example.vmconnect/com.example.vmconnect.MainActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.vmconnect/.MainActivity }

    Android Studio Connection Output
  5. You should now be able to debug and Test your application in the Andoid VM on VirtualBox.