I am working on an Android Project which makes use of the NDK and binds the rather large Boost C++ library. Upon every startup of Android Studio, the IDE takes a rather long time of about 1 hour (more or less, on an i7 quad-core machine) during the Building Symbols stage, during which it is effectively impossible to use the IDE. I guess the bottleneck is directly related to the huge number of symbols included in Boost.
Is there a known remedy to this problem? I have not seen many complaints about this problem, but this forum post seems to ask for help for the same issue: https://forum.xda-developers.com/tools/android-studio/android-studio-2-2-add-cpp-files-using-t3499634
I am facing the exact same issue - after upgrading my Android Studio installation to 2.3.3 yesterday, opening my project now faces me with at least 30 mins of "building symbols" at which point the IDE is effectively useless.
I can build the project via gradle commands in terminal, so I have no idea why this step is mandatory in AS.
I read that this may have something to do with using the NDK build (Android.mk?) vs. CMake (CMakeLists.txt), but I have not yet been able to convert over my .mk file to test this out. This is a legacy project, and the NDK portion is still somewhat of a mystery to me :(
Related
I'm writing an Android app that includes C/C++ code that is compiled alongside the Java code. My app is crashing during the execution of the native code.
Is there a way to step through Android C/C++ source and inspect variables as it is possible with Java source?
I am not necessarily looking for a way to step through the source from within Android Studio. That is obviously the ideal solution, however, if I need to use an external tool after starting the app from Studio, that's fine. I want to be able to step through the execution line-by-line and inspect variables.
Android Studio 1.0.2
Android NDK r10d
Edit: Stemming from the immediate response of, "Use Eclipse with ADT plugin", let me add more requirements.
This project started as an Eclipse ADT project. However, I have now migrated to Android Studio. My project is now built using Gradle, and my project directory structure reflects this. I am willing to use Eclipse; I am not willing to change my project structure in order to revert to Eclipse from Android Studio. If there is a way to open the Android Studio project in Eclipse and debug it that way, please elaborate on the process.
[UPDATE]
As of July 2015, Android Studio DOES support NDK.
You can learn more about it on this link.
[OLD]
NDK is not yet supported in Android Studio.
When we have to deal with NDK, the only solution is to use Eclipse.
EDIT
We basically keep Eclipse project with NDK feature (map in our case) and Gradle project with other (non-map) features. So everything that has to be done with NDK, we do in Eclipse and then include changes into Gradle project.
To be more precise, inside directory /src/main/ we created another directory called jniLibs and put the compiled *.so file inside architecture-specific folders (armeabi-v7a, armeabi, x86...). Then in the main class of Gradle project simply added a line
static {
System.loadLibrary("OurNDKLibName");
}
You can add this line only once per project. Maybe I am wrong but we did not have any issues for doing so.
As of version 1.3+ Preview Android Studio supports C++ debugging, quoting Android M Developer Preview & Tools:
Most notable is a much requested feature from our Android NDK & game developers: code editing and debugging for C/C++ code. Based on JetBrains Clion platform, the Android Studio NDK plugin provides features such as refactoring and code completion for C/C++ code alongside your Java code. Java and C/C++ code support is integrated into one development experience free of charge for Android app developers.
It isn't wasn't isn't working very well.
hello-jni fails failed with:
Starting LLDB server: run-as com.example.sample
/data/data/com.example.sample/lldb/bin/start_lldb_server.sh
/data/data/com.example.sample/lldb
/data/data/com.example.sample/lldb/tmp/platform.port1442695333842 "lldb
process:gdb-remote packets"
Error while launching debug server on device:
com.android.tools.ndk.run.DebuggerContext$StartServerException:
java.lang.IllegalStateException: Failed to read platform port
/data/data/com.example.sample/lldb/tmp/platform.port1442695333842
I'm using 1.4RC1
compileSdkVersion 23
buildToolsVersion "23.0.1"
And the "app-native" run configuration #Gerry mentioned. It's nearly there, but I can find no trace of an lldb directory in my app's private data folder. I do find a 400kb gdbserver in the lib directory linked from there, with my own *.so right besides. Unfortunately the option for debugging with gdb instead of lldb has gone with the upgrade from 1.3 to 1.4. NDK 10e ships a 400kb gdbserver binary in ndk\prebuilt\android-arm\gdbserver which it is (I guess). On September 15th the gdb debug howto https://github.com/mapbox/mapbox-gl-native/wiki/Android-debugging-with-remote-GDB was updated. This is harder than logcat debugging IMO, but a current topic, sorry to be so negative but I don't believe lldb actually works yet.
I have run hello-jni and reached the same conclusion.
So in answer to your question, it is not yet possible to debug C/C++ in Android Studio. Sorry this wasn't the answer you hoped for and I hope to be proved wrong with conclusive evidence to the contrary, but right here, right now, no chance!
UPDATE I raised an issue where I was given a fix for one phone.
UPDATE2 Too early to tell, it is experimental after all, but I am occasionally failing to connect, often if not always getting out of order stepping and breakpoints with nonsense parameter values. I just set a conditional breakpoint that didn't fire but the logcat shows it should. Initially I assumed it was my logical error, but it goes deeper.
Simply hitting breakpoints at all is very helpful but it is still a million miles short of Java debugging, or Vis Studio C++ debugging.
UPDATE3 Gone back to stable 1.3.1 as the canaray channel version was pausing for a toilet break every keystroke. While native debug build at least launches with my "fixed" phone, no breakpoints are hit even in hellojni, or a slightly extended version to give more opportunity. I'm used to logcat now but have had better degbugging experiences with Android, NDK and Eclipse. A more elaborate solution is also easier to break, but at least it works.
Yes, Android Studio does support C++ debugging at least with Android studio 1.5.1 and android-ndk-r10e.
In the old days, you will have to write make files Android.mk and Application.mk in order to build the C++ code in Android Studio. You don't need them any more. As long as you put them under the jni folder, gradle will be able to pick it up and compile it. You should see something like the following:
And also allow you to set break point and debug it.
You should follow this step-by-step tutorial and learn more about it. And read more about the documentation here. I've uploaded a complete working example so that you can download and try it out on GitHub.
With Android Studio 1.4 from tools.android.com, debugging is possible. When you open/create a project with C++[jni] code in it, Android studio would create a new configuration, something like $(module_name)-native
I would select this configuration, sync gradle, build, set breakpoint etc and run it with Android Studio. After a long wait, my debugger is connected, app is broken in[I think you could also set breakpoint at this time]; this break is not at my set break points, I let it go in android studio and my breakpoint is hit. Hope this helps
Some samples are supposed to work with android debugger
yes! it is possible to debug native code in android studio. As from the updates Android Studio 2.2+ support in built tools for debugging native code.
I use eclipse for my android development and have a 32-bit Eclipse Juno setup where I can debug my android app via the emulator. The android app uses maven for it's build and works properly.
I recently got a new laptop and installed the 64-bit version of Eclipse so I could increase the amount of memory available to it. I have installed the same plugins (from what I can tell) and made a copy of my old workspace to make the transition easy. However, when I try debug the android project I get
trouble processing javax/xml/namespace/QName.class
Conversion to Dalvik format failed with error 1
I've tracked the root cause of this error to the fact that eclipse is including the xpp jar into the apk even though it was marked as "provided" in my pom.
When I view the pom dependency heirarchy from the 64 bit install showing it as "provided"
(don't have enough points to post a link to this)
But the libs view from the 64 bit install shows that it is getting exported anyway (bad) 1
Finally, here is the libs view from the 32 bit eclipse install showing that it does NOT get exported (good, proper behavior) 2
Been looking at this for awhile and am completley stumped as to why the 32 bit install works properly but the 64 bit one insists on exporting the provided jar. I really thought copying the working workspace would solve it, but apparently there is something else going on here.
Any help is greatly appreciated!
The solution to my particular problem was to create an empty workspace, check the project out fresh from svn, and rebuild from scratch.
Apparently me cloning the old workspace did more harm than good.
I am using Xamarin Studio with Xamarin.iOS and Xamarin.Android. My workspace contains two solutions, one for android, another for ios. Projects are pretty much the same. When I build the solution for ios, it rebuilds only changed projects. It does some additional operations which take really little time. So pressing Build second time takes virtually no time.
But when I build the Android solution, it rebuilds all projects regardless of changes in files, configuration and so on. If I press Build after successful build, it rebuilds it all over again. Even worse, if I try to Run a just built project, it rebuilds it! Furthermore, if I run the project after run (when you debug a program, it happens often), it rebuilds it again. As I have many projects, it takes really long time, plus the compilation is very CPU-dependant, so improving speed is hard.
Generally, the question is if it is possible not to rebuild entire solution upon every build? Maybe there is a configuration option I am missing, or something is misconfigured?
I don't know if anything in projects configuration is relevant to the question, so please tell me what part of solution/projects configuration may help.
Versions:
Xamarin Studio
Version 4.0.9 (build 12)
Xamarin.Android
Version: 4.7.11 (Business Edition)
//I thought that separate compilation nowadays is a must in every serious compiler, so I assume, I have done something wrong.
UPD:
I have installed latest versions of Xamarin Studio and Xamarin.Android:
Xamarin Studio
Version 4.0.12 (build 3)
Xamarin.Android
Version: 4.8.1 (Business Edition)
It takes 1 minute 58 seconds to rebuild the android solution. Every time when I run the application.
Honestly, this sounds like a bug in Xamarin Studio or the xbuild build tool, at least, assuming you don't have any custom build steps (which you probably don't)? Could you file a bug report on https://bugzilla.xamarin.com? Thanks! It really shouldn't rebuild the project each time.
I'm really happy to hear that your iOS project doesn't rebuild, though, because I'm the maintainer of the iOS build code :-)
I would think the reason for complete rebuild, when you want to run is because an APK file is not generated when just rebuilding. It is first generated when wanting to either deploy or run the project.
It's not a bug, I have the same features, and I have wasted lost of time waiting for each run in debug mode. I think using Xamarin has cost me 10x more time than using any other development environnement cause of tons of problems like this...
It's an unprofessional tool.
When we first started developing for android, we had 2 projects:
One for the 'core' functionality, other for the 'business' functionality.
So far so good, we went through bad times waiting so much time for compilation of XML changes, but life was still quite bearable.
After some time, we evolved (or not) to come with 9 projects. For some projects, we have a 'test' project.
We also have some library projects, for instance, we have two different projects for different versions of android, and we have a 'shared' project for shared configs or controllers.
The reason for that is because our application is quite big.
When we make some changes on the core project, we usually have to recompile, and 'clean' the workspace with eclipse. Also, we usually have to use the 'Build Project' option a few times for the projects to update their references, the first build hardly compiles everything, we call this in our team 'COMBO', which is the combination of 'F5' and 'CTRL+B' to compile the projects.
All this setup is killing a lot of time and making developers sad, like, a team of 6 developers :(
I know that by this time we should pretty much know all the issues and the best options, but I can't believe the way it is. And after so many time searching and trying to improve, we can't seem to find other solutions to improve development time with android.
Our set of tools is:
Eclipse 4.2.1
ADT 21.1.0
Eclipse Colour Themes (for a cute code)
SDK always updated
Hardware:
Windows 7 Professional 64 bits
8 GB RAM
Intel Core i5-3470 3.20GHz
I would love answers about:
Compilation time improvement: Did you found any IDE that for YOU it was faster than eclipse? Why? How was the setup? What are the drawbacks of using ADT and how can I improve performance with it, while using multiple projects?
Project references management, is there any suggestion on how
to speed up build? Should I put the whole source code in a single project?
Any way to speed up development when you have the device and need to deploy it while testing the application?
Try Intellij.
In the latest version, 12, they made project build improvements that make it much faster than 11 and Eclipse.
Parallelization
Note also the third column, called Parallelized. This
is a new compiler option which allows you to use more than one core
for building a project. In this case the compiler runs for multiple
independent project modules in parallel. Since each compiler thread
uses file system, the benefit of parallelizing highly depends on how
fast you hard drive is. Still the average gain in performance is
spread between 10 and 20 percent for large projects.
Automatic Make
One more exciting compiler option added in IntelliJ
IDEA 12 is automatic make. This is another time-saver, which triggers
project make automatically on every change. Since the compiler runs in
a separate process, it is able to compile modified files in the
background, while you are doing something else. This means your
project is in compiled state all the time, so you don’t need to wait
any time you want to run it.
http://blogs.jetbrains.com/idea/tag/brand-new-compiler/
Also if you are using git for version control I have noticed Intellij is much better at updating after I switch branches. It integrates well with git and notices that you switched branches and refreshes and cleans out the project in the background automatically, while on Eclipse you might have to refresh and clean manually.
In the last few days I have noticed some very strange behavior in my android project:
After every single little change of an xml-resource, the building of the android application's workspace takes a long time.
The changing of java source files doesn't cause the same slow building
And I have no idea what's going wrong.
I have already cleaned that project but it didn't help.
Is there any way to find out what is making the build process so slow?
P.s.
At about 89% i see the building message invoking 'Android Pre Compiler' on 'proj. name'
I've dealt with various eclipse problems before that slowed it down. A couple things to recommend, enable advanced garbage collection and some of the other items recommended for a performance boost in this article How can you speed up Eclipse?.
Try enable verbose build output in your preferences for android>build to see if any of your specific resources are the bottleneck.
Although I was unable to find the article, I've read about using eclipse in debug mode and profiling the IDE as you work to see if any plugins are causing interruptions.
Last, I have used the community version of intellij idea 10 http://www.jetbrains.com/idea/ which has strong android support. It's much faster than eclipse for most tasks, but doesn't have as much embedded android support (you must use ddms as a separate tool, no UI builder, etc...)
Increase Xms and Xmx parameter in eclipse.ini file.
My default values was:
-Xms40m
-Xmx256m
My new values are:
-Xms256m
-Xmx1024m