IntroAndroidDevNetBeans

(Difference between revisions)
Line 1: Line 1:
==Introducing Android Development with NetBeans==
==Introducing Android Development with NetBeans==
-
'''Updated on 26 November, 2008 for NetBeans 6.5 and Android SDK 1.0 Release 1'''
+
'''This wiki page described an old version of Android plugin and that's why I deleted the content here to avoid confussion. Read about current version at [http://www.nbandroid.org/ nbandroid] website.
-
Contributed by: [[AmitKumarSaha| Amit Kumar Saha]]
+
Namely look at the [http://www.nbandroid.org/p/installation.html installation] and first steps in [http://kenai.com/projects/nbandroid/pages/Home project wiki]. --Radim Kubacki on Jul 28, 2011'''
-
'''Note that this wiki page describes an old version of Android plugin. Read more about current version at [http://www.nbandroid.org/] and about installation and first steps in [http://kenai.com/projects/nbandroid/pages/Home project wiki]. --Radim Kubacki on May 22, 2011'''
 
-
----
 
-
In this article, I shall show you how you can start with developing for the [http://code.google.com/android/ Android] platform using NetBeans using [http://kenai.com/projects/nbandroid/ nbandroid].
 
-
 
-
__TOC__
 
-
 
-
===Prerequisites===
 
-
 
-
Before you can get started with developing Android applications, you are advised to acquaint yourself with:
 
-
 
-
*The Android Framework
 
-
*Overview of writing applications for Android
 
-
 
-
Please refer to the [http://code.google.com/android/documentation.html Android SDK documentation] for information on the above.
 
-
 
-
You will need:
 
-
 
-
*[http://www.netbeans.org NetBeans 6.5]
 
-
*[http://code.google.com/android/download.html Android SDK] (This document works with Android SDK 1.0)
 
-
*'''Android plugins for NetBeans''':  The Android plugins are now called ''''nbandroid'''' and being developed http://nbandroid.kenai.com. Earlier, the project was called 'undrioid': [http://undroid.nolimit.cz http://undroid.nolimit.cz]
 
----
----
-
===Installing the Android plugins for NetBeans===
+
If you really need to access old version of this document contributed by [[AmitKumarSaha| Amit Kumar Saha]] you can find it in history.
-
 
+
Current maintainers of the plugin would be curious why you do this and you can contact them using one of the means described at [http://www.nbandroid.org/p/contacts.html contacts page].
-
The [http://kenai.com/projects/nbandroid/ nbandroid project] provides the plugins for Android development on NetBeans.
+
-
There are 3 possible ways to install the plugin:
+
-
* '''PREFERRED''' [http://kenai.com/projects/nbandroid/pages/Install Using nbandroid update center]
+
-
* Download and install NBMs. Those are available for download from [http://kenai.com/projects/nbandroid/downloads here]. Once downloaded, install all the plugins by going to Tools > Plugins > Downloaded.
+
-
* You could also clone the project's [http://kenai.com/projects/nbandroid/sources mercurial repository] and build the module suite yourself and then install them. ([http://amitksaha.blogspot.com/2008/11/building-and-using-nbandroid-android.html How?])
+
-
 
+
----
----
-
 
-
===Adding the Android platform===
 
-
 
-
After you have installed the plugins,you have to add your Android platform by going to Tools->Java Platforms:
 
-
 
-
[[Image:android-plat_IntroAndroidDevNetBeans.png]]
 
-
 
-
Point it to your Android SDK location:
 
-
 
-
[[Image:android-plat-1_IntroAndroidDevNetBeans.png]]
 
-
 
-
If you're having error "A platform target has to be selected" like on picture below, make sure, that you've downloaded SDKs by running tools/android update tool (see [http://kenai.com/jira/browse/NBANDROID-55]).
 
-
[[Image:android-plat-2_IntroAndroidDevNetBeans.png]]
 
-
 
-
----
 
-
===Creating a new Android project===
 
-
 
-
Now, go to File->New Projects. You should now see a new entry for Android:
 
-
 
-
[[Image:new-project_IntroAndroidDevNetBeans.png]]
 
-
 
-
Go ahead with the default application name (or change it!)
 
-
 
-
[[Image:new-project-1_IntroAndroidDevNetBeans.png]]
 
-
 
-
You should see a new project structure as below:
 
-
 
-
[[Image:project-structure_IntroAndroidDevNetBeans.png]]
 
-
 
-
The file MainActivity.java is as shown below:
 
-
 
-
<pre>
 
-
 
-
/*
 
-
* To change this template, choose Tools | Templates
 
-
* and open the template in the editor.
 
-
*/
 
-
 
-
package org.me.hellodroid;
 
-
 
-
import android.app.Activity;
 
-
import android.os.Bundle;
 
-
 
-
/**
 
-
*
 
-
* @author amit
 
-
*/
 
-
public class MainActivity extends Activity {
 
-
 
-
    /** Called when the activity is first created. */
 
-
    @Override
 
-
    public void onCreate(Bundle icicle) {
 
-
        super.onCreate(icicle);
 
-
        // ToDo add your GUI initialization code here       
 
-
    }
 
-
 
-
}
 
-
 
-
</pre>
 
-
 
-
As described in the [http://code.google.com/android/documentation.html Android SDK documentation], an Android application is organized as a set of '''activities'''. The file MainActivity.java that has been generated is the main activity class for this application.
 
-
 
-
----
 
-
===Running your project===
 
-
Now, build and Run your project as you would do with any other NetBeans project. Your project builds successfully and the Android emulator boots up:
 
-
 
-
[[Image:run-default_IntroAndroidDevNetBeans.png]]
 
-
 
-
Where is our '''Hello World'''?
 
-
 
-
Just add
 
-
 
-
<pre>
 
-
setContentView(R.layout.main);
 
-
</pre>
 
-
 
-
to the above file in place of
 
-
 
-
<pre>
 
-
// ToDo add your GUI initialization code here
 
-
</pre>
 
-
 
-
This should have been generated by the plugin, because the main.xml containing the main view was generated.
 
-
 
-
 
-
Alternatively we can do the following.
 
-
 
-
We shall now add support to the skeleton code to display the text- '''Hello, Android'''. Add the following to the above file in place of the "// ToDo add your GUI initialization code here":
 
-
 
-
<pre>
 
-
TextView tv = new TextView(this);
 
-
tv.setText("Hello, Android");
 
-
setContentView(tv);
 
-
</pre>
 
-
 
-
You will notice that the IDE complains- "Cannot find symbol". This is because we need to import the class '''TextView'''. Its easy with NetBeans. Just click on the yellow bulb and select "Add import for.."
 
-
 
-
[[Image:import-tip_IntroAndroidDevNetBeans.png]]
 
-
 
-
The file should now look like:
 
-
 
-
<pre>
 
-
package org.me.androidapplication1;
 
-
 
-
import android.app.Activity;
 
-
 
-
import android.os.Bundle;
 
-
import android.widget.TextView;
 
-
 
-
 
-
/**
 
-
*
 
-
* @author amit
 
-
*/
 
-
public class MainActivity extends Activity {
 
-
 
-
    /** Called when the activity is first created. */
 
-
    @Override
 
-
    public void onCreate(Bundle icicle) {
 
-
        super.onCreate(icicle);
 
-
       
 
-
      TextView tv = new TextView(this);
 
-
      tv.setText("Hello, Android");
 
-
      setContentView(tv);
 
-
    }
 
-
 
-
}
 
-
 
-
</pre>
 
-
 
-
Now, run the project again
 
-
 
-
[[Image:run_IntroAndroidDevNetBeans.png | Image:run_IntroAndroidDevNetBeans.png]]
 
-
 
-
 
-
'''Prevent Selection of Target on Each Run'''
 
-
 
-
When you run your project you are given a dialog asking which android device or emulator you would like to use. This can get annoying after several compile/run iterations. To set a default target, right click on the project name, select '''Properties'''. Select '''Run'''. Click on '''Automatic''' and set the preferred AVD. If you do not set the preferred AVD, NetBeans will continue to ask you at each run instance.
 
-
 
-
----
 
-
 
-
===Conclusion===
 
-
 
-
The 'nbandroid' project is just getting started with plenty of opportunities to contribute. Join in at [http://kenai.com/projects/nbandroid/ http://kenai.com/projects/nbandroid/]
 
===References===
===References===
# [http://code.google.com/android/documentation.html Google Android Documentation]
# [http://code.google.com/android/documentation.html Google Android Documentation]
 +
# [http://www.nbandroid.org/ nbandroid site]
 +
# [http://kenai.com/projects/nbandroid/ nbandroid/ porject hosting]

Revision as of 21:37, 28 July 2011

Introducing Android Development with NetBeans

This wiki page described an old version of Android plugin and that's why I deleted the content here to avoid confussion. Read about current version at nbandroid website.

Namely look at the installation and first steps in project wiki. --Radim Kubacki on Jul 28, 2011



If you really need to access old version of this document contributed by Amit Kumar Saha you can find it in history. Current maintainers of the plugin would be curious why you do this and you can contact them using one of the means described at contacts page.


References

  1. Google Android Documentation
  2. nbandroid site
  3. nbandroid/ porject hosting
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo