Android How do I use the same native library (.so) for multiple projects and classes? - java

I am making a android project with some native code . running javah results in header files which contain function prototypes with fully qualified java class name in their names. I assume this means that those functions and headers are generated to be called only by the java class which was used to create them using javah.
How do I go on making a native lib that I can use with other classes as well as other projects. Like say I made a library that has a function that I want to use in all my projects then how would I build it so that I can use just the .so file each time without recompiling it for the project. I think we call this dynamic library?
Is it possible? or do I have to create seperate jni headers for each class and then reuse the remaining c/c++ code?

if you want to reuse your native library from various Java projects, you should directly bundle your native library with a Java class that is independent from your initial project.
This way you'll be able to distribute it as an Android Library Project, and use it from your various classes and projects.

Related

Is it possible to use links file java class files instead of copying them into project in Android Studio?

I have many java class files written by me for common purposes which I need to use very often in my Android projects. These classes (let's call them 'library') has many static methods in them and I call these methods when I need them in my Android Studio projects without any problem
When I create a new Android Studio project I copy all those library files into the Java folder of my new project. So, I can call them with the syntax like classname.methodname() at any time in my projects (in activities, in other java classes, etc)
The question is that this technic causes many independent library files in each project. This means that, when I have added a new method or changed a method, I need to do the same thing at each library files in each project.
As I am new at Android Studio and I am playing with that at the moment, this might be ok. But in real life, this will be impossible in the near future while I was struggling with many projects.
I am sure that, there should be a way to use file links instead of inserting these library files by copying them into the Android projects. So, making changes in a source library file will affect all projects at once. Something like $I directive in the C type languages...
Is this possible and if yes, how?
Thank you...
One good way would be to create your own library/module in android studio.
Here is a link for that : https://developer.android.com/studio/projects/android-library
And another way would be to create your own JAR file.

Java call of .NET

I try to use a .NET Library in Java. Therefore, I use JNI calls of a C++ project which refers / uses a DLL of the .NET.
To use the .NET Library I have several steps in-between. First I use C# project as a ‘wrapper’ instance between the Library and a C++ project. The C# project creates a DLL.
The main wrapper C# class (CSHARPWRAPPERSession) is [ComVisible(true)] and has a fixed GUID [Guid("XXX")]
Out of this ‘C#’-DLL I create a TLB file.
This tlb file is imported by my C++ project.
#import ".\CSHARPWRAPPER.NET.tlb" no_namespace, named_guids
When I create an exe out of the C++ project I can use the wrapper perfectly and call the needed .NET library.
Now I try to make a connection between the C++ project an JAVA. Therefore, I use JNI and created DLL out of the C++.
This leads to the error 0x80040154 – Class not registered.
This error happens, when I try to call CoCreateInstance(CLSID_CSHARPWRAPPERSession)
I have registered all used Libraries with regasm and done a gacutil on it.
What am I doing wrong? Any ideas or suggestions?

How to use external jar library in a SAP HANA XS project

I am trying to make an XS project in HANA which will use some of the classes and methods that can be found in a .jar file. These classes and methods will do some calculations and present it to the user in the UI.
The question is: How do I access methods and classes of that .jar file?
I have registered it as an external library, but I have no idea how to call it from my XS javascript source files.
there's no way to invoke external .jar package from XS's server-side JavaScript. You can use an external library using function "$.import", but this is only valid for JavaScript library.
XS Server does not and will not support Java. Only Javascript...
If you want to outsource some of your xsjs functions to an external library, xsengine provides a special format for this, called ".xsjslib".
You can import a library using the following code:
$.import("<package_your_library_was_deployed>","yourLib");
access functions inside your lib by this path:
$.path.to.your.library.filename.yourFunction();

How can I use Android with Java and a core made with Scala?

I made a small project using Scala (SBT + IntellijIDEA) that provides me a set of classes and other functions that I want to use in Android. I will call this project $core.
So, keeping that in mind I tried to first only use scala. I tried to create an Android Project using android-plugin and I got it.
But what I really want is to use my $core in an Android Project AND expand the $core classes using Java. $core provides an API that I would like more people to use and they probably don't know Scala so Java would be perfect. Besides, I need to go into a safe route with Android. I saw some info that scala takes a lot of time to compile into Android and has some limitations (like with parceblles).
I already tried to use the classes in eclipse with the import class folder option. I even tried to generate a jar so at least I would have a way to run it and no success. Always the NoClassDef error when I try to use one class from the $core. I have tried to import also the scala compiler library, but didn't work out aswell...
Core isn't finished yet and I would like to develop on a single environment that allowed me to debug on the android device. How can I setup all of this?
PS: Changing to eclipse now maybe is better? Never tried android on intellijIDEA and In scala I can't debug over there, at least using ScalaCheck...
Is it possible that you are getting an noclassdeffound error when working with Scala code from java because you didn't add the Scala library to the java project or at least included the party of it that it's used in the Scala code in the jar?
Could you post the rest of the error?
You could package the core to .jar together with Scala library, use Proguard to remove all unused Scala library classes from it, and then use that jar as a regular library.

Make package for Android

Problem Description
I'm writing module for Android (JAVA) that use native code (C). In JAVA I have created Class "MyClass.java" and implement all functions and classes there, also I call loadLibrary function from that file.
Now I want to build something like dll in C only for Android JAVA in order to give it to other users and they can use my class and functions.
You probably want to create a library project that contains your Java and C stuff.
http://developer.android.com/guide/developing/projects/index.html#LibraryProjects
Do you want it to be used at runtime or compile time?

Categories