Building Unity for Android with Eclipse

Eclipse + Unity

While working on a Unity project for Android I found the need to move the build process to Eclipse. This process used to be complicated and tricky, but thankfully it became rather simple with Unity 4.

Note: The instructions below relate to Windows 7. YMMV.

Before we begin, you’ll need to install two tools:

  1. Android SDK
  2. Eclipse + ADT Plugin

You can download them both here. They’re bundled together, named “ADT Bundle”. In the same page you can click “Use an existing IDE” to download only the SDK.

Android SDK

If you’re not familiar with the Android SDK, you should know that it consists of multiple components. After you install it you can manage which components are installed using the SDK Manager. The components that you must have are SDK Tools (installed by default) and at least one SDK Platform. I decided to go with Android 4.0.3 (API 15). Choose whatever suits you. Once you choose your platform, you only have to install “SDK Platform”. The rest is optional. (You may want “ARM EABI v7a System Image” to use the emulator.)

I also recommended installing whatever the SDK Manager suggest under Tools and Extras, namely: SDK Platform-tools, SDK Build-tools, Android Support Library and Google USB Driver.

Invokation Failed

I’ve encountered a bug with version 22 of the SDK. Unity could not build with it. I’d get the following error:

Edit: This bug seems to have been solved with version 22.0.1 of Android SDK.

At least this is the case with version 4.1.2f1 of Unity. If you have this problem, try downgrading your Android SDK version: Uninstall version 22 and then install version 21 (available here). Strangely enough, after you install version 21 you can let the SDK Manager upgrade “Android SDK Tools” (under “Tools”) to rev. 22 and Unity will still be able to work with it. Voodoo.

After you downgrade to rev. 21 and you’ll be seeing this error each time you open Eclipse:


Don’t worry about it. Just hit Close.

Eclipse & ADT Plugin

If you’ve already built stuff for Android using Unity then you probably already have the SDK installed. You could install Eclipse for Mobile separately and then the ADT Plugin. But you can also download the ADT Bundle and take from it only the “eclipse” directory. It’s a download overkill (>400MB), but it’s easier to install.

Anyway, all Eclipse installations are simply ZIP files. There is no installer. Extract the ZIP file contents to wherever you want, e.g. “C:\eclipse”.

Export Eclipse Project from Unity

It’s time to open Unity. Open the build settings for Android and you’ll see a check box “Create Eclipse project”. Selecting it directs Unity to create an Eclipse project instead of building an APK file. When asked, choose a target directory for the Eclipse project.

Import Project into Eclipse

Open Eclipse. Choose “File => Import”. Under “Android” choose “Existing Android Code Into Workspace”. Fill the “Root Directory” field with the path of the project directory and hit Enter. You should see your project in the list. You might see more than one project if you’re using plugins. Deselect the plugins, you don’t need to import them – they’re included in the main project. Click “Finish”. That’s it. Your project is ready to be built.

Windows tech tip of the week #1

Open File dialog box


It’s been a long time since I posted. Sorry about that  😉

It took me a while to figure out what I want to write here in my blog. I started the blog thinking I’d write about technical stuff. Maybe software development, or game design. It was right after I stopped working on Swat and I had the burning feeling that I needed to help the world by warning it about the dangers of using ActionScript. I wanted to tell the world about it’s rounding bug when changing an object’s alpha property. I wanted to rant about how animations started playing just because I had the audacity to pre-load them. And how I got around it by muting the speaker. I was young and infused with a sense of mission. But, alas, my passion faded away. At first it was simply too painful, the wounds still fresh. I always found excuses not to do it. After some time I was thinking: there are some good solutions out there, though few and scattered. Shall I point them out? Fill out the blog a little with a few good pointers? Nah… that’s not very interesting. And then, after a while, I just thought about Flash less and less, like most of the world, I presume.

So what shall I write about? Maybe some stupid hello-world-first-post-in-the-blog thingie? (No, that’s boring, right?)  I could just write about what I’m developing – about Windows Phone 8. That’s annoying enough! Maybe I’ll share my frustrating experiences with simply trying to install the damn development platform? I only laid my hands on it and already had several new warnings to share with the world. Should I start my blog with a good, long rant? I do love to rant.

Nay. I’ll have enough time for that later! Here’s a useful little tip instead.

Windows tech tip of the week #1: If you’re using Windows, this might help you save some time whenever you need to attach a file.

Know that annoying “open file” dialog box? Well, it’s annoying if you’ve already got the directory open in front of your eyes. You can see the file, but you can’t simply drag and drop it, now can you? What you can do is copy the file (ctrl+c) and then in the dialog box in the file name field paste it (ctrl+v). It will paste the file *name*, complete with the path. Hit OK and get back to your life.

You can also copy the file path by holding down the Shift key and right-clicking the file. The Shift key miraculously add the “Copy as path” option to the pop-up menu.

Oh, and speaking of Windows 8, don’t install it on your laptop just yet if you’re a keyboard man like me.

peace out