Is there way to get libs/nativearch/<.so files> listed from the package-manager. Considering that apps like apk-info do it, I guess there should be a way to get the supported architecture of the package as well the listed .so files inside each folder. Any idea on this?
PackageManager won't tell you this directly.
However it will tell you the filename of the app's APK file (via ApplicationInfo.sourceDir), and you can then use ZipFile to iterate through all the files in the apk, to get a list of the files in the libs directory tree.
See also How to get the file *.apk location in Android device
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 am trying to link my Android app with a third-party archive. This archive, libvpx_new.a,is one among many archives that are being created as part of building webrtc for Android (on Ubuntu). I copy this archive and the header files into C:\ThirdParty directory on Windows. My Android app tries to link with ThirdParty/libvpx_new/libvpx_new.a.
When the build runs, I get link errors such as:
xxx/arm-linux-androideabi/bin/ld.exe: error: cannot open
C:/ThirdParty/libvpx_new/source/libvpx/vp8/libvpx_new.vp8_dx_iface.o:
No such file or directory
If I simply copy all the missing object files (in appropriate subdirectories), my build goes through. It is as if the archive file libvpx_new.a contains links to the object files instead of storing the actual functions.
Is this possible? If so, is there a way to fix the archive file to just absorb the object files instead of pointing to them? Regards.
It turns out archives can indeed store external links. Such archives are called "thin" archives. Look at Turn thin archive into normal one to convert thin archives to normal archives.
I reversed an app (my own dummy app) using apktool.
>apktool d testing.apk
The last line of output in the terminal says "I: Copying assets and libs..." but there is no "libs" directory in the generated folder.
Am I missing something here ?
I want to know which 3rd party libraries are being used. This can be found from "libs" directory but I am not getting this directory. Any help is highly appreciated. Thank you.
You don't need apktool to get the libs. An APK is just a ZIP. Just unzip testing.apk and look for a lib/ directory.
If it's not there, it may not use shared libraries. Or, they may be downloaded at runtime. To check, install and run the app such that you're sure it's used functions from the shared library. Then, pull the files off the device with:
adb pull /data/data/<package name>/lib
I have some files that I want to read from my app.Currently, I have to do the following:
Check if the file exists in the files directory.
If it doesnt, then copy the files from assets to the files directory
If it does, then, skip step 2
So, is it possible to not copy the files ? This increases the size of my app (uselessly) as there is an extra copy of all the files.
Note, that I have to access the file using getfiles(). I am using a library that doesnt work if I give the uri of my assets folder.
So, it it somehow possible to compile the app with some files already in the files directory ?
Internal storage for you app is created when application is installed so there is no way to provide files there during compile time, that would be magic.
You could try creating ContentProvider for sharing your files stored inside assets folder.
Besides, you should tell which library you are using. Then I may be able to suggest something more precise.
I want to know how to find a resource in an apk after installing it. I mean, whether Android will extract the apk and save into file system after installing.
By now, I only know apk will is saved in /data/app. classes.dex can be found in dalvik-cache directory. But I don't find any clue about resource in this apk, such as string.xml, png or any file in assets. Is it possible that Android system unpack apk every time when it will use these resource?
I red many old thread, but I don't find answer yet. So can anyone please explain it for me?
Thanks very much in advance.
br
The resources are inside the apk file as binary xml files. Also after the installation. For simple xml files it will load them only from the apk file. Images and larger file might be cached, but I don't know exactly where.
only resources in res/raw folder will be available on device storage, otherwise it will be inside the apk as binary data
To explore an Android APK file,
[ View the graphics, play the audio, etc.]
all you have to do,
is right click on an APK file,
and set it to "Open With" to WinZip, Winrar.
or your favorite unzipper.
Thereafter, any time you click on an APK file,
you can view the graphics, play the audio,
view the resources, explore the programming, etc.
If you want to convert an APK file to Linux/Unix,
download "Dex2Jar" from
http://code.google.com/p/dex2jar/
then unzip one of the APK files
to a convenient directory,
navigate to the directory
and right click on the CLASSES.DEX file,
and set it to "Open With" "dex2jar".
Thereafter, anytime you click on an Android DEX file
this will convert the Android DEX file
to a Unix JAR file and put it in the directory
with the Android resources.
--
Tom Potter