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.
Related
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.
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 want to edit the resources of an APK file from WITHIN Android. I know how to do it with ApkTool in windows/linux, but I'm having problems doing it in an Android app itself.
In particular, I need to add a few files to the resouces, edit the AndroidManifest.xml and put the files back in the APK.
I know APKs are simply zip files, but the resources and manifest inside them are "compiled" in binary format so they cannot be edited directly, so I need some kind of library or tool for Android that can decompile the resources and then put them back in the APK.
I know this can be done, since apps like APK Editor do it (and without needing root!) but I can't find any documentation on how to do it myself.
I used this library for parsing an APK.
I have an enterprise app which I am deploying manually (no Google Play) which uses a number of .so libraries for mapping (ArcGIS). However, the .so files (arm, armv7a, x86) in the libs folder blow the .apk size out from 3mb to 21mb. I dont particularly want to remove one of the .so files (removing support for that architecture), or mess around with one .apk per architecture.
Can anyone think of a way I can update my app without including the .so files in each update .apk?
Yes, you can have the Java portion of your app manually download the appropriate .so files into your app's internal storage folder and mark them executable.
You will then have to load them with System.load() and the full pathname of the .so file, rather than System.loadLibrary() and the trimmed library name.
The biggest issue here is that you are now responsible for matching the ABI's yourself, and more importantly, providing your own protection against being tricked into installing a modified or imposter library which might do something nefarious in the name of your app and using it's permissions.
Of course you have to make sure not to try to call any of the native methods before you have installed them.
You could also consider delivering the .so files as binary assets each in its own skeleton .apk having a shared user id (and matching certificate) as your main .apk
Or you could simply make platform-specific .apk's for each target, containing only one .so, and have your distribution system pick the right ones (though that doesn't help with the upgrade problem).
Actually I want to know that if in my application's libs folder, any library file(e.g .jar file) is present, then after installing(running) that application, will library file present in .apk file?
According to my understanding, library FILE should present in generated .apk file. If I am wrong then please correct me.
If my question is below standard, then extremely sorry for that. Any help will be well appreciated
With recent versions of the Android tools, .jar files in the libs folder are automatically included in the build. (See Dealing with dependencies in Android projects.) So, yes, the library is included in the compiled bytecode (not as a separate file).
If you use ProGuard in a release build, then it will attempt to strip out any code which is not actually used. So, it may be that some parts of the library are included in the final .apk, and some parts are removed.
the answer is yes. The apk is just a zipped version of your compiled project. If you open it with winrar for example, youll see that everithing is in there ;)
You can try it and see yourself but you can not directly see the .jar file under libs folder in the apk generated. Library class files are all together are compiled into a single .dex file. If you decompile that dex file, you can reach the java codes.