Fortran Compiler - android

I am developing an android app on a Mac.
Does anyone know of a fortran compiler for android???
I was going to call some fortran routines from a C routine. Then wrap the C routine with a java class and use the JNI to do this.
BUT, I can't get the fortran code compiled.

Haven't tried it myself, but people have successfully built gfortran for Android. See e.g. http://specificimpulses.blogspot.com/2012/08/something-borrowed-android-fortran.html and http://danilogiulianelli.blogspot.com/2013/02/how-to-build-gcc-fortran-cross-compiler.html .
If the only reason for your C code is to wrap the Fortran code, maybe you could instead just use ISO_C_BINDING (which gfortran supports), and have JNI call that directly (with ISO_C_BINDING you can make code in Fortran that is ABI compatible with C).

Related

Create react-native Native Module in C or C++ using Android NDK?

Must I create a Java Native Interface (JNI) in order to access C or C++ code from a react-native Native Module for Android?
My goal is to re-use common C and C++ algorithms (non-UI ) in a react-native Native Module that supports both Android and iOS. It is simple to call C from an Objective C *.m module, or C++ from an Objective C++ *.mm module. However, a react-native Native Module for Android implements the Native Module code in java.
https://facebook.github.io/react-native/docs/native-modules-android.html#content
The Android NDK allows you to write Android code in C or C++. The Android NDK works well with C++ frameworks such as Qt 5.6. I do not understand how I can cross the javascript to react-native Native Module while avoiding a java JNI?
Thanks in advance for any tips or direction,
I recently had to do this on a React Native project, and I couldn't find a way around it without using JNI. To do so you essentially have to make code for the JS to Java bridge, and then more code for the Java to C (via JNI) bridge, and then back out to JS.
If you're only passing primitives then it's pretty easy as JNI can deal with type conversion, for example a Java int to a jint (which is an int typedef) in C, but if you're passing complex data types then you have to write code to get a C struct out a JNI jobject by telling JNI what fields your class has and what types those fields are. I found easier to write up utility functions to do this. It's a lot of initial setup and boring code, but once you get going and are used to it it's not that difficult. The JNI Spec is great for reference, it just doesn't tell you how you should use it.
I have a github project that uses JNI to pass around some example classes. This blog article explains all the setup steps for JNI, and if you're already comfortable with that, it gets into dirty detail in the "Real World JNI" section. Let me know if you have any questions about it!
If you are willing to do a little extra work you can use Djinni.
This project generates interface bindings for Objective-C and Java. Once you create the wrapper code for C++, you can create Java and Objective-C classes that integrate with React Native. Thus React will call Obj-C/Java which will call C++. Profit.
It will be cool to see how this works for you, I have not seen anyone do this yet.
As mentioned by https://stackoverflow.com/a/36693929/1925631 you can use Djinni, there's even a fork for react-native https://github.com/sulewicz/djinni-react-native/tree/master/example-react-native/ExampleProject

Are there any simple way to use c/c++ source code directly on my android application?

I am currently working on an android application that evaluate images in different aspects, and I found that there are lots great open source algorithms can be used.
Problem 1: Most of the algorithms are designed on c/c++/matlab languages that cannot be applied directly.
I've search that NDK is a tool that allows us develop android application by other languages, but the setup procedures are quite complicated that I stuck for days. So before I go further on it, I would like to first ask whether I can include other's c/c++ source code directly like calling java library?
Problem 2: For example, I would like to use Point Matching algorithm's source code in my application, but there are lots files inside as it's just source code but not library/plugin. What are the steps to apply the require functions in my android application?
(the most desired way is to blindly input some images to the alogrithm, and it returns the results like calling functions, which I dont have to understand the working principle of it.)
You can't directly use other C++ libraries, you have to build them for Android first using NDK. If there is a version of the library built for Android, then, of course you can use it directly by linking to it using NDK.
You have two options here. First, you create a regular Java application for Android, write a C++ wrapper for handling calls to native side and build the necessary source files using NDK. Your java application will make calls to wrapper using JNI and the wrapper will call your actual C++ functions as in Java->JNI wrapper on C++->Your actual C++ source.
Second option is going fully native, which will leave out Java, JNI calls and the wrapper. You can access your source files directly as if you were writing a desktop C++ application. In the end you will have to build using NDK but this step is required in any case.
As a suggestion, you can also take a look at OpenCV for image processing purposes. It has libraries built for Android, all you will have to do is to link them.
Short version.
Download opencv4android library. Import it in eclipse and see if everything is fine (compile errors, output, etc.).
Secondly, try to import face detection application and try to understand how it works.
It has a java part and a native part.
In order to understand how it works you must understand how java interacts with C++, more or less how NDK works.
One important aspect is to learn how to create your interfaces in C++, based on the native ones defined in java. When you got there then you can try creating your own application.
After that you can come here and ask specific questions.

compile Java to native Android instead of writing in C

We are looking for a way to protect our code and obfuscation is not enough.
Is it possible to compile Android java code to a native Android library?
Another option would be to write the code in c and connect with it through JNI ourselves. But the code we have is quite elaborate and well tested, a rewrite to c would start the testing all over.
PS: Before we were running on x86 hardware and used Excelsior Jet as a means for protection. As we want to move to more cost-effective (cheaper) Arm/android hardware we are looking for a simular solution as Jet, which alas only compiles to x86.
In theory you should be able to use LLVM. It has:
A Java frontend
A C backend
In principle, this could do what you need. However I imagine you'd need to distribute (in compiled form) lots of the Java class library. All in all, it sounds really hard. And someone who really wants to read the code won't have too much problem with ARM disassembly...

Connecting a C library to iOS app

I hope there is somebody that can help me with the following.
Currently i have an Android app that is connected to a C library using JNI.
Now i would like to connect my iOS app to that same C library, but how can i call the functions and how can i access the interfaces without JNI?
Hopefully somebody has some good tips or tutorials.
So what i have is an Android App, an iOS App and a C-library adapted to JNI (Java Native Interface). The Android part works. But now i would like to reuse as much as possible but still connect my iOS app to that (or most of that) library. (library are separate header and .c files)
Please help :)
To elaborate slightly on my comment - unlike Android, iOS apps are built using Objective C with Apple's libraries. Objective C is a superset of C, which means that any valid C code is also valid Objective C code. You should be able to add the source files directly to an iOS project in Xcode, and sprinkle library calls anywhere you want. That means there is nothing like the JNI for iOS (or OSX) development.
You have two options:
Directly use your library by adding it to project in xcode, assign a library search path, assign header search path and incude headers in .m objective-c source code that use it.
Add all .c files to be compiled and linked by xcode and incude headers in .m objective-c source code that use it.
p.s. if you have used some particular compiler switches you may need to rebuild your libraries to properly target iOS.

Android C++ and NOT C

I'm trying to decide if using C++ to create an Android app is sensible. I've tried to use Java for what I want, but it simply doesn't have the language features I need.
I see a bunch of things written as C/C++, but everyone of them are actually 'C' examples.
I'd like to build a simple C++ app (NOT 'C') to better understand how to do this in Android. I've read some about the NDK which seems to support C++, but I don't know to what extent.
Is there a sample C++ project out there? One that has real C++ and not C code inside a .cpp file? An "Hello World" program would be fine. Simple is good to start.
Please pass by this question if you want to answer with how C++ wraps a 'C' function. If the example doesn't address name mangling, it's not C++. No extern 'C' please. Thanks for understanding.
NDK works really fine. It is so simple that you have your .cpp and .h written in C++, compile them with ndk-build, and you have your android code including the cpp's like explained this tutorial shows:
Good luck:
Part 1
Part 2
Official documentation: Sample applications

Categories

Resources