Clone wiki

nbandroid / NBAndroid

Features

The NBAndroid is comprised of a number of parts providing different functions.

  • Core Android SDK support
  • Project support
    • Using new Gradle based build system
    • Using legacy project types built with Ant
  • GUI layout preview (experimental)
  • Enhanced editors for Android XML files
  • Lint support

Core support

Provides a bridge for a communication between IDE and all Android SDK tools and connected devices. It uses Android SDK registered in Tools | Options dialog in Miscellaneous section and Android tab. Set up this location first before you begin to work with NBAndroid.

  • Connected devices can be seen and controlled to some extent in Services in the IDE (Ctrl-5). Device nodes can be explored using their Properties window when you select them.
  • LogCat viewer. It is accessible from main menu Window | Output | ADB log viewer.

Android Project Support

Gradle support

Gradle is the new build system for the Android project and the infrastructure is being developed now by Android Tools team. See their Android tools site for details and documentation.

Gradle based Android projects is based on NetBeans Gradle Plugin that will be installed automatically with NBAndroid Extensions.

  • Support for Gradle projects using version 1.0.0 of Android plugin and Gradle version 2.2.1 or newer
  • Classpath set according to selected build type and flavor
  • Access to project resources again using applied selection of build variant
  • Deploys and execute or debug your application
  • Run Android tests
  • Other features from NBAndroid plugin like resource editing are working for Gradle projects too

Ant-based command line projects

Project support in NetBeans is designed to be compatible with command line tools in Android SDK. It means the project layout and build system is the same as for many other applications. This makes it possible to develop your project using different tools when you want to switch. Read more about these projects at http://developer.android.com/tools/projects/projects-cmdline.html

You can open existing Android projects or create a new one using New project wizard in the IDE. Every project needs to have a build target assigned. You can view and edit this target in project customizer (select project node in Project tab and invoke Properties action from its context menu) or in one of .properties files in a root folder of your project. This is a target platform used when building your application. Most likely you want to match this target with minimum API level in AndroidManifest.xml.

Run and debug is supported for your applications. In addition to that you can http://www.nbandroid.org/2011/06/attach-debugger.html attach debugger to processes running on your device.

Test projects are supported too and you can http://www.nbandroid.org/2011/04/initial-support-for-test-projects.html execute your tests and browse the output using standard JUnit results window.

Libraries and Project Dependencies
  • Android Library Projects are supported and inter-dependencies are modeled in NBAndoid. Read the documentation at http://developer.android.com/tools/projects/projects-cmdline.html
  • To add JAR libraries as a dependency just copy them into libs folder of your project. Alternatively you can use a different directory if you add jar.libs.dir=_path_to_your_lib_ into one of properties files included by Ant build script (project.properties).

TODO: beware of pom.xml in your projects that will turn it into Maven project (ActionBarSherlock).

TODO: document how to attach sources to JARs

Where is my R.java?

Read our blog post on why you can see error markers at identifiers like R.layout.main when you open a project that is not built - http://www.nbandroid.org/2012/11/where-is-my-rjava.html

Building, running, testing

Obviously there is a support for application building that delegates the work to Ant.

It is possible to run or debug created application on emulators or real devices.

Deployment to a device

You can deploy your application to an emulator or to a real device.

If you want to use an emulator you have to create it outside NetBeans/NBAndroid. There is plenty of resources describing how to do it using Android SDK tools.

Real devices are used using Android Debug Bridge. Make sure it is configured properly. This involves things like USB driver installation (windows) or USB system setup that make the device accessible. Also you need to enable development mode on your phone/tablet.

If there are problems with this and you cannot see the device the first thing to check is to open Services tab (Ctrl-5) and verify that the device is visible under Android Devices there. If it is not there you can try to restart ADB using an action in context menu of Android Devices node.

Testing

NBAndroid also knows about test project and how to run their tests. As usual you can find introductory material at http://developer.android.com/tools/testing/testing_otheride.html

Application publishing

Release version of an application is usually built on a CI server but you can do it in NetBeans using NBAndroid too.

Here is what you need to do:

Another description of this feature is on our blog - http://www.nbandroid.org/2011/05/building-signed-packages.html

GUI layout preview

GUI layout preview in current versions is an early prototype of GUI rendering that makes it simpler to create GUI for Android. It avoids the need to build the application and then run it on a device with some special profiles to see the differences in rendering.

To use the layout preview open its window from main menu Window | Output | Android Layout Preview. The window will attempt to render last selected layout file (i.e. it tracks file selection in the IDE).

  • It renders layouts based on selected device profile and configuration and using rendering engine of Given Android platform. Things that need to be set to render the layout include:
    • Device - resolution, DPI, color density, default orientation and other inputs are primarily derived from this information. You can select device from a list of devices in top left popup. The list can be managed in Android tool that is part of your SDK - http://developer.android.com/tools/devices/managing-avds.html. Go to Manage AVDs... screen and switch to Device Definition tab there.
    • Platform - this is used to pick proper version of rendering engine and resource. The plugin pre-selects this according to values find in AndroidManifest.xml but it has be reported that this selection is sometimes not working properly - just re-select the value in such case.
    • Theme (the popup in the bottom row) - this is another important aspect of rendering. The theme chooser sets it to default 'Theme'. Ideally it should associate the layout with an activity and check if there is a theme assigned to it.
    • Other controls are optional and will set device orientation, mode (NORMAL/CAR/DOCK/TV), time, and locale.
  • It expects that the project is built.
    • R.java file generated by the build is needed to resolve identifiers in layout file to symbols in code. Adding new widgets or changes in their IDs will break that resolution and affect what can be rendered.
    • If there is an application code involved (for example custom view classes) it needs to be compiled to let the renderer instantiate these objects.
  • Visual editor is not implemented yet.
  • Fragments are not supported yet.

GUI preview troubleshooting

If you cannot get it to work you can look at the existing bug report https://bitbucket.org/nbandroid/nbandroid/issue/3/cannot-render-missing-rendering-data

Better than submitting comments 'it doesn't work for me' is to attach IDE log files with logging enabled. There is a how-to in Contacts. You can also add an example of your project and steps how to reproduce the problem.

Other features

Resource editors

There is a limited support for XML editing of Android specific XML files. Our editors are aware of AndroidManifest.xml file syntax and they recognize general structure of layout files. The features were documented http://www.nbandroid.org/2011/04/easier-androidmanifestxml-editing.html here, http://www.nbandroid.org/2011/05/more-improvements-in-xml-editing.html here and http://www.nbandroid.org/2011/05/xml-editor-work-continued.html here.

Go to NBAndroid Extensions to read about additional features.

Resource navigation

Hyperlink navigation for resource identifiers to link Java sources in Android project and resource definition under res folder hierarchy and in AndroidManifest.xml (described here).

  • Identifiers like R.id.xyz are recognized in Java sources and you can navigate to a defining resource file.
  • Various attribute values in XML files are supported as well. For example "@string/my_label"
  • Class names in AndroidManifest.xml are detected too.

Formatting preferences

Projects using NBAndroid extensions can define their own formatting preferences.

Lint support

Android's Lint tool is integrated thanks to help from NetBeans folks and you can see what Lint tells you about the project in Java files as well as in various resources files and manifest.

Updated