简体   繁体   中英

how to extract only the needed (e.g FileProvider) from the android.support.v4.content bloat?

I have read Googles Guide to Support Libraries for Android because I needed such a Support library the android.support.v4 since I needed the one specific functionality FileProvider to be included in my App.

I notices that my 163kb apk grow considerably by the inclusion of the support library . My question is "how is it possible to only include the needed/used" part of this support library, and not to bloat(increase my apk size) by including other features provided, but not anyway used by my app?

I made some tests removing some content of the android-support-v4.jar for instance I kept android/support/v4/content but removed android/support/v4/media thinking that I will not need any of the classes provided there.

So far that arbitrary exclusion has not shown any negative effects, yet my testing space (ie one only Android 5.x phone) might be bit enough and the support library parts I excluded are indeed necessary for android/support/v4/content.FileProvider .

The thing is that I was unable to find out how such support libraries are supposed to work?

My question is how can I cut down to just the used features?

My question is "how is it possible to only include the needed/used" part of this support library, and not to bloat(increase my apk size) by including other features provided, but not anyway used by my app?

Most of the bloat should come from Java classes (by my quick examination of the support-v4 AAR). Most of that bloat should be cleared out by ProGuard for a release build. You could look at your APK, using something like ClassyShark , to see if you need to tune your ProGuard configuration beyond what you have.

Or, since IIRC FileProvider is just one Java source file , use the source directly.

Or, use my StreamProvider , based upon FileProvider with some additional features, that is a 21KB AAR at the present time (and is unlikely to grow dramatically).

Or, write your own ContentProvider .

Or, wait until Google splits up support-v4 into separate distinct libraries, which is planned, based on Google I|O 2016 presentations. However, we do not know how soon this may occur.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM