Tag: android

Free Unity 3 “basic” License

Last year I talked a bit about some of my augmented reality projects. Many of you have sent questions and posted comments so I suppose there is a certain level of interest in that field. One of the conclusions I had back then was that to achieve a certain level of quality (great lighting effects, surface reflection, etc.) when rendering a 3D model in an augmented reality project, you better use a good 3D engine (such as Unity). I still think this is true.

Yesterday I “discovered” that Unity is offering its iOS and Android “basic” license for free until April 8th. Normally, you’d have to pay $400 for each of them. So if you were unsure Unity was a good choice for your project of not, go ahead and buy it for free. 😉 What a great way to finally test it out.

  1. Go to https://store.unity3d.com/index.html
  2. Select Unity FREE
  3. Add features: iOS and Android (both free until April 8th)
  4. Proceed to checkout
  5. Open email upon reception, and follow the instructions

Now enjoy your brand new installed Unity development tools!

Render Your Own 3D Model in QCAR

Teapot 3D Model

Note: this article is short and doesn’t give detailed answers as much as I would have liked. I started writing it a while ago and realized it had never been published. I haven’t worked with QCAR for a couple of months now, so the subject isn’t so fresh in my mind anymore. Here it goes…

I’ve worked with QCAR for about two months earlier this summer. Using the library is very easy, and it gives pretty good results in terms of responsiveness and robustness. But because my knowledge of OpenGL is very limited, my worst problem has been importing my own 3D model and making it render correctly (with textures and proper lighting).

Use Blender to triangulate

First, mobile devices don’t run the standard OpenGL library, they run OpenGL ES. This means 3D models have to be triangulated or they won’t render at all. Triangulation is the process of dividing all polygons into triangles.

Blender is a free open source 3D graphics application. It can easily be installed on any Ubuntu version by installing the package named blender. Using Blender you’ll be able to triangulate your model when exporting to an .obj file. Then you’ll have to export the .obj file to a .h, which finally can be imported into your QCAR/Android project. This might be “great” for testing, but in the long term, you’ll run into dozens of problems of lighting, reflection, animation, etc.

Texture dimensions

A problem you might run into is using badly dimensioned textures. This problem was kind of hard to find for me as you only get runtime fatal errors which don’t give any relevant detail. But you need to know that almost all mobile devices will only take squares and 2×1 / 1×2 rectangles for texture files. For example, these dimensions would work: 512 x 512, 32 x16 and 128 x 256 pixels. These would not : 1024 x 16, 512 x 64 pixels. Another thing with textures: depending on models, there are limits to the total number of texture files you can load at the same time in an application, and there are limits to their dimensions (1024, 512, and 256 pixels).

I recommend using Unity

According to Wikipedia, “Unity is an integrated authoring tool for creating 3D video games or other interactive content such as architectural visualizations or real-time 3D animations.” In other words: it makes A LOT OF STUFF much better and much faster than an OpenGL developer (or a whole team) would do. What are the downsides? Size (approximately 16 to 20 MB when correctly compiled), cost ($400 for the Android license), and finally, support is not as good on Android as it is on iOS. More information available on Unity’s website.

Even if Unity’s solution isn’t perfect (are there any perfect solutions anyway?), it is in my opinion a million times better than working with your own 3D model and custom OpenGL ES. You’ll be able to simplify your model(s) to enhance performance (which is very important on mobile devices), lighting and other visual effects will be much easier to create, etc. Overall, you’ll get a much better result for way less effort. Everyone wins!

Please visit QCAR’s developer site for SDK download, documentation on how to start a QCAR project, how to integrate the Unity extension, and more.

Remove Underline from Android TextView Link

As you may already know, the TextView object has a property named android:autoLink that creates HTML or email links automatically. You also got properties to change link colors such as android:textColorLink and android:textColorHighlight. The only missing option many of us would like to have is a way to remove the underline under the link itself.

Sadly, removing the underline seems to be somewhat “hard” to achieve. So here’s my way of doing this, greatly inspired of the code I found on this blog.

First, let’s create a TextView:

<TextView android:id="@+id/myTextView"
          android:text="Want to search www.google.com?"

The TextView above should look approximately like this when rendered in Android:

Want to search www.google.com?

Then we need a “util” class we’ll name URLSpanNoUnderline:

package com.evilcodingmonkey.android.util;

import android.text.TextPaint;
import android.text.style.URLSpan;

public class URLSpanNoUnderline extends URLSpan {
    public URLSpanNoUnderline(String p_Url) {

    public void updateDrawState(TextPaint p_DrawState) {

If you already have a StringUtil-like class (I always have one in my projects), add the following function to it. You may add this function anywhere you want anyway…

 * Removes URL underlines in a string by replacing URLSpan occurrences by
 * URLSpanNoUnderline objects.
 * @param p_Text A Spannable object. For example, a TextView casted as
 *               Spannable.
public static void removeUnderlines(Spannable p_Text) {
    URLSpan[] spans = p_Text.getSpans(0, p_Text.length(), URLSpan.class);

    for(URLSpan span:spans) {
        int start = p_Text.getSpanStart(span);
        int end = p_Text.getSpanEnd(span);
        span = new URLSpanNoUnderline(span.getURL());
        p_Text.setSpan(span, start, end, 0);

The last thing you have to do to replace all occurences of URLSpan by URLSpanNoUnderline in your TextView objects. I do that by modifying the onCreate function of my Activity classes. For example, this is the onCreate function of the “about” screen of my app:

protected void onCreate(Bundle p_SavedInstanceState) {


    // Remove underlines from HTML links
    TextView txtUrlGoogle = (TextView)findViewById(R.id.textUrlGoogle);

    // Make sure the TextView was instantiated correctly
    if(txtUrlGoogle != null) {

And we’re done! As you can see, this is totally reusable. All TextView properties such as color will continue to work as they are intended to. As I said at the beginning of my post, I did not invented this way of removing underlines, but I think this will help clarify it, and show how it can be easily reused.

Setting Up Eclipse for Android Under Ubuntu

Android using Eclipse under UbuntuI know, tutorials such as this one can be found all around the Web. But I feel this might be helpful for many people reading this blog. I will try to cover everything from JDK installation to deploying applications directly to your phone using the “run” button in Eclipse.

Used for this tutorial

  • Ubuntu 11.04 (Natty Narwhal)
  • Acer TimelineX 1830T netbook
  • Samsung Galaxy S Fascinate
  • USB cable

Before you continue

Before you continue, please note that I rarely use the Ubuntu Software Center to install packages and applications so I will mostly use command line in this article. If this causes you any problem, feel free to post your questions in the comments section.

Installing Eclipse

If you don’t already know, Eclipse is a free and open source IDE (integrated development environment) that can be used to develop in Java, C++, PHP, Ruby, and many more. To install Eclipse, open a Bash shell and execute the following:

sudo apt-get install eclipse

By installing the Eclipse package, many other packages such as Java JRE and JDK will be installed. This will save you a lot of configuration time.

Installing the Android SDK

Call it a personal preference. but I like to install SDK’s in the /usr/lib folder. If you prefer to install it somewhere else, in your home folder for example, feel free to do so. Note: replace your_user by your Ubuntu user name.

cd /usr/lib
sudo mkdir android
sudo chown -R your_user:your_user android
cd android

Now navigate to the Android SDK Download Page and copy the link to the Linux (i386) SDK. At the time of writing this article, the URL is: http://dl.google.com/android/android-sdk_r10-linux_x86.tgz. Now back to your shell:

wget http://dl.google.com/android/android-sdk_r10-linux_x86.tgz
tar -xvzf android-sdk_r10-linux_x86.tgz

Installing the ADT Plugin for Eclipse

The Android Development Tools (ADT) Plugin is required for any Android development. Follow these instructions to install it:

  1. Open Eclipse (confirm workspace location if prompted, default location is good)
  2. In Eclipse’s top menu, select Help / Install New Software…
  3. Click on the “Add…” button
  4. Enter “ADT Plugin” for the name, the following for the URL and click the OK button: https://dl-ssl.google.com/android/eclipse/
  5. Check “Developer Tools” (to download everything offered) and click the Next button twice
  6. Accept terms and conditions and click “Finish”
  7. If security warning pops, click “OK” to continue
  8. When asked, click “Yes” to restart Eclipse

Configuring Eclipse with the Android SDK

Eclipse needs to know where the Android SDK was installed:

  1. In Eclipse’s top menu, select Window / Preferences
  2. In the window’s left menu, click on “Android”
  3. Click “Browse…” and locate the place where the Android SDK was previously installed (in my case: /usr/lib/android/android-sdk-linux_x86)
  4. Click “OK” but not “Apply”

Other essential SDK components

Before you are ready to start developing, some essential components must be downloaded and installed using the Android SDK and AVD Manager. To open the manager, you can use the download-like arrow icon located in left part of Eclipse’s icon bar, or you can select Window / Android SDK and AVD Manager from the top menu.

Click on “Available Packages” on the left, and under “Android Repositories” select the following packages:

  • Android SDK Platform-tools
  • Android SDK Tools (if in the list, but it shouldn’t at this point)
  • Documentation for Android SDK
  • One or several SDK Platforms (I chose Android 2.1 and 2.2 because that’s the API’s I’m developing for)
  • Click “Install Selected”
  • Select “Accept All” and click “Install”
  • When asked, click “Yes” to restart the ADB

Note 1: it is recommended you choose an Android API as low as possible to reach as many users as possible. Click here for the latest usage share.

Note 2: if you need more help selecting components, please read this.

Adding the Platform Tools to your environment

To make the Android SDK Platform-tools available from everywhere, you need to add the platform-tools directory to the PATH environment variable. To do so, use your favorite text editor (I use nano) and do the following:

nano ~/.bashrc

Scroll to the end of the file and add this line:


Logout from your Ubuntu session and log back in. Now the “adb” command should be available from anywhere in your Bash shell.

Setting your phone

To be able to deploy your applications directly from Eclipse to your phone, you need to do two things:

  1. Set USB Debugging on (on my phone, with Android 2.2, it’s located under Settings / Applications / Development)
  2. Allow install of non-market applications (again, on my phone, under Settings / Applications)

Connect your phone to ADB

Using your USB cable, connect your phone to your computer. Your phone should “say” it is now under USB debugging. On your computer, open a shell and type:

adb devices

You should get an output like this one:

List of devices attached
1000ed430c4c    device

If you can’t see your device, try:

adb kill-server
adb start-server

Finally, deploy to your phone

Now start Eclipse. Open your Android project or create a new one (not covered in this tutorial).

You will need to create a run configuration at this point if not done already. What is important here is to set your configuration’s target to “Manual”. When finished, press “run” (the green play button). A window entitled “Android Device Chooser” should now open and your phone should be there. Select it and press the OK button. It should then deploy to your phone and the application will start by itself.

If you get a timeout error

When deploying to your phone, you may someday get:

Android error: Failed to install *.apk on device *: timeout.

It can be solved easily by going into Eclipse’s top menu in Window / Preferences / Android / DDMS, and changing the ADB connection timeout.

Why not use the emulator?

The emulator may be a good tool in some situations (you can’t own/test all different devices). But I prefer to develop directly on my phone. This is why this tutorial won’t cover the use of the emulator. At this point, I’m almost sure you will figure it out by yourself as all the required tools have now been installed.

Need more help?

I really hope this will help you getting started with your Android development projects. If this tutorial doesn’t answer all your questions, here are some sites/pages you may want to visit:

As always, feel free to post your questions or comments!

Starting an Android AR Project with QCAR

Qualcomm LogoIn my previous post, Augmented Reality on Android, I listed several AR libraries for Android. After reading and trying some of them, I finally decided to go with Qualcomm’s QCAR. By great coincidence, QCAR’s first production-ready release happened this week with version 1.0.0.

My reasons for choosing QCAR

  1. Official support for a great list of devices, old and recent
  2. Their demos, tested on my Samsung Galaxy S, are way snappier than other libraries I tried
  3. It recognizes partial markers (when partly in the camera’s sight)
  4. Great developer guide and API documentation
  5. Great developer community (forums)

Loading a 3D model

As stated in my previous post, I need to load a 3D model over a marker when it comes in the camera’s sight. The model I have to load is a .obj file, but QCAR only “works” with .h files (the usual way of doing things in OpenGL). I found two ways of solving this problem:

  1. Converting .obj file to .h file using this script: OBJ2OPENGL
  2. Using a second library to load .obj files

Right now, I’m trying both options. I’ve had success with the min3d library, but I’m experiencing some image distortion. I still have a lot of work to do. Like I said before, I’m no Android expert, and I’m still learning the basics. I’ll be back soon with more on this subject. In the meantime, feel free to post any comment or question.

—- EDIT (September 9, 2011) —-

I am not working on this project anymore, but I’d like to let everyone know I didn’t use min3d. I converted my 3D model to OpenGL ES .h file. Read this post for more information.

Augmented Reality on Android

AR Baseball Card

Augmented reality is an old concept but only recently, we start seeing more and more of it on our phones. Here’s my quest for finding a good library that will help me build an Android augmented reality as requested by a client. I want to add to at the moment of writing this, I’m fairly new to Android development and I’m about to create an AR application for the first time of my life. What are we waiting for?

Client needs

  • Display a 3D model of “something” on an event ticket

Library requirements

  • Recognize a pattern or a picture (that will be printed on the ticket)
  • Add a 3D model layer over the pattern or image
  • Be as responsive as possible (lagging AR sucks)

Available libraries

Obviously, finding an AR library for this small project would be a good thing. After searching Google for a while, here’s what I have found:

  1. Magnitude (Google Code project)
  2. Qualcomm AR or QCAR (Qualcomm AR SDK download page)
  3. ARToolKit (Sourceforce page)
  4. Popcode (Popcode official demos)
  5. AndAR (Google Code project)
  6. Android AR-Kit (GitHub page, tutorial)
  7. Mixare (Official website)
  8. NyARToolKit (Official website)

1. Magnitude

First, the project’s last update was in July 2010. Not too old, but not that recent either. Second, it seems to be only based on GPS instead of marker recognition. Also, the author says it uses AR-KIT (listed 6th in my previous list), ported to Android. It can’t help me.


Updated for the last time in December 2010, this project offers multiple target recognition and seems to have great documentation. This library is definitely worth a try.

3. ARToolKit

Not much is said on the project’s page, but it seems somewhat serious and works with marker recognition. Will probably give it a try.

4. Popcode

Their demos look very great, but based on their documentation (if I understand well), it only works with specially designed Popcode markers, and as of now, there is no way to display my own 3D model, if it’s not previously saved on the device’s SD card. It seems to be a great library though, so investing more time to understand the way it works correctly would be a good thing.

5. AndAR

Already tried it to create a green cube that appears on a marker. Works great and is very easy to use, but I experience a lot of lag with my Samsung Galaxy S. I’ll take a look at the library’s code and try to find what the problem is if I can’t find a better library.

6. Android AR-Kit

This was originally an iPhone only library, but it has been ported to Android. Two major problems though: there has been no update since December 2009, and it only works with geographic localization.

7. Mixare

This seems to be a very nice library that supports both Android and iPhone. Problem for me: it only works with geographic localization.

8. NyARToolKit

This project supports many languages (Java / Android / C# / ActionScript3 / C++). Here’s the link for the Android project. The project is well alive with last commit on April 15. It supports multiple markers and is definitely worth a try.

Now what?

Now I gotta make tests with: QCAR, ARToolKit, AndAR, and NyARToolKit. Stay tuned for the upcoming conclusion in a couple of days or weeks.

© 2019 Evil Coding Monkey

Theme by Anders NorenUp ↑