As part of our continued efforts to make Visual Studio a productive environment for developing mobile applications we’re pleased to announce that Visual Studio 2015 Update 1 RC adds support for debugging your Java source files that are part of your Android projects and (with the help of an extension) get IntelliSense and Browsing assistance for these files in the editor.
This blog post shows you how to get started with the newly added Java support as well as what to expect from the Visual Studio support in Update 1.
Support for building Java files is already part of the Visual Studio 2015 RTM release. The ANT build system by default picks any .java file under the “src” folder for compilation. If you include these files in the Android project, they also easily participate in Visual Studio’s built-in source control integration.
To get started with Java into your Android project, you can do any of the following:
When first opening a .java file in the editor, you’ll notice a new breadcrumb notification message that encourages you to install the new Visual Studio extension for Java language support. This notification can be dismissed, but we recommend that you try out this extension and share with us your experience. Note: you need to restart Visual Studio after installing the extension for it to kick into action.
The extension will provide colorization (both syntactic and semantic), error and warning squiggles as well as code outlining and semantic highlighting in your Java files.
In addition to these, while writing code, you’ll get IntelliSense help:
Another handy feature for larger codebases or for navigating 3rd party libraries for which you have the source code available is Go to definition (F12) which will take you to the symbol definition location (if available).
To turn on Java debugging for your Android projects in your next debugging session, in the Debug Target toolbar, change Debug Type dropdown to “Java Only” as in the picture below.
To make the choice persist, you can also go to a project’s properties (right click in Solution Explorer and select “Properties”) and in the Debugging tab switch Debugger Type to “Java Only”.
You can now set line breakpoints anywhere in your Java code. Not only that, but you can add conditions or hit counts for the breakpoints to be hit as well as specify breakpoint actions you want to take when the breakpoints are hit, including continuing the execution of the program (i.e. turn the breakpoint into a TracePoint).
When a breakpoint is hit, you have access to several debug windows providing you insights into the state of your application: Call stack, Watch and Locals windows, and Logcat.
Threads window aids with multi-threaded debugging by displaying the full list of threads including their names and respective call-stacks.
In the Exceptions window, you can configure which first chance exceptions you’d like the debugger to stop on. Once an exception is thrown, execution will stop to the specific location in code with a familiar First Chance Exception dialog giving you the opportunity to inspect the exception.
In addition to the watch window, you can also use the convenient DataTips to quickly view the value of a variable or pin DataTips for specific variables right inside the editor.
This summarizes the current support for Java debugging and language services in Android projects for Visual Studio 2015 Update 1. We look forward to you trying out these new features and sharing your feedback either through Send-A-Smile/Frown (use #cpp2015), Connect, User Voice or down below in the comments.
Simple questions follow.
1. Does this (whatever) allow me (whoever) to do exactly what I can do using Android Studio?
Namely,
A. Write .java
B. Write .c and .cpp
C. Build and make it all work
Simply questions that are not ever answered.
@TL;DR:
The short answer is yes. I also mentioned under "Building Java sources" that to get started with a quick example, you can either use one of the templates that ship with VS or one of the Android NDK samples we also published on visualstudiogallery.com (for example moreteapots). Any of these will be a good starting points to experiment with Visual Studio and write both Java and C++ code.
Also, for more information about Visual Studio's support for mobile cross-platform development, including Android, I recommend watching CppCon talk on this: www.youtube.com/watch
Why only debug Java or debug native, and not debug Java and JNI calls (native)?
If that's just the way it is, how would one easily simulate both?
What should be a given but isn't. Android Studio and the NDK are like a very old couple; they live together but hardly know or care what the other is doing. Case in point, the NDK. Maybe your system is more involved?
What I want to do is to take some java files to do the UI, probably network and other I/O, and have native, as c and c++ files, do various defined jobs related to security.
The security modules are currently static libraries (on x86/win32), and inter-late amongst themselves (c++ calling into c). No way to do this in Android Studio now, and the fuster cluck that is AS and the NDK I don't see how this is going to get there any time soon.
So, if I have (to put it in bare VS parlance) two (sub) projects in a solution, one in c and one in c++, as static libraries, and APIs in the c++ are called from a main project app, can this be done in VS now/or at Upddate 1?
The main app here would have java, so java jni into c++ code and the c++ code into c code and back to c++ code and back to java.
Can this build system make a final apk, when some code is in multiple, native static libraries?
I have a dream... I have a dream... no more Netbeans nor Eclipse to mantain legacy Java code... And you guys are making it happen!
@Lee Van Cleef,
Visual C++ Android development supports static library projects (generating .a), shared libraries projects (generating .so) as well as Android packaging projects (generating the final .apk). You can create project-to-project references between these projects and VS will package all the .so outputs into the .apk. Then in your Java code, you want to make sure that you do System.loadLibrary("foo") for your libfoo.so.
Take a look at this sample for this exact scenario: code.msdn.microsoft.com/.../hello-jni-Android-790ab73d
Awesome! Are there any plans to implement a design editor? If so, would you be able to import projects and UIs from android studio?
Awesome!