Android - add files into APK package? - android

is it possible to add to my apk file some XML file storing program version, update path and other useful data (note: I don't mean Android XML file). All I want to is this file to be unpacked somewhere to local data folder and I will use it for comparing version info installed locally and on the server in case of updates.
I am asking - is it possible to add to apk some other file?
Thanks

The assets/ folder in apk is intended to store any extra user files in any formats. They will be included to apk automatically on compilation stage and can be accessed from the app using getAssets() function. For example:
final InputStream is = getResources().getAssets().open("some_file.xml")
It is even unnecessary to copy them to some local folder to read them.

If you only want to know the version info of the app then there is a much easier way to identify it. You can use
getPackageManager().getPackageInfo(getPackageName(),PackageManager.COMPONENT_ENABLED_STATE_DEFAULT).versionCode
to get the version code and
getPackageManager().getPackageInfo(getPackageName(),PackageManager.COMPONENT_ENABLED_STATE_DEFAULT).versionName
to get app's version name

Related

can asset folder be accessed by the user when the apk is installed?

For example i have an android program which contains important files in the assets folder , can the user who installed the apk access the assets folder or not ? for hacking purpose
Anyone can open your .apk just by changing the extension to .rar, what you can do to protect your code is releasing it using proguard rules, but still in that case an image for instance in the drawable folder can be compromised, however an string in your strings.xml is bit more protected.
Anyone can decompile your app and can see a lot of things including your assets. .apk file is just an compressed file which can be extracted easily.

Using a linked file in Assets directory - FileNotFound Exception

I am trying to link to an external file from a shared repository between my iOS and Android apps. This does not present a problem for iOS, but it does for Android. My current solution is to create a copy of the file from the external repository and place it in my projects Assets folder. This solution works, but is not much of a good one in my opinion and involves too many extra steps.
Using Eclipse, I am able to link to a resource. It's as simple as copying a file into my Assets folder and being prompted to either copy the file or link to the resource. If I link to the resource and try to run my app, I get a FileNotFoundException. If I copy the file instead, the app file is found just fine.
Ideally, I'd like to link to the file so that when I pull a new update from git then I don't need to copy the file over every single time. I'd prefer to link to the file.
I don't know what Eclipse uses "under the covers" for "Link here" drag-and-drop stuff. However, it is an Eclipse-ism. Android's build tools are fairly isolated from Eclipse proper, and so they won't know about those links.
Using a hardlink, or perhaps a symlink, at the OS X filesystem level should work, as both Eclipse and Android's build tools should treat it like a local file.

Decompiling .apk file created in Appcelerator and getting to .js files

Is there any way to get to .js files with code created with Appcelerator from compiled .apk?
I lost a source coude of one of projects and now have only .apk files and would like not to rewrite the whole code.
Thank in advance
If you would like to do this manually:
In release version of the app, Titanium puts all of the assets into Java class called AssetCryptImpl, you would have to decompile apk and look for that class file in the sources.
AssetCryptImpl file will contain private method called initAssetsBytes, which returns one large chunk of data as CharBuffer, which contains encrypted data for all of the asset files. The other method called initAssets, will contain all of the original asset filenames and also ranges for each of the asset files.
Asset data is encrypted using AES in ECB mode, and last 16 bytes from asset data are the decryption key. Asset decryption method implementation is inside JNI library but its not hard to rewrite. filterDataInRange will call native code to decrypt the resource.
You can easily rewrite filterDataInRange method, with your implementation, which will get the key and decrypt the resource data and write it to file. And write a method which will call readAsset for each filename from HashMap, from initAssets method.
If you want one click solution:
You can use the tool called ti_recover.
Install it with node package manager:
npm install ti_recover
Than use it from terminal/command line:
ti_recover apkfile.apk outputdir
Depends on how the Titanium app was built. If it's an emulator build, then yes, you can get the JavaScript files. If the apk is from a device or dist build, then no.
For device and dist builds, Titanium minifies and encrypts all JavaScript, then injects it into the Java code before compiling it.
So if you have an apk from an emulator build, you can just rename the .apk to .zip and unzip and the JS files will be there.
One thing to note is if your app is an Alloy app, then you'll only get the compiled Alloy code, not the original Alloy code. That means you won't find any .xml views, .tss styles, etc.
This Website might be your best bet. It uses a range of technologies to decompile .apk files.
You can try making a new folder and copy over the .apk file that you want to decode. Rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it. After extructing, Now you can access the classes.dex files, etc. Also, in Asset folder you will get the resources. Though you can't get the .js file by following this process. You can use this http://www.javadecompilers.com/apk website. But still it will give you a java dicompilation.

In Flex, How to access packaged file in apk?

I am building an android app using FlashBuilder and is using a sqlite database, and the initial database shall be packaged into the apk (Android package). When the app runs firstly, the packaged database should be copied to "applicationDirectory".
However, problem comes.
I can use File.applicationStorageDirectory.resolvePath("xx.db") for the destination when using File.copyTo() function. However, how about the file to be copied (from the apk package)?
Can you be more specific about the problem. Is it that you are getting an IOError when you try to copy a file(db) from the application directory to the app-storage directory? Have you checked the contents of the packaged apk? Why dont you consider creating the db in the app-storage directory when the application starts because that application directory is quite protective of its content.
What are you trying to achieve really?
P.S. Keep in mind that the Application directory is read only. So your code cannot write files that reside on that directory.

Configuring Android application from file

I am trying to create an Android application that would use a configuration file (plain text) when loading.
When testing locally (with an emulator), I place my config file in the src/ folder (ecplise) and I see it is copied and used from the bin/ folder upon project build.
My questions are:
1) Where do I need to place this file when testing on a device ?
From what I understand I need the *.apk file and the config file to be both present on the device during run time.
2) If I am using eclipse to install the *.apk file can I somehow specify the config file as a dependant file and force eclipse to copy it as well ? If not do I need to manually copy the *.apk & config files to the device ?
NOTE: I am using getResourceAsStream to load the file.
Thanks,
RM
Well actually there shouldn't be any problems with accessing the file in a way you do. But preferred (and recommended by Android developers) way is to place the file into /res/raw folder. Then you can access the file as application resource:
InputStream is = getResources().openRawResource(R.id.your_file_name);
Here getResources is a method of Context class, it should accessible anywhere within your activities. R.id.your_file_name is a static field generated by eclipse at the time you place your file into /res/raw folder.
Read the https://developer.android.com/guide/topics/resources/index.html to get more about application resources at Android.

Categories

Resources