Calling 3rd party native library in your own android app - java

Is it possible to write code for native libraries you do not have the source code for in your own android app?
For example - RarLab's android app comes with a native library librarlab_rar.so for at least 4 different platforms.
Assuming that I'm doing this for experimental and copyright isn't an issue and I don't plan to distribute the app externally, is it possible to compile a Java/Kotlin android-based app with only including the native binary in android development tools such as Android Studio or Eclipse?

You would need to disassemble the binary .so file and work out the API yourself. This process is called reverse engineering.
See: How do I reverse engineer .so files found in android APKs? for ideas on how to accomplish the task.
Once you've figured out how to call into the .so file, you can then write your own version of the API which you can then call from Java/Kotlin.

Any lib….so file that you put under jniLibs/$(ABI) folder in your app will automatically get packed to APK and unpacked to the device (provided the ABI matches). You may need to write your own Java wrapper for the libraries, or to reuse the Java classes that you need from the same app.

Related

Uploading files in google colab

So I am writing code in java in google colab because I want to copy-paste the code in android studio to perform a specific function. Now in python it is pretty easy to upload files to google colab but I want to do it in java (I particularly want to upload image files). I should be able to upload image files in such a way that I can use it as input in my code. How can I do it? Also, for all the packages that I import in google colab, will I have to separately download them for android studio or can I just copy-paste the code and it will run?
Google Colab presents a Jupyter-notebook like environment for Python code only. It cannot run Java code (at least, I cannot find where you'd make it do that).
I want to copy-paste the code in android studio to perform a specific function
Android code runs on an Android device, not in a server.
If you want to run Java code on a server, then you'd host an HTTP-based Java web-server that you use an HTTP Client from Android app to communicate with it. (In theory, yes, you can install and run JAR files in Colab, but you would then need to know the IP of those servers in order to connect with them).
The more appropriate solution would be to use Google AppEngine or GCE/GKE (assuming you want to use Google Cloud)
I ... want to upload image files
You can use the Java Google Drive SDK for that
for all the packages that I import in google colab, will I have to separately download them for android studio
Android Studio is an IDE. Gradle will download packages for compiling your Java/Android code, yes, but as mentioned, Colab is downloading Python packages, not Java

Import java package from Matlab deploytool to Android Studio App

I managed to create a java package from a Matlab function (for image processing) using deploytool. I tested it in Eclipse and it runs perfectly. The problem is that I want to use this Matlab function for an Android Studio project and I can´t find any way to make it work.
As you may know, when you use Matlab´s deploytool for java packages it generates three folders: "for_redistribution" which contains an .exe file (MyAppInstaller_web.exe), "for_redistribution_files_only" that contains the .jar and documentation, and "for_testing" which contains pretty much the same, the .jar file, documentation and java classes
My question is: is it possible to use this in an Android App? And if so, how? And are there any other options (other than using openCV instead of a Matlab function) to make it work?
Thank you in advance
Java components that are generated from MATLAB code using deploytool (or using other functionality from MATLAB deployment products such as MATLAB Compiler, MATLAB Builder etc.) depend on the MATLAB Compiler Runtime (MCR).
The MCR has much too large a footprint to run on an Android device, and it's really not possible to deploy MATLAB Code to Android in this way.
You have two main options:
Use the add-on product MATLAB Coder to convert your MATLAB code to C. This C code does not (unlike the deployment products) depend on the MCR, and be compiled and incorporated into your Android app like other C code.
Deploy your java component as a web service, and have your Android app communicate with it remotely.

Build Android native library with Adobe Air

I'm currently working on an Android application built with Adobe Air sdk, in AS3. I was wondering if it's possible to compile a kind of UI library that I can import in a Android native application (Java). Basically, I would like to build my UI with Adobe Air, but the main part of my application with Java, the native way.
What I have in mind is to convert the adobe air-generated APK into a Jar file I would import in the native application project, and call some functions that display something on the Screen.
Is it possible? I think it may be possible, because when I don't import Adobe Air SDK in the application, I must install Adobe Air application with the Play Store to make my application working. I don't find lot of things on Google about that :s.
Thank you for your help.
Yes it can be done (in theory), but hold on to your hat, it's a bumpy ride!
I see it is a very old question, with a new bounty (the questioner has not logged on for 3 years!), but here we go...
This method goes to the heart of how android java apps are constructed and run (i.e. DEX, so it will work with adobe-air or ANYTHING, it is fundamental [general method]). (by the way you use the word native in a confusing way, native is commonly understood to mean the JNI (c++) library element of an app).
You say:
"What I have in mind is to convert the adobe air-generated APK into a
Jar file I would import in the native application project, and call
some functions that display something on the Screen."
Android programs are compiled into .dex (Dalvik Executable)[now called ART but binary compatible] files,
which are in turn zipped into a single .apk file on the device (with other things like the manifest and resources). (unzip a .apk and look inside).
A .jar file contains DEX files (zipped). (unzip a compiled .jar and look inside).
I have done some work like this before, here's a link to a tutorial and coding examples [tested by me] (in android studio + gradle) [custom build elements are usually needed (I also give an ant example)].
See my stack-overflow answer Dynamic loading of DEX files
This in theory answers your question, but it's fundamental stuff, complex and has limitations that make it hard to code and maintain (resources are a real pain in the a**e).
Question: This all seems very complicated and hard !
Yes it is ! It is an increadably silly an difficult thing to do! That is why we invented cross platform frameworks, (and for web based code javascript/css/html5...). Failing that PORT the code.
I'm more of a Flash/AS3 coder than Java so can't give you a full answer but...
A better approach might be to just render your SWF-based User Interface itself via Java code (as opposed to compiling SWF into APK format then trying to embed Flash APK inside Android APK).
This way your SWF can also communicate with Java functions (via AS3's external Interface class). Making it easier to trigger Java functions when a button on the SWF U.I is pressed etc..
You just have to find an SWF render library for Java.
Maybe check out SWFTools. Particularly the SWF Class looks promising. I have not tested this library but it might help you.
I am not a Adobe AIR developer at all, however, I have developed a few Android App with both native environment and with some kind of framework (specifically PhoneGap). So, may this can help you.
I don't think that there would be any tool which could directly convert mobile apps build using frameworks like Adobe AIR, PhoneGap or any other HTML5 based framework to a native Android app because technically it is very difficult and unfeasible to do a proper mapping between each and every element of HTML5 (or Flex element in your case) to a corresponding native control or logic. The best you can do is use plugin mechanism provided by your framework to interact with Java and vice-versa and basically that is why the framework is there. For most of HTML5 based frameworks there is a plugin mechanism which allows developer to interact with native functionality (like Background Services, Activity or any other native resource). Even these frameworks are build using the same modular or plugin based approach and there major functionality (accessing Camera, Audio, SD Card etc native resources) works like this. We have to enable that feature before using that in our app.
So, look for plugin type of mechanism in Adobe AIR.
Hope this helps.
Maybe this is a dirty way to help you, but you can :
Install the adobe air program in one computer
Copy the files of the install folder of the adobe air program
Embed all this files in the java application
Install the java application
Save the adobe air files in one folder
Start the adobe air with java (like you will do it with the console, a simple call to YourAirApp.exe)

Developing for Android on the phone itself

I read about AIDE and it's ability to develop and compile Java directly on Android but what about C support? I read that the PC Android NDK adds full C support only if you wrap it in a dll but a newer version would allow apps to be developed directly in C without any wrapper.
Is there anything like that for Android as well? I know of c4droid and it's gcc plugin but I assume that is for developing for x86 and not ARM.
With Android Native Development Kit (NDK) you can implement parts of your application using C. http://developer.android.com/sdk/ndk/index.html. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.
Well, you could install linux (Ubuntu, in this case) on your phone and put your development environment in there, I guess.
Check https://play.google.com/store/apps/details?id=com.zpwebsites.ubuntuinstall
you can use NDK with JNI (Java Native Interface)
the following example is simple and could help you to understand quickly the NDK and JNI:
Using NDK to Call C code from Android Apps
The following document contains more examples and details concerning the use of NDK and JNI
JNI Examples for Android
Your C code will be build as dynamic linux library (.so) and will be loaded when your application start. The use of JNI will allow your JAVA code to use the C functions from the library. The use of such solution (calling C function from JAVA) is very useful especially if you have complicated and long duration algorithms. executing such algoritms in C take much less time comparing to Java.

Using MonoDroid Library apk from Java code

If i created a apk library with monodroid. Can i u use this just in Eclispe(Java) and do my rest code in Java ?
In short: no. A DLL compiled from a Mono for Android class library relies on the Mono runtime in order to run it, which wouldn't be present in a normal Java Android application. It is possible to go in the other direction though, and use Java libraries within a Mono for Android app. Xamarin has documentation of how their architecture available here.
That said, in some cases it is possible to access C# code from Java code when you're in the scope of a Mono for Android application. This question/answer has some good details about that.

Categories

Resources