How to debug Android Studio Project (using NDK and JNI) line by line to see the workflow? - android-studio

I was using Visual Studio and it's Debug mechanism is really useful to me. With many header and C files in 1 project, just a simple F10 it could take me a tour around from the beginning of the main() function so that I could see the sequence of the code being executed.
Now I'm jumping into Android Studio and start with a project using NDK, JNI (this project for example: https://github.com/googlesamples/android-ndk/tree/master/gles3jni), it makes me confused because there're many .java files and others C++ (native code) files and I don't know which code from which file is executed first and how it goes on.
My Question is: I'm looking for a way to debug in Android Studio line by line from the beginning to see its workflow likes how Visual Studio did but all I got from searching is how to start from a breakpoint when debugging.
I have tried putting the break point in the onCreate() method of the launcher activity and use F8 to Step Over and F7 to Step Into but it doesn't work as i expect. It keeps taking me to the super class Activity.java and GLSurafaceView.java instead of taking me to the C++ code. Is there any way to do so in Android Studio and how to do it?
I have tried with others project but the problem still remain the same. Hope someone could help.

This won't happen. Your app (the Java boilerplate code) is set to respond to many system events that happen when the user works with the app and the device on which the app is installed. If your c++ code is a piece of monolythic straightforward algorithm, you can set s breakpoint in the beginning and really follow step by step. But with Android Studio, even this process is not as easy as with Vusial Studio. To begin with, it's always remote debugging, dependent on delicate communication protocols.
This said, you can try to set up Microsoft Visual Studio as your IDE for debugging native Android code. It is surprisingly robust, and also may be more familiar to you.

Since you've asked about Android Studio, I will answer about that - I am not familiar with Visual Studio for Android and perhaps it is better for what you are asking.
In Android studio such debugging is very hard - although some people said they managed to get it to work, I wasn't able to. Especially in a complex environment. So, what I'm doing is extensive logging, with as many details as possible, and visual debugging - put some text view on the screen and update it with the info you need. This could be quite powerful in some cases. Or, alternatively, make some changes in your ui or your scene as a result of certain conditions you define - so you could see the visual effect. Again, much less useful than debugging, but can still be quite powerful.

Related

VS Code Flutter shortcuts equivalent to Android Studio Flutter

I am looking for a few things to improve my productivity, Android Studio has these features and it really sped up my work, if you know any of these please share.
Ctrl+Shift+Space equivalent in VS Code Flutter. What it did in Android Studio was auto complete a statement. For example if I typed in if and then hit Ctrl+Shift+Space, the if condition code block would be completed for me automatically with () and {} after it, with putting the cursor within the condition.
Code snippets for things like for loops. On Android Studio you could type in iter and then Tab, it would create for (var _ in ) {} and automatically jump to both variables to fill their names on two Enter keystrokes.
These were great for me, please share if these exist in VS Code, as I understand it is supposed to be superior.
You should install dart extension for VSCode.
In order to prioritize the extension snippets and have these ones for the first suggestion, go to File/Settings/Text Editor/Suggestions and set Snippet Suggestions to top. Now it looks like

"Run|Debug" Buttons Not Appearing on Visual Studio Code Java Programs

A couple days ago I tried to initialize Visual Studio Code to be able to code in C++ using online instructions. They ended up not working at all, but I had edited some settings files (such as a .json file) in Visual Studio Code that I thought were all C++ specific. Afterwards, however, I no longer have the convenient "run | debug" buttons appearing above any "main" functions that I make in java files. In the past I used to be able to just click run and my program would run in the terminal at the bottom of the screen, as opposed to manually compiling and running the program using a terminal. I am running Windows 10. Does anyone know of any way to get these buttons back?
This is an example of what the two buttons look like, appearing above any main functions in a java program.
I also found on the Visual Studio Code website a description of how to begin debugging, attached here, that describes that you need Language Support for Java(TM) by Redhat in order to get these two buttons. I have this extension downloaded, but it is still not working. Please help if you recognize this issue!
What worked for me:
Make sure you have Java extensions, Java Debugger and other basic Java packages installed.
Then making sure the main function is formatted properly like below allowed the Run|Debug buttons to be seen.
public static void main(String[] args) {}
First of all, for troubleshooting, actually we need to have a reproduce steps which can understand what happened in your environment. So can you tell us what you have done to your settings first?
Second, there is a setting under common setting tab, that is Java>Debug>Settings>Enable Run Debug Code Lens. Please check whether this option has been unchecked. Although I think it should not be changed by you.

Extend Visual Studio functionality for Installshield ISPROJ Project type

InstallShield must be the crappiest "industry standard" application in existence, for reasons too numerous to enumerate here. However, one of those deficiencies is something I'd like to be able to fix, and with my first foray into writing an extension for Visual Studio (currently using 2015 version).
InstallShield has created a .isproj type, to allow integration with Visual Studio. This allows a developer to create an installer that references the output of a project as the files to include in the installer (rather than having to manually select individual files to include). This works well enough as long as the .isproj is being built in Visual Studio, and in a solution that references the project for which you need the output.
However, I also have an automated build for my installer projects, that we run on a build server using MSBuild. When attempting to build this way, we were getting completely opaque error messages indicating that the project output references above couldn't be resolved.
As with all InstallShield errors, Googling for answers turned up nothing except for multitudes of other people having the same problem. So I decided to dig into the plain text of the .isproj to see what I could find.
As it turns out, the .isproj type is a just a regular MSBuild script, and it even has lines commented out that explain options that can be added to the project; one of those things that can be added is an ItemGroup containing ProjectReference nodes. Manually adding the nodes helped solve the problem. Command-line build now works.
However, I am dissatisfied with a) having to manually type this stuff in, b) having no visual representation of what projects are being referenced, and c) not finding out about a problem until the build fails. So, I would like to be able to extend Visual Studio to help me with this. Here's what I'd like to do:
1) Add a "References" node to the project in Solution Explorer that acts like the References node for any normal .csproj.
2) Restrict the available References to other projects in the the current solution.
3) Visually represent a project with missing references (e.g. by underlining the project name with a colored squiggly, as with errors/warnings), and potentially failing the build if missing (depending on whether I want to treat it as an error or a warning; TBD).
To these ends, I've downloaded MPF for Projects - Visual Studio 2013, which provides an SDK for creating a new project type.
However, before digging too deeply, I need to know if it's even possible to EXTEND an existing project type, as described above, as I obviously don't have InstallShield source code. Also, any links or guidance as to a starting point for doing so would be greatly appreciated.

Any way to circumvent inbuilt auto save in android studio?

The current Android Studio version has inbuilt auto save. Which means if you close a file, it will automatically save the changes.
This is inconvenient, it means when experimenting with code, all changes need to be noted as there's no option to have a dialog requesting to save changes on closing a tab or the project, as in many other ides.
According to documentation IntelliJ IDEA 15.0 Help/Saving and Reverting Changes:
When does IntelliJ IDEA auto save changed files?
Autosave is initiated by:
Compiling a project, a module or a class
Starting a run/debug configuration
Performing a version control operation such as pull, commit, push, etc.
Closing a file in the editor
Closing a project
Quitting the IDE
.../...
Note that those are optional autosave triggers, and you cannot turn off autosave completely.
These are the auto save settings that can be changed in Android Studio:
TLDR
Is there any work around to circumvent this autosave?
These questions are related, but do not acknowledge that this intended behaviour of the ide and are rather asking for fixes within the ide.
Related:
How to disable Auto Save save in Android Studio
How turn off autosave in Android Studio?
If you want to experiment, use the revert button at the top right. This works especially well if you are using a VCS (like git...) as it will revert to the last committed version. And since commits are still manual, this will soon replace your traditional save.
If you are not using a VCS the point in time to which it reverts is a little more arbitrary, but in my experience it takes a pretty good guess. If that doesn't suffice, you can use the history button next to the revert button, which keeps track of every version IntelliJ saved, and you can then go back to any point in time you like. :)
Android Studio as a software is very much based on the JetBrains software solutions such as IntelliJ (used for Java) and PHPStorm (used for PHP, as its name shows).
As a concept in itself, JetBrains have implemented this feature and as a company believe that it's much more efficient and productive than manual save. Hence, there is no way to disable this behavior or enable any confirmations in Android Studio either.
Taken from JetBrains FAQ for IntelliJ:
Because IntelliJ IDEA has the ability to change so many files simultaneously in large refactoring actions, and change them without ever opening them, single file saves don't make very much sense. In recognition of this, IntelliJ IDEA reserves the right to save any of your files literally whenever it wishes. It's actually quite nice to never have to worry about your file's save statuses, once you get used to it.
Having said that, and encountering this issue myself too as a developer, I agree that it would be a good idea if the Manual Save feature were enabled by the Android Engineers (or JetBrains themselves). After all it is up to the developer to choose whether he needs this feature or not.
To Jetbrain's defence, they have a very good Undo function through their Ctrl + Z shortcut keys, letting the developer go back many steps and find where a certain error has occured.
All IntelliJ based products nowadays save any opened or modified files whenever they wish - read this as "immediately".
I would suggest you give up on trying to disable it (trust me, it's not possible to hack it) and either change your work flow or work on copies of the files.
As background I should mention that I am a plugins author for IntelliJ (with 3 publicly released plugins in the JetBrains repository) and thus have a reasonable understanding of the internal IntelliJ architecture.

Displaying build times in Visual Studio 2013?

I am using Visual Studio 2013 to execute c++ code.I want to see the execution time of my code.
I performed the following activities
Tools -> Options -> Projects and solutions ->VC++ Project Settings->Build timing->yes
**Tools -> Options -> Projects and Solutions -> Build and Run and set the MSBuild project build output verbosity to "Normal"**
but it's not working for me.
I use Squared Infinity's VS Commands Visual Studio extension which has an option to display a build summary in the output window that lists the time each project took to build.
If you want compilation time, as the title of your post suggests, you're in the right direction. You may want to look at this thread for further help.
If you want to know how your code performs at runtime, that's a different story. You can either insert use datetime variables along with print commands in your code to see the elapsed time in a console window (not very pretty or efficient) or use a profiling tool (much better IMHO).
Personally I use RedGate's ANTS Performance Profiler and am quite pleased with it. :) I should mention I never tried it with managed C++ but it should work just fine.
Visual Studio also has a built-in profiling tool, but I never tried it myself. You might want to take a look at it.
Hope that helps.

Resources