The Native Code of the Android application is going alone with application as lib file in the APK file. Suppose if I want to share a native code between two different applications, Is there any trick avail apart from the below:
Adding the lib with every application
Copy the lib in to system/lib folder and dynamically link it with application. (If we build just only the applications then we cannot use this).
You can't copy anything onto /system unless you are root, so I'd suggest you just include your native library in every application that needs it.
You must create library project ant than create your activity and lib.so file. You may be added all project this library.(Such as vitamio)
Related
Anytime I clear build folder in flutter (either with flutter clean or manually), my jni folder rebuilds (~40 mins). Is that possible to compile library to some binary, and use it from android without breaking any interfaces and functionality?
P.S. My library consists of many folders and contains .mk, .c, .cpp, .h files.
Is that possible to compile library to some binary, and use it from android without breaking any interfaces and functionality?
Of course yes. Build you libraries like shared .so or static .a and use them like prebuilts. Here the example how to use native prebuilt libraries: How to link .a to .so and create new .so for android
Moreover, you can also put them together with the used SDK, NDK, AS, and other thirdparties in Docker image and work with your project from Docker.
I have one android myLibrary.jar file. But myLibrary.jar file will load the native 3 different so file. I have a.so, b.so and c.so.
When i using in my own application, it just simply put the jar file to the Android Dependencies and all 3 so files put in the libs/armeabi of the main application package.
When deploy and install on the device, these so file will be in the data/data/my-appname/lib/*.so.
Now i need to provide the sdk solution. The user side doesn't want the main application. They just want the myLibrary.jar. So i am considering about packing all 3 *.so files to the jar. I searched for the how to add to the so files to myLibrary.jar. But i still don't understand.
In this following post:
[Ant]How to add .so file into a jar and use it within jar(set the java.library.path)?
It mentioned about adding the so file to the jar and extract at runtime. But i still don't understand how to achieve that.
After trying that mentioned in the following post:
Creating a product SDK: How do I add a native lib (.so) and a jar with the SDK I am creating?
After my sample application reference the the compiled jar that included the .so file. After installing to the device, the libs/armeabi/xxx is not unpacked on the install. So i would like to know how to extract them dynamically and save them to data/data/my-appname/lib/ so that i can use with System.loadlibary(.so).
Thanks a lot.
I'm building AOSP from source. What I would like to do is to include a few prebuilt files in the generated system.img as part of the make process. I'm trying to find the actual file that creates the system.img and add a few lines there. Any idea?
Thank you in advance.
A good way of adding custom files to the system.img is to add them under vendor/your_name/product_you_want_to_add_them/proprietary/your_files_go_here and add a custom make file called device-product_name.mk.
After that's done, just define which files are to be copied from the proprietary folder and inside (e.g. vendor/samsung/crespo/device-vendor.mk add to call your device make file).
Just put your source code to the Packages/apps directory,then make sure your project has a correct make file like other project in the apps directory.You will make the package prebuilt after finish the android build.
To add a prebuilt file to a build, find a .mk file which makes sense for your project and add the file under PRODUCT_COPY_FILE. It looks like this
PRODUCT_COPY_FILE += your/build/tree/$FILE:path/to/location/on/device/$FILE
Using a separate vendor tree is following good domain-driven principles...but is perhaps overkill for a single binary. Examine the makefiles you already use, there is often prebuilt apks already being added that you can piggyback on. device and existing vendor trees are good places to start looking. Maintaining an entirely new project is not something to be taken lightly, in my opinion.
If you want to add programs in the system.img, go to the vendor, then go to the operator, then go the app and enter the files inside the app
If you use the roms modification program, the program name is rom helper, it modifies prmission to 0755, and it modifies UserID 2000, thus adding the apk to rom
I have an apk file. I create other android project. I place the apk file within that project. Is it possible to access the Activities in the apk from within the new project (similar to importing classes in a jar)?
You cannot link one APK into another. You can either include the sources and resources from it (perhaps as an Android library project) to access its contents directly, or you can require that the user install it as well and you can invoke its intents.
I've built OpenSSL into an Android Library that I would like to reference from another Android project.
Unfortunately,
Yes, I do need OpenSSL, as I need to change the behaviour of dependant Android classes not in the public API. (not enough space here)
My experience with native code is non-existant.
The project is selected as a library in Preferences > Android
This library is referenced from a second Android project
My Questions are these
How can I reference the .so files in my Android library from Android.mk in my second project so that I can build dependant files there? I'd prefer not to put the .so files directly in my second project - but if that is the only solution I would accept reasons and directions as an answer.
How should I include/reference the .so file in files I am building in the second project?
Surely, it is something simple.
Thanks in advance.
once you generate (.so) library file, then make a folder in your applitcation's project folder named "libs/armeabi/" put (.so) file in this folder
and in your application write
System.loadLibrary("library_name");