Note that there are some explanatory texts on larger screens.

plurals
  1. PODownlaod drawables from server to reduce APK file size
    primarykey
    data
    text
    <p>To reduce the APK file size, I want to remove the drawables (images and XML files) from my project and download the proper ones from my server on the first app start.</p> <p>The problem is how to load and use the downloaded drawables in my code?</p> <p>This is what I found after some research:</p> <ul> <li>For normal images, I can use <a href="https://stackoverflow.com/questions/3375166/android-drawable-images-from-url"><code>BitmapDrawable</code></a>.</li> <li>For 9-patch images, I can use <a href="https://stackoverflow.com/questions/9284784/android-how-to-create-a-9patch-image-from-an-inputstream"><code>NinePatchDrawable</code></a>.</li> </ul> <p>But I still don't know how to load and use XML drawables that have references to other drawables, like this:</p> <pre><code>&lt;layer-list&gt; &lt;item&gt; &lt;bitmap android:src="@drawable/other_drawable" /&gt; &lt;/item&gt; &lt;/layer-list&gt; </code></pre> <p>Any thoughts on this or other effective ideas to reduce the APK file size would be appreciated.</p> <p><em>Notes:</em></p> <ul> <li>The drawables make up most of the APK file size (20mb/25mb).</li> <li>I already compressed image files and I'm using ProGuard.</li> </ul> <hr> <p><strong>Update:</strong></p> <p>After some more research, it seems to me possible to load/use downloaded XML drawables after modifying them a little by using custom attributes for referenced drawables and a subclass of <code>Drawable</code> instead of native <code>BitmapDrawable</code>. So the above XML drawable example will become something like this:</p> <pre><code>&lt;layer-list xmlns:custom="http://schemas.android.com/apk/res-auto"&gt; &lt;item&gt; &lt;custom-bitmap custom:ref="other_drawable" /&gt; &lt;/item&gt; &lt;/layer-list&gt; </code></pre> <p>Though, it's not a very easy solution and I'm not sure it's better than doing things manually.</p> <p>References:</p> <ul> <li><a href="https://groups.google.com/forum/#!topic/android-developers/glpdi0AdMzI" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/android-developers/glpdi0AdMzI</a></li> <li><a href="https://code.google.com/p/adet/source/browse/trunk/AdetSample/res/drawable/svg_button.xml" rel="nofollow noreferrer">https://code.google.com/p/adet/source/browse/trunk/AdetSample/res/drawable/svg_button.xml</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload