I am trying to use the DexClassLoader to download a JAR/APK in my app. I would like to modularize my app so I can download UI flows the user might go on demand instead of shipping them all together into my main app.
Loading the actual classes works fine and I managed to load some UI components which I can add to my host activity.
My problem is that obviously I cannot access or add resources (Strings, drawables, layouts) to my downloaded package because they do not come with my host APK. Is it possible to dynamically load resources for my downloadable JAR/APK?
You can "dynamically" download any resources you want, put them in a directory you choose, and use them in your app. It's what I currently do in an app. I don't think you can put them in the same directory with the resources that are in your project, but does that matter?
Related
I am creating three apps that are almost the same except some changes in the assets and raw files between them.
So I wanted to create a library from the first one, that will contain all the logic and activity and all the layouts and resources, and then import this library to the other two apps, and only change the assets and raw files.
the problem is that when the layout from the library loads, it is loading the assets from the library itself, and not the assets of the main app.
I am sure that my design here is wrong then I would also appreciate if someone can explain to me what is the right way to share activities and layouts as libraries in android.
NOTE: I don't want to use flavors. I want to build it as a completely different projects.
cheers
I am working on application with multiple types choices and every type has different UI, content and operations.
If i packaged all activities, xml and drawables files inside same .apk file for all users with showing and hiding methodology it's an inefficient way as it waste user space and download time.
Are there another ways to upload activities,xml and drawables files to external servers and download them based on user selected choice?
appreciated any help.
thanks.
You may download the Activities and other Java classes from the server and load them up, perhaps even Drawables, but XML part would be a tricky one.
If you can manage to avoid XMLs by creating layouts with Java if Layout is what you meant by XML, the answer is yes, it is possible.
You will need to explore how to load Java classes at runtime.
the answer is here
Multiple APK Support
-----> The build system enables you to automatically build different APKs
that each contain only the code and resources needed for a specific
screen density or Application Binary Interface (ABI). For more
information see Build Multiple APKs.
I have a standard aplication. It uses resources - PNGs that are when programming in the DRAWABLE folder. They build up menus, buttons etc etc. ... Classic application nothing special.
And what I need to have is - "theme" support. Lets say I use this PNGs in my app:
menubutton.png
scrollbotton.png
arrwo.png
and these are in the DRAWABLE folder.
And I would like to be able to change the THEME of the app by changing this PNGs for different ones. Lets say I have PNG's with same names, but under a different url:
.../template1/menubutton.png
.../template1/scrollbotton.png
.../template1/arrwo.png
and than I have a another "template"
.../template2/menubutton.png
.../template2/scrollbotton.png
.../template2/arrwo.png
IMPORTANT: Of course all the PNGs have exactly same size, and name
So and the app shall have the functionality to download this PNGs and replace the ones that are currently in use. The important point is that the additonal PNGs from different templates HAVE to be availiable online - I dont want to ship the app with many templates that would not be used.
Can you please confirm this can be done and that it should not be a problem?
The Drawable resources are packaged in to the application and cannot be modified. You idea of using an SD card will work (or you can use the applications sandboxed directory), you just need to manually load the png resources (ex. myImageView.setBackgroundBitmap(...); [pseudo-code]).
As a note: If I ever open an application that immediately tells me to wait since it is downloading resources, I will force-close it and uninstall. Applications on Android, iOS, Windows, etc. should work right away without the need to download more resources. If you want a default "theme" then package it with the app, don't make the user download it (which will cause problems if the user is on mobile networks or doesn't have an internet connection when they open the app)
I am trying to write a modular extensible application to deploy in Android. The idea is to provide an API to allow the creation of custom functionality for the app that may include custom layouts and other resources. This custom functionality will be loaded, at runtime, from another location (e.g. SD Card).
Currently I am able to load .jar files from this location and work with them as I like, unfortunately I can only include references to layouts and resources that are also present in the "Main" project.
I have been unable to find a good way to reference an entire library project, resources included. I essentially want each custom piece to contain all the resources it needs to display and run itself.
Right now I am toying with the idea of including an "Assets" project that can be referenced by each of the modules to be a central area to store layouts and other resources. Unfortunately this would require me to have a project that must be loaded by any other project that needs to be built.
Another idea was to include the layouts, images and strings, along with the jar files, in a folder and load those at run time. I don't think this will work well since the layouts seem to be pre-processed at compile time in some way and cannot be inflated at run time.
Does anyone know a way for me to include all the resources and code into a single, dynamically loadable, file that I can then access at runtime?
Does anyone know a way for me to include all the resources and code into a single, dynamically loadable, file that I can then access at runtime?
That is not supported. It is rather likely that it will never be supported, though it is possible that it might work with the new build system that is under development.
I have a small Android application that uses different sets of files (a couple of images, a small SQLite DB and a couple of XML files) depending on the specific task at hand.
I know I can include my files into the main application APK using resources or assets but I would be happy to distribute them in a separated APK.
How can I create a data-only APK file?
How can I distribute it? In particular, do I have to do anything special for a data-only package (for example for associating it to the main application package in some way)?
(I'm intentioned to give the user a link to the data package and ask him to install it. No automatic installation required.)
How can I install my files into the internal or into the external storage area of my application? Is it possible at all to install files into the internal storage area created by the main application installer? Do I have to set any particular permission for this?
My approach to this would be to create a wrapper app that's nothing but a content-provider and serves up the files per request by your main app. This would allow you to supply different data packages for the user -- you could even have your main app select between those relatively easily.
It looks like that the commonly accepted way to have the same application with different contents (or styles, or configurations) is to use an Android Library Project for the common code (that is: the whole application, the "engine", the "app framework") and a standard Android Application Project for the contents (that is: an application that actually contains just data). A little bit confusing, just because the "library" here is actually the whole "app", but this seems to be the way to go.
More in detail:
Create an Android Library Application and put into it as much code as you can (all of the non-changing stuff). Please note that this library cannot be launched and cannot be distributed alone. It must be included in a hosting application.
Create a standard Android Application. Include your library into this project. Put in /res and in /asset all of your data (files, XML, etc.).
Compile everything and distribute.
Repeat this cycle every time you need a different version. Different because of data, style, configuration or anything else. Publish the resulting app with a new name.
For what regards me, I'm not completely satisfied by this approach.
A possible alternative is preprocessing the source code with Ruby, Python, Perl, GIT, bash, Ant, Maven, Rake or any other tool that is able to read a file from here, make some change here and there, and write the file there.
The general outline is something like this:
Make a "template" application. Leave your /res and /assset empty.
Run a custom-made script. The script reads a configuration file, copy the /res and /asset files from your repository into the project /res and /asset directories, changes some Java source file and creates/changes some XML file.
Compile and distribute (with a new name, of course).
Using GIT or other SCMs, you just make a new branch for every new version and compile it. Not very elegant (because it can strongly interfere with the normal use of the SCM) but...
There are a few example of these approaches on the web. I'm not completely satisfied by them, either.
Frankly, what the Android ecosystem should offer to solve this problem is some kind of "in-app package manager". Something like the Eclipse Update Manager. This would allow us to use the same application framework to handle different scenarios.
As an alternative, a solid, officially-supported, template-based code-generation mechanism would be nice. Something in the spirit of "Software Production Line": https://en.wikipedia.org/wiki/Software_production_line . Have a look at fw4spl, for example: http://code.google.com/p/fw4spl/ .