Is is possible to build Android games in Go using the NDK with cgo and/or SWIG or similar? - android-ndk

Is it possible to use Go to build Android games at all? I'm not wedded to the technologies mentioned in the subject line. I know that some people have built some Android programs in Go, but they may have been headless.

No, it is not possible right now. Go and C programs can interoperate via cgo. but in that case, the Go program has to start and initialize its runtime before passing control to the C-based part of the program.
When using the NDK in Android, your C code is called by the Dalvik virtual machine via dlopen. So the Go runtime would not have a chance to initialize itself.

If you want non-headless apps, my advice would be to use cgo for the GUI. That sounds counterintuitive, but if the NDK supports C android gui libraries, it'd probably be easiest to write the GUI using those calls. Of course, you don't have to write all the logic in C. You could simply cgo wrappers for each of the GUI calls and then write the GUI in go, except that each gui call would be translated through cgo.

Related

Java to NPAPI for Chrome Extension

I was wondering if it is possible to make an NPAPI plugin from a Java project (Since java can be compiled straight to a dll with the help of gcj)? I already looked at the mozilla page describing NPAPI plugins but I could not find anything related to Java. All the tools over seem to focus on C++ projects.
Thanks in advance.
The tools and examples focus on C/C++ because NPAPI is a C API. There's no way to make an NPAPI plugin purely in Java.
If you really wanted to, you could probably write a bridge layer in C using JNI, but that means you'd need to have your plugin start a JVM. If your plugin were running in a browser that doesn't run plugins out-of-process though, you'd potentially be running two JVMs in the same process, which might not end well. And getting the drawing right across the bridge will be a nightmare, at least on the Mac.
Before trying to go down that route, you should ask yourself why, if your goal is to run Java code in a browser, you aren't just using the Java plugin.

Android: is there any tool for profiling native code?

I have only found one profiling tool - http://code.google.com/p/android-ndk-profiler/. Wasn't able to get it working so far, so I wonder if there are other tools available.
I need to profile on a physical device, as my application doesn't even work on emulator.
It is not easy to make the Android-NDK profiler work. You need to follow the steps here thoroughly.
Here are some tips that led me to success:
Make sure your android.mk is correct and that you export the NDK_MODULE_PATH.
Use correctly the following functions
monstartup("your_lib.so");
moncleanup();
If the gmon.out is generated now you need to pull it from the device, but not to anywhere in your PC. For me it only works if I go to the application's folder (where jni, obj, res and other folders are) and I do:
console$ adb pull sdcard/gmon.out
Then run gprof. Try will all the versions in your NDK toolchains. For me only one worked, this one:
console$ ~/Libraries/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gprof obj/local/armeabi-v7a/libxxxx.so > profile.txt
The Shiny profiler is platform independent, it runs anywhere and it does not have any dependencies besides a standard C++ compiler. In its more simple usage, all you need to do is add a macro at the beginning of all functions and methods (or at least those that you want to profile).
Intel VTune Amplifier. This profiler allows you to collect hotspots with stacks on Android devices without root or any OS modification.
Here is simple guide:
http://software.intel.com/en-us/articles/using-intel-vtune-amplifier-on-non-rooted-android-devices
In the NDK r13b there is a new tool called simpleperf

is it possible to use a visual studio 2010 c++ code on a linux machine?

Newbie here. I made a project in visual studio 2010, and it works perfectly. Now i need to compile and run this code in a machine that runs ubuntu. Is there some export/import method, or how does it work (of course assuming such thing is possible).
What i am thinking is making a makefile in visual studio, then take the code and compile it in ubuntu? does such thing make sense?
Thank you in advance.
In an ideal world, the code is independent of any IDE or build chain, which keeps its own metadata saparate. Windows doesn't play nice with Linux.
On the other hand if you set up your project with CMake or something like that, then you can generate Visual Studio projects for a given code base just as easily as Linux makefiles.
You shouldn't need to change much code itself. Or, at least you should be aware of what is windows-specific. You probably will have to expend some effort in creating your CMakeList.txt or whatever you end up using, but it's pretty easy once you're familiar with it.
If you mean take Visual Studio source code and compile it on Linux: the answer is yes, though there may be anywhere from zero to a lot of work to make the code compile properly and run. It all depends on programming choices. Unfortunately, standard practice with Visual Studio generally is to use the most Microsoft-specific API features, thus greatly complicating porting to a POSIX or Linux environment. It is possible to make most non-GUI choices very portable, however a GUI intensive program is the least portable unless a cross-platform GUI API is used.
If you mean take the resulting .exe file output from Visual Studio and run that on Linux, that is usually much easier. Install the Wine package, (yum install wine or whatever the Ubuntu equivalent is) and fire up the program with wine program.exe. I have had very good luck (98+%) running Windows programs this way. The major exceptions are Microsoft software: in particular Visual Studio uses many non-standard Windows API operations, so much so that the Wine developers call VS's support level "garbage", a surprising outlier considering the number of Windows games which are well behaved and run under Wine straight out of the box.

Can I invoke another software using C++ and can I interface my c++ code to a gui?

My application would run on Windows. Would I be able to invoke and run another application (say,provide the files selected by the user in the GUI to Matlab) using system() command while my C++ program is still running?
Can't SPAWN() and exec() do the job?
Does VisualC++ provide some mechanism or libraries to interface GUI with my C++ code?
Can you suggest me some compiler to do the job?
Can you suggest me some tutorials on QT or FLTK?
Sure under windows you can start a programm using CreateProcess (which is more low level) or ShellExecute (which is simpler).
If you want to create a GUI with Visual C++ the simplest thing is to use MFC. Is is not very beautyful (neither the gui, nor the code) but it is simple to develop since you have designer support.

MFC like easy to use tool for Linux

When I used to write test tools in Windows, I use MFC for creating the front-end GUI. This made development of GUI development very fast, and I always used to concentrate on the back-end. Recently I moved to the console based Linux-world. Where most of the things are just console based.
My question: Is there any easy to use equivalent of MFC in Linux?
If you are used to MFC, you will LOVE QT.
http://www.qtsoftware.com/products/
There are a lot of alternatives.
I like wxWidgets. Others will recommend Qt.
Another option is to use Glade to build GTK+ or GNOME applications.
I've never used MFC, but supposedly the wxWidgets toolkit is somewhat MFC-like. Though I prefer Qt over wxWidgets as IMHO the API is nicer, more complete and better documented, and the Qt GUI builder is pretty good.
A nice thing with both Qt and wxWidgets BTW is that they are both cross-platform toolkits; they work on Linux/Unix, Windows, OS X, and maybe other platforms as well.
There's a a huge omission here! gtkmm, the official C++ binding to GTK+, is arguably the modern C++ GUI kit, since it goes out of its way to really use and evolve with the language. For those learning modern C++, it's the best counterpart to the stdlib. It grabbed and kept my interest, where no other GUI lib could, due to its modern and clear API. And it'll work wherever GTK+ does - a tonne of places. I'm glad to have built my first ever (and not trivial!) GUI project around it. It also provides sigc++, which I imagine is really powerful for custom signalling/event systems. Disclaimer: I'm just a self-taught user.

Resources