sábado, 30 de abril de 2011

Netbeans + Android SDK + Debugging Androidx86 VM

Since my netbook resources aren't enough to support virtual devices from SDK, it's easier to set up a vm using VirtualBox, and configure adb server to point to this machine IP.

I also have Netbeans installed, so this was a great opportunity to test the Netbeans Android development plugin. This is something experimental, Eclipse works fine enough. But's let's give it a try.

First Steps
The way to try this configuration is based on resources from the following wiki's:



Coments: since you cant install all this resources werever you want, i'll use the following tags:

ANDROID_VM_IP = This is the virtual machine static ip given
HOST_IP_IN_VBOXNET= This is the host machine in the same network than virtual machine, eg vboxnet0
ANDROID_SDK_PATH= This is the path where the Android SDK is installed, ej: /usr/share/android/
PROJECT_PATH= This is the path were your Netbeans project is located, eg. /home/my_user/NetbeansProjects/MyProjectFolder

Adb settings

1. use adb

In the VirtualBox network configuration, it is simplest to configure it for Host-Only or Bridged.
boot up Android iso image on the VirtualBox.
setup ethernet (normally, it will do DHCP by default)
find the IP address of the android VM, by going to the console alt-f1 and then typing: netcfg
you can go back to the UI by pressing alt-f7
on you host machine, go to
cd ANDROID_SDK_PATH/platform-tools
./adb kill-server
./adb connect ANDROID_VM_IP:5555, after this command, you should see something like below
* daemon not running. starting it now *
* daemon started successfully *
ANDROID_VM_IP:5555
./adb logcat to dump the debug log
Now, about my settings:

  • Virtual machine is using host-only network, usually called as vboxnet0
Default segment is 192.168.56.0/24
vboxnet0 Link encap:Ethernet HWaddr 0a:00:27:00:00:00
inet addr: HOST_IP_IN_VBOXNET Bcast:192.168.56.255 Mask:
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:2637 (2.5 KiB)

But this can be done using bridged network or NAT if Internet access is needed, the instructions are explained on link given from AndroidX86.
  • Android is using static IP from current the configured segment


  • Android OS is configured to accept applications from any sources:
Settings>Development>



Now everything should work as usually.

Netbeans IDE


Next step is test Netbeans. Create a new project once the plugin has been installed:




Set a name and activity class:



And that's all, a basic app project tree is created:




And changing the source code from the main activity:

package yesica.tests.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class YesicaHelloWorld extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, This is a Android x86 VM");
setContentView(tv);
}

}

Building the app:
Right click on the project name, and then in Build, option.
We must see something like this:

Creating output directories if needed...
Compiling aidl files into Java classes...
Compiling RenderScript files into Java classes and RenderScript bytecode...
Generating R.java / Manifest.java from the resources...
compile:
ANDROID_SDK_PATH/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
Compiling 2 source files to PROJECT_PATH/Android-helloworld/bin/classes
Converting compiled files and external libraries into PROJECT_PATH/Android-helloworld/bin/classes.dex...
Packaging resources
Creating full resource package...
Creating Android-helloworld-debug-unaligned.apk and signing it with a debug key...
debug:
Running zip align on final apk...
Debug Package: PROJECT_PATH/Android-helloworld/bin/Android-helloworld-debug.apk
And using adb to install it:

$ ./adb install PROJECT_PATH/Android-helloworld/bin/Android-helloworld-debug.apk
And there will be an output like this:
265 KB/s (13470 bytes in 0.049s)
pkg: /data/local/tmp/Android-helloworld-debug.apk
Success

Using Netbeans, click on the run button, and it will prompt to select a device, we should see our VM:



after selecting the device, the Output window will show:

Package Android-helloworld-debug.apk deployed
Starting activity yesica.tests.helloworld.MainActivity on device ANDROID_VM_IP:5555
ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=yesica.tests.helloworld/.MainActivity }


and we see on our VM:


Removing App

To remove the application, we use the Aplication manager/uninstaller from Settings>Applications

Final Comments

[working on the final review of this, with bugs and limitations found]

martes, 5 de abril de 2011

Bienvenida

Este es un nuevo proyecto aun esta en construcción.
Va ligado a mi tesis y a mis hobbies.