Is is possible to package non-standard files in APK without assets? - android

I am trying to package /somewhere/lib/python3.x inside APK's lib folder like jniLibs. But it contains *.py, *.pyc and other files. I have asked another question, but there is no answer. So this is a general question: do you ever used or developed any plugins that embed non-standard files in APK instead of using assets?

How would you access those files? I mean you could put them in the apk, an apk is just a zip file. But the system won't unpack them for you, and at runtime you won't be able to access the apk file itself (installation unzips your file and deletes the apk). You might be able to fool it into doing so by putting it with the jni libs and hoping it doesn't look at extention, but it seem like a bad idea.
However its not uncommon for an app to take its assets and write them to the filesystem on first boot. In fact its fairly common to do this with updatable assets (you'd then just download new versions on top of them, but you can use the old versions to not need an immediate network connection). This would probably work for you. Just make your initial activity a splash screen, and have it do the copy from assets to files in the background while the splash is up.

Related

Load a custom .so in Android

I am currently porting a library from Linux to Android and I am having some trouble.
The lib has an extension system : it will look for all the files with a particular extension in the folder /usr/local/lib/{thelibname}/extensions/, check if they are dynamic libraries, and load them and call a handler if it is the case.
However, I don't think it is possible to tinker with the base filesystem folders in Android.
I looked into assets but they did not convince me, it looks like they are more intended for images, audio, etc...
Is there another way to embed some files in an .apk and load them afterwards by enumerating a DIR* and calling dlopen ?
The other possibility would be to put the extensions with the app data but I don't know if there is a standard path for this that I could hardcode in the lib, is there? And I don't how to put some stuff in the data at the installation of the apk ? (I use QtCreator for the generation of the APK)
Okay, I found another question which helped me to solve my problem :
How to integrate native runtime library with dlopen on NDK?
You can easily load extension libraries from anywhere in the file system, including shared folders like /sdcard/ and her children. Any app (and native libraries therein) can gain full read access to /sdcard/ with READ_EXTERNAL_STORAGE permission.
This way you can establish a folder where the extensions will be updated not necessarily by a single APK (note the changes for WRITE_EXTERNAL_STORAGE in KitKat).
If you want to deploy all extension libraries as part of the APK, it's easiest to put them in the standard folder that is used to pack the APKs (for ADT, it's ${project_root}/libs/armeabi) and then they will be automagically installed in /data/app-lib/${app_package}. This approach allows to prepare an APK for multiple architectures, preparing appropriate files in ${project_root}/libs/x86, etc.
Note that all libraries must have lib prefix and .so suffix, so e.g. mylib.so or libcrypto.so.6 will not work, even though theoretically such libraries can be loaded by dlopen().
Your app has read access to the /data/app-lib/${app_package} directory, so you can scan it either from C code, or from Java. In Java, its easy to resolve the ${app_package} even if you don't want to hardcode this name. Simply call getApplicationContext().getPackageName().
In C, you can use /proc/${pid} to find the full path to your shared library, and this way you will also know the path to the extensions.

Unity Android patch.obb file creation and use

We are currently working on a Unity Android project that has to have localised mp4 streaming Videos. In order to achieve this I was hoping to put the video files in an expansion obb file, then we can have the same apk and submit it with different obb files according to language.
Unfortunately our application without the videos is still over 50Mb so we need to use the first "main.1.name.obb" for the application.
However we are allowed to also submit a second obb under the name "patch.1.name.obb". However I am having trouble making this and using it. Has anyone tried this with unity before?
The application builds and runs with the first obb file absolutely fine (i.e. the game works without videos) the problem is just in the patch obb creation.
I have tried to create the obb by using a linux zip command with 0% compression then renaming it to a .obb file with no luck. (e.g. patch.1.packname.zip to patch.1.packname.obb)
I have tried to create the obb using jobb tool, and it adds the videos fine but still in game they are not found/played.
The videos are definitely in an "assets" folder inside the obb files made (where I believe streaming assets have to be)
I have fudged the streaming Assets Path ( Application.streamingAssetsPath ) to replace "main" with "patch" and have seen through logcat that it is indeed trying to get the videos from the patch obb file.
(e.g. "jar:file:///[storagelocation]/Android/obb/packname/patch.1.packname.obb!/vid01.mp4 )
Our version code in the AndroidManifest.xml if definitely 1.
Can anyone suggest anything else to try or point out an clear errors I am making in trying to do this?
Let me know any more information you may need to help as well and thanks in advance.
I haven't worked with Unity before, but from my experience I can point out a few things I have found from working with '.obb' files:
Simply renaming the '.zip' file to a '.obb' file will not work. You will need to make a folder named '.obb'. Then add all the needed resource files to this folder and then zip this folder, using 0% compression of course. Make sure that the zipped file contains only the resource files in the root and not a sub folder (the folder you made previously). Now you have a zip file named '.obb.zip'. At this point you can rename the file to '.obb'. Of course, the files may be in a sub folder inside the obb file (the assets folder in your case), but I am not sure about the consequences of this.
In regards to the statement you made concerning the files that are not found after using the jobb tool, this is most likely due to a miss-spelling somewhere or in one of my cases, forgetting to rename the package after copying it from a previous app. I know this seems foolish and maybe insulting (in which case I deeply apologize), but it happens.
This answer is based on my personal experience and may be slightly off center, but here are some links I used:
http://developer.android.com/google/play/expansion-files.html
http://developer.android.com/google/play/publishing/multiple-apks.html
http://developer.android.com/tools/help/jobb.html

Where we put language files of tesseract ocr engine in an android app?

I'm programming an application in android which uses OCR. I'm using the tesseract ocr and I want to ask where should I put the language files in my project, so that when I install my app in my phone(Samsung Galaxy S) the files be somewhere for the app to use them for the ocr process. I think that it should be in a place like: /mnt/sdcard/tesseract/tessdata, but how this can be done without putting them myself in my device and let the installation to do this.
You'll have to include the files with your project in the assets folder.
See AssetManager to learn how to access your files from your activity. Also I would suggest that you don't copy them to the SDCard. Unfortunately since your files are going to have to be included with your project, and thus will be present in your apk file you're going to end up with a larger application size. But also unfortunately I don't believe that there is a way to delete the files from your apk at runtime, so even if you copy them over to the SD your app is still going to be the same size. For that reason I see no reason to copy them to the SD card, just access them from the AssetManager when you need to get them. Doing it that way also means that your application will not break if the SD card is removed / unmounted.
Simply put them under Assets in a "tessdata" folder. That is in your project.
You can use Xamarin and the Tesseract for Xamarin nuget package, they're really easy to use, just bear in mind that you probably will have to install older version of the nugget if the latest version doesn't work. (2.10 was the working one as far as i remember)

How to access resources (like sound, images etc) directly from native code using Android-NDK?

I want to know that how can I directly access the resources like images, sound files etc. from native code i.e. C++ files. Actually I am looking for any example that could help me to use the asset_manager_jni.h methods.
Looking for suggestions. Thanks in advance.
With Regards,
Atul Prakash Singh
Well, you have access to stdio.h. So if it's in a known place (say on the SD card), you can just use that as a path. And there's lot's of tutorials on the net about hot to use stdio (fopen, fclose, etc).
The issue is that resources you bundle into the apk itself (either in res/raw, or assets), stay inside the apk after install. What's worse is that by default, they will be compressed which makes reading it not feasible. This can be avoided, and the easiest way is to rename the asset to have the .mp3 extension (or there are others). The reason for this is because by default, .mp3 is not compressed, regardless of whether or not it actually is an mp3 file). There are other extensions you can use, and ways to tell the tools not to compress your data if you don't like naming all of your assets with .mp3 at the end.
So, you have a few choices here:
Download your resources from the net on your first run, put them in an unobtrusive place (it's probably best to get that path from the sdk when you do the downloading), and use that.
Store your resources in the apk (remember the .mp3 extension, in the assets folder). On your first run, extract the assets to a folder you have access to (and doesn't annoy the user), and use the resources from there.
(what I do) Store your resources in the apk (.mp3 again), and use the jni to read directly from the apk. Yes, the jni is a bit slow, but you shouldn't be reading from the file system all that much anyway, and certainly not at a performance critical point. Nvidia has some very helpful code you can use, you can find it here, it's in the sample code if I remember. Inside the libs folder are some good general purpose libraries you can use that matches stdio, except it also reads from the apk itself.
Hope it helps.
I did use this trick once :
mv $file lib/lib%${file}.so

Include a database file with Android application via Eclipse

How can I instruct Eclipse to copy a file from my Android solution to an emulator, as part of Run/Debug? I have a small database, stored in Assets, that needs to accompany the application. Thus far I have simply copied the file myself using DDMS but would prefer to have it automatically included. The project properties allow me to specify some aspects of the build, e.g. the build order and which libraries should be included, but I don't see anything about simply copying a file.
Is the file in your "res/assets" folder not available using the AssetManager class during testing versus during testing or when installed via a signed apk?
I use a large file that I store in "res/raw" in one of my games, I am able to access this file during testing with eclipse without a problem just using the normal calls to context.getResources().openRawResource()
Deploying databases with your application it a reoccurring topic over in the android-developers Google group here is a post with a few thoughts on the matter.
Good luck.

Categories

Resources