Category Archives: Development Environments

Install Android SDK and Tools with Eclipse in Ubuntu, Mac OS X and Windows

Here I’ll explain the process to install Android SDK and Tools. There are 4 things you have to install in order to develop Android applications:

  • Android SDK
  • Eclipse
  • Android Development Tools plugins for Eclipse (ADT)
  • Android Virtual Device (ADV)

Android SDK

You can download the latest version of the Android SDK for your OS at the official Android SDK web. Latest versions at the time of this writing are those:

Ubuntu android-sdk_r24.4.1-linux.tgz
Mac OS X android-sdk_r24.4.1-macosx.zip
Windows android-sdk_r24.4.1-windows.zip

Once downloaded uncompress it anywhere you like in your hard drive. It can be for example in your users home folder (/home/username/android-sdk-linux for Ubuntu, /Users/username/Applications/android-sdk-macosx for Mac OS X, C:\Documents and Settings\username\android-sdk-windows for Windows XP, C:\Users\username\android-sdk-windows for Windows Vista/7/8/10) or beside other applications (/usr/lib/android-sdk-linux for Ubuntu, /Applications/android-sdk-macosx for Mac OS X, C:\Program Files\android-sdk-windows for Windows).

Be sure you have configured the JAVA_HOME, ANDROID_HOME and PATH environment variables:

In Linux edit the ~/.bashrc file:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/javac::")
export ANDROID_HOME=~/android-sdk-linux
export PATH=$PATH:~/android-sdk-linux/tools

For Mac OS X you should edit the ~/.bash_profile file:

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=~/Applications/android-sdk-macosx
export PATH=$PATH:~/Applications/android-sdk-macosx/tools

Eclipse

For Eclipse installation just go to https://eclipse.org/downloads/, download it and install it.

Android Development Tools

Open Eclipse and go to “Help→Install New Software”, click “Add…” and enter “ADT Plugin” for “Name” and “https://dl-ssl.google.com/android/eclipse/” for “Location”.

eclipse-add-new-software

eclipse-add-new-software-adt-plugin

Select that repository in “Work with:”, choose all the packages and proceed the installation. Click OK if you see a message saying that unsigned content is being installed . Once installed you have to restart Eclipse.

After the restart, Eclipse will ask you to configure the Android SDK location. Click “Open Preferences”, select “Use existing SDKs” and fill “Existing Location” with the path you used to decompress Android SDK. If you don’t configure it now you can configure it anytime in the Eclipse preferences under the Android options.

eclipse-preferences-android

After configuring the Android SDK location path you will be asked to install SDK Platform Tools. Click “Open SDK Manager” (or select “Window->Android SDK Manager”), select all the packages inside “Tools” and the version of Android of your choice (I used 4.2) and click “Install X packages…”. Don’t worry if you see “Stopping ADB server failed (code -1).” in the log messages, it’s OK.

Android Virtual Device

Now that everything is installed you have to create an Android Virtual Device (AVD) so you can use the emulator. Open the Java perspective (Window->Open Perspective->Java or click the icon with the yellow plus sign at the top right of the IDE and select Java). You will see 2 new icons with the Android symbol in the tools bar. Click the one on the right that looks like a phone (the other one opens the Android SDK Manager), click “New…” and give your Android Virtual Device a name, a device type, a target, etc. If you can’t select a target just restart Eclipse so it can load the newly installed SDK Platform Tools.

In Ubuntu for 64 bit systems you can get this error when creating an AVD:

Error: Failed to create the SD card.
Error: Failed to create sdcard in the AVD folder.

To solve it install the ia32-libs libraries (http://stackoverflow.com/questions/3878445/ubuntu-error-failed-to-create-the-sd-card). Beware that they are about 260MB:

sudo apt-get install ia32-libs

Your first Android Application

Now you are ready to create your first Android application. Create a new “Android Application Project” with all the default options, just fill a “Application Name” like “Hello World”. The default option uses a “BlankActivity” with a template that needs the the Adroid Support library. It will ask you to install it and is as simple as clicking the “Install/Upgrade” button showed in that dialog window.

And there you have a fresh new “Hello Word” Android application. If you make the mistake of clicking the “Run” button you will get an error like this:

Error in an XML file: aborting build

That’s because by default the opened file after creating this “Hello World” project is “activity_main.xml”. You can also notice that a new file called “activity_main.out.xml” has been created, and it even is marked with errors. Delete that newly created file and open the “MainActivity.java” file under “src” folder. Now you can click the “Run” button. Select “Android Application” in the “Run As” dialog window.

I had a problem in Mac OS X Lion after running the emulator several times. When I tried to run the application the emulator crashed every time. Searching on the Internet I found this page where it explains that if you run the emulator in a secondary monitor and close it while in that monitor, a value of the X position of the window is stored and next time that value is bigger that the first monitors resolution and chashes. Deleting the emulator-user.ini file from the /Users/username/.android/avd/device_name folder (executing open /Users/username/.android/avd/device_name from a terminal window) and running the emulator again solved the problem.

As a hint I always deselect “Project->Build Automatically” option because I prefer to build the code manually pressing Control+B or Command+B.

Sources: http://developer.android.com/sdk/installing/installing-adt.html
http://developer.android.com/sdk/installing/adding-packages.html

Deactivate VCS (Version Control System) in PHPStorm

You can enable VCS (Version Control System) in PHPStorm from the VCS menu but, how do you deactivate it?

PHPStorm VCS

I didn’t found an option for that anywhere so this is the solution: Remove the .idea/vcs.xml file and restart PHPStorm.

Ref: How to disable version control in phpstorm?

No splash screen on NetBeans

I’m not a fan of the splash screens the applications, even less on those that place it on top of all your applications all along.

netbeans-splashs-creen

The NetBeans splash screen is easy to hide. You can run Netbeans with the command line option “--nosplash” or add this option to the default ones in the configuration file. This configuration file is in different places depending on the operatin system, but it usually in:

GNU/Linux: "installation folder"/etc/netbeans.conf
Mac OS X: /Applications/NetBeans/NetBeans 8.0.app/Contents/Resources/NetBeans/etc/netbeans.conf
Windows: C:Program FilesNetbeansetcnetbeans.conf

Now that you know where the config file is, edit it and add “--nosplash” to the netbeans_default_options option:

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true --nosplash"

Debug console PHP applications with NetBeans

Assuming you already have PHP and NetBeans configured to debug code using XDebug, these are the steps to debug a console PHP application:

In the terminal window export the value of the XDEBUG_SESSION_START get parameter that NetBeans adds when starting a debug session on the web brower. It’s usually netbeans-xdebug so you should run this for GNU/Linux or Mac OS X:

$ export XDEBUG_CONFIG="idekey=netbeans-xdebug"

And this for Windows (notice the lack of quotes):

C:> export XDEBUG_CONFIG=idekey=netbeans-xdebug

You can change the XDEBUG_SESSION_START value inside PHP NetBeans options in the Debugging tab:

configure netbeans debugging options

Then inside NetBeans set any line you want as a stop point and start the debugger as usual pushing the debug button:

netbeans debug button

Your web broser should open a new tab with the current web being developed. Now in the terminal window that you exported the XDEBUG_CONFIG variable run the php file you want:

$ php my_php_file.php

The debugging process should start and you’ll be ready to go:

debugging

Ref: http://stackoverflow.com/questions/2944880/debugging-php-cli-scripts-with-xdebug-and-netbeans

Fix Netbeans fonts after installing Wine

As I wasn’t going to use Wine that much and broking my fonts pissed me off I decided to completelly uninstall it.

sudo apt-get remove ttf-mscorefonts-installer
sudo apt-get remove wine1.6 wine1.6-i386 wine-mono0.0.8 wine1.6-amd64 wine-gecko2.21 winetricks
sudo apt-get autoremove
rm -rf ~/.wine ~/.winetrickscache ~/winetrickscache ~/winetricks

After all this fonts still were wrong but finally this fixed it:

sudo apt-get remove fonts-unfonts-core

Don’t forget to close and open again Netbeans.