Include APK and files in an android ROM compiled from source - android

I am compiling a ROM from source (say CM12.1)
I have obtained the source code and am ready to build.
However I wish to add an app (say ES file explorer) as a user app and another app(say Titanium) as a system app. Also I need to copy a file to one of the system folders.
How is this done?
I dont have the source code of those apps and hence cant compile from
source.

You will have to add the source code of the app the the packages/apps folder. Remove any precompiled files that exist.
Add the android.mk file. You can copy from it from the already available apps in the packages/apps folder and customize it for your app.
Add the app name to core.mk file in build/target/product
Build the ROM and it should have your file.

Related

Copy folder structure containing binaries to native libraries folder

I want to copy and execute some precompiled binaries on device, the problem is that the relative folder structure needs to be the same as in the original package (I cannot move all binaries to root folder).
What so far I found about this is how to copy binaries without .so extension to lib folder here. It works as expected, once installed I can locate the binary using context.getApplicationInfo().nativeLibraryDir, however when I place the directory with binaries it cannot find it using the command.
Further investigation shows that folder does get coppied to apk. I can confirm that by unziping the apk and finding the binaries coppied at /lib/arm64-v8a/.
Now since the apk is fine, the next step I did is check what actually gets copied to device. This can be found in /data/app/app.name.com+random_hash/lib/ and I confirmed that folder does not get copied over, only binaries from root folder do.
What I want to know is whether the code responsible for copying native libraries is located on device and cannot be changed, or the application can be somehow configured to copy the folder structure?
Example repo: https://github.com/D4no0/copy_native_binaries
The code is on device, part of the OS :
"Subdirectory is not supported by the Android OS.
When the APK is installed, the .so libraries are extracted to a directory in the form of /data/app/your.app/lib/. That directory is added to the library path searched by System.loadLibrary so that it can be found. System.loadLibrary do not support a directory structure, thus, the .so files in a subdirectory under lib/ are not extracted."
The above answer is coming from a Googler working on Android, from the following issue :
https://issuetracker.google.com/issues/63707864#comment4
Cheers,
Jérôme

Include files with different prefixes in apk

I have a project with native libraries that I want to use, files with this format: lib<name>.so do get included into apk. But files with <name>.so format does not.
Is there a way to include the later type into apk in lib directory?
If not, is there a way to include the files into a directory inside apk, where I can load it from my native code?
The short answer is "no". The native binaries will only be packed into APK, and extracted to executable files upon installation, if their names follow the lib….so pattern.
Note that these libraries will be extracted to files according to the ABI of the target system. The installer does not check the actual properties of the file. The decision is based on the name of the folder under lib in the APK structure.
If you add the attribute extractNativeLibs=false to the application tag in AndroidManifest.xml of your APK, the installer (on Android Nougat and higher) will not extract the native libraries.
You can trick the system and have files that don't follow the above rule to the lib folder of APK, but there is very little sense in it, because they will never be extracted by the loader (it may also extract file gdbserver if the file is there).
The common practice is to put the arbitrary files in the assets folder of your APK, and extract them programmatically when the app runs for the first time after install. You cannot extract these files to the secured location where the usual native libraries go. You should not extract the native libraries to sdcard (e.g. getExternalFilesDir()), because the system may not allow execution of the files there, regardless of the execute access flag on the file. Make sure that you use the correct ABI flavour.
You can peek at the source code of Nougat native lib loader that can load native libraries from the APK without extraction, and use it to load your custom libraries directly from the assets folder of your APK.

Android how to extract *.so file during execution

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.

Replace .so file in android apk

is it possible to replace .so file in android app without source code?
I am creating app which use some .so files under LGPL license v2.1 http://www.gnu.org/licenses/lgpl-2.1.html
License says: "...you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it..."
Is it possible to replace .so file and recompile app without source code e.g. in existing apk? I can't give user source codes. Or some option to give user .class files so he can create apk?
Is it even possible and if so, what are options?
Thank you!
Yes, you can replace a .so file in an apk. Just use 7zip to open the apk replace the file and you are done.
About gpl: you should have 2 libraries, one so for your code and one for the code you borrowed, this way the user can replace the so for the library, but your code cannot be changed. You can also put a check for the libs version and just exit if it was changed.

Sharing Android NDK Lib

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)

Categories

Resources