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.
Building Java sources
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:
- Create a new project starting with the Basic Application template (under C++ > Cross-Platform node under New Project Dialog)
- Start from one of the Code Gallery Android C++ samples that ship with Java source code
- Import an Eclipse Android project that already contains Java files (under File > New > Android Projects from Eclipse… menu, after installing the Java support extension)
- Place one or more .java files under your “src” subfolder of your existing project folder and then include it in your project.
Editing Java sources (New in Update 1, Experimental)
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:
- Member List will show the possible candidates for import statements, instance members, etc.
- Parameter Help will aid with writing function calls
- Quick Info will appear when hovering your mouse over any symbols
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).
Debugging Java sources (New in Update 1)
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.
Simple answer: No.
No, because I think it’s highly non-trivial thing to do at this moment.
However, I’ve managed to recombine C++ and Java in same project, for one test application, as well as for godot.
See some description here: https://godotdevelopers.org/forum/discussion/comment/21942/#Comment_21942
logcat was not working out-of-box, I needed to use 3rd part logcat extension available in Visual studio market place.
@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: http://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!
Oh. My. God.
@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!
Is there a way to color logcat output? I only see a row which is selected (reverse blue background, white text). Other rows (which is 99% of them) in logcat are (probably) black on black. No other tool-type window has a problem.
High-contrast theme. w81p.
Where is the replacement for the 9 year old WPF that works cross mobile (windows, android, ios) platform which is a first tier platform and not second tier (web browser control and javascript/css/html) app?
Sorry about the High Contrast bug, we're going to fix that in Update 2 of Visual Studio, as the ship vehicle for Update 1 has left.
Thanks
-Ion
Visual C++
Hello,
will this work for Cordova apps with native java plugins ?
Cool, now support layout editing, style editing, and everything else Android Studio has so we can use a decent IDE for Android.
hi all,
are there any ways to include the prebuilt .so library such as ffmpeg to android project on visual studio 2015 ? because i usually build these third party libs on different toolchains(on linux) or use exist lib.
i tried many ways but failed.
And how to create a new source folder on android java project? i can only add folder named "new folder" currently.
thank you very much.
This should work for _all_ Java projects, not just Android. The extension should have a few Java project templates, syntax highlighting, IntelliSense, build and debug support for generic java projects. Can't you take the work this guy has already done? visualstudiogallery.msdn.microsoft.com/bc561769-36ff-4a40-9504-e266e8706f93
I agree…
There is so much great stuff out there that you guys could run with to improve Visual Studio and make it !!THE!! development utility.
why i have Unable to start program 'app_process'.
how can i fixed it?
Did this issue get resolved?
I’m having the same problem.
Tried doing the vs repair, still get the same error:
“Unable to start program’app_process'”
My code is Native C++ plus some java
My debug mode is ‘Java Only’ and yes the build is Debug
My manifest file contains:
The project was built on the back of helloJNISample ABI “armeabi-v7a/NEON”
Any help would be greatly appreciated.
Cheers,
Tony
Missed this bit…
My manifest file contains: ”
I guess the blog strips anything it finds that looks like web code!
Try again:
My manifest file contains: android:debuggable=”true”
The exact error output:
—————————
Microsoft Visual Studio
—————————
Unable to start program ‘app_process’.
The debugger is not properly installed. Run setup to install or repair the debugger.
—————————
OK
—————————
Any solution to this problem? I have (exactly) the same issue, can debug only Native apps…
Cesar,
Although the error message is very generic, one of the common causes we’ve seen is not having the 32-bit NDK installed. Can you please change the installed components of Visual Studio 2015 under Programs and Features in Control Panel, and check whether Android Native Development Kit (32 bits) is installed?
Oleg
Cheers for the info, tried your solution but VS does exactly the same thing :(
Somebody must have a solution for this issue “MS can you hear me?”
More info: running Win 10 with the NIC breaking anniversary update.
the Google ADB driver appears to have problems with Win 10 so I use the fallback Microsoft ADB driver (not by choice)
Developing Java on Android reminds me of early 80’s asm development the only debug tools you had then where prints and change border or background colours… have we moved on?
Not sure if this is still relevant, but I got this resolved, when I closed Android Studio which was running next to Visual Studio.
@wenweiqi, I'd like to ask a couple of questions to figure out the root cause of your problem.
Was your project created using the New Project Wizard, or did you download one of the samples?
Which Solution Configuration (Debug or Release) are you trying to launch?
Are there any errors in the Output Window when you built your project?
Thank you,
Oleg Kharitonov
@wenweiqi, I have the same problem as you.
It happens when you try to debug app as Java Only.
To fix the problem you should repair your visual studio 2015 through "Programs and Features/visual studio 2015/change/repair".
Now I don’t need eclipse to code in Java! Nice job!
Maybe this was obvious to others but not to me. If you’re adding Java code to an existing pure NDK project, you may have an AndroidManifest.xml with this line:
In order to compile Java code in the application, you MUST change android:hasCode to true. Otherwise the build will ignore the Java code.
Ok that didn’t come out right. It’s the application tag in the manifest.
Why can’t I make it work for CMake-generated Nsight Tegra projects? Is there a workaround for that?