Visual Studio V Android Studio
Written by MIke James   
Thursday, 12 November 2015

If you think that Microsoft's involvement with open source and even Linux is a remarkable reversal, what about Visual Studio supporting Java - and Android native development? Visual Studio is now an alternative to Android Studio!

Microsoft's relationship with Java isn't a happy story. After a falling out with Sun over its implementation of J#, a .NET version of Java, it has ignored the language almost completely. Now and quite suddenly Java, proper Java, is back and it is in Visual Studio Update 1 RC. However, it is stuck in a strange place and you might not even notice it.

If you have a copy of Visual Studio 2015, the Community edition will do, then you can install Update 1. Support for building Java files was already in Visual Studio 2015. The ANT build system picks up any .java file in a src folder. Now we have enough Java support to create, debug and run an Android program written in Java. 

 

VSAndroid

 

However, if you go looking for a Java project type or even an Android project type you might conclude that there isn't such a thing. The trick is that you have to look under C++ and open the Cross-platform submenu for one of the Android project types - which show as C++ projects! 

If you select say, Basic Android App, what you get is the familiar Android project folder structure, minus some folders and a Java file in the src folder which reads:

 

package com.Android1;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class Android1 extends Activity
{
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
/* Create a TextView and set its text to "Hello world" */
  TextView tv = new TextView(this);
  tv.setText("Hello World!");
  setContentView(tv);
 } 
}

If you program Android you will recognize this as a perfectly good, simple, app. It is slightly odd in that it doesn't load a resource file - but it could. 

You can now start working on the project. If you download the Java language support extension you will be able to edit the Java with the help of code colorization, error squiggles, code outlining and semantic highlighting. You also get some Intellisense help including member list, parameter help and so on. 

 

vsjava2

 

If you are happy with your code you can run it either on an external USB connected device or via the VS Android Emulator. It just works - click the run button and the code is compiled, the emulator started and after a wait you will see the code running on the emulator. 

New is the ability to also debug the code. You can set breakpoints, look at the call stack, locals etc. In fact this gives you most of the facilities you get under Android Studio. 

At this point you probably want to know the pros and cons. 

The first thing to say is that there is a facility for importing Android Eclipse project, which I haven't tried, but not one for importing Android Studio projects. You can also add source files and make use of the code gallery samples.

If you are familiar with Visual Studio then this might be enough to get you started with Android programming, but compared to Android Studio there are few "comfort" features. The biggest omission is that there is no drag-and-drop UI editor. If you want to build a UI then you have to create a resource file by hand or create the UI programatically, as in the generated code above. You could use Android Studio to create the resource file and then import it into the VS project but this is a little indirect. It also lacks lots of other small editing conveniences that are in Android Studio - the regionalization, editor for example, and various code completion/generation options. However a lot of Android Studio programmers don't realize that these exist anyway!

So what is it all for?

The key to this is the fact that this is a C++ project. Android Studio is not good at supporting the NDK. It is getting better but it is still a long way from being fully capable. If you want to create a mixed Java and C/C++ project using the NDK then this is exactly what Visual Studio is aimed at and it can do things that Android Studio can't. You can find Android NDK samples in the gallery.

The only question that doesn't have an obvious answer is why?

Why is Microsoft creating NDK and Java projects for Android in Visual Studio?

There are a number of obvious explanations - bringing new programmers into VS, making it easier to migrate to Microsoft technologies. However, none of them seem to be a compelling reason.

Will this push continue and will VS become a real challenger to Android Studio, or Eclipse/Netbeans even?

 

androidVS

More Information

Java debugging and language support in Visual Studio for Android

Related Articles

Android Studio 1.4 Goes Vector

Android Studio 1.3 Released

New Tools In NetBeans IDE 8.1

Visual Studio 2015 Launched - Any App Any Developer

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin

 

Banner


Java Version 23 Released
30/09/2024

It was in April 2024 that we had Java 22. Now after just 6 months there's version 23, which is a STS release with lots of features in preview status.



Android Apps Can Block Being Sideloaded
17/09/2024

Android developers now have a way to prevent users sideloading their apps, and users are seeing the effects. Google Play Integrity API, which was released in June, blocks sideloading.


More News

 

kotlin book

 

Comments




or email your comment to: comments@i-programmer.info

 

 

Last Updated ( Thursday, 12 November 2015 )