'When can I stop using AppCompat or Support libraries? [closed]
I'm building an app with minSdkVersion 23
. Can I stop using support libraries like androidx.appcompat:appcompat
and stuff like AppCompatActivity?
I assume it would reduce app size and avoid unused code. Or am I missing something?
At which SDK version do we draw the line?
Update: as pointed out by the community, these libraries exist to provide compatibility to older Android versions. Particularly regarding Material Design.
As we increase minSdkVersion
is there a point where compatibility is no longer needed?
For example: Android Toolbar replaced the old action bar on SdkVersion 21
. If my minSdkVersion
is 23, I don't need to provide compatibility to the Toolbar.
So, is there an SdkVersion
where all the libraries and APIs are natively available?
Solution 1:[1]
Its better not to remove any support libraries, some of the libraries are strongly recommended for the developement.
We can replace
**proguard-android.txt**
withproguard-android-optimize.txt
, Adding optimization introduces certain risks also.Make
minifyEnabled
andshrinkResources
astrue
buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }
Solution 2:[2]
It depends on the components you are using actually, as you are using minSdkVersion 23
which is Android 6 you can in my opinion.
If you are not using any support component you can stop using support libraries, a great example is CPU-Z app, which is not using any support libraries as they are not using any, so the app size is less than 2 MB.
Solution 3:[3]
In my opinion, there's no rule or mention on the official document that 'AppCompat' or 'Support' libraries should be used below specific version.
The reason, Appcompat & support libraries were introduced on the first place was to provide backward compatibility for lower/backward versions of Android SDK where few functionalities were not available. (Mainly I can remember is Material design support which app might be using but not available on the specific android version's SDK like NavigationDrawer, CollapsingToolbar etc.).
So, the goal of these support libraries were to be shipped with the app such that it doesn't crash on lower versions as well as provides newer functionalities to those apps it's implementing which is not supported.
My short answer is 'Yes, you can decide not to use appcompat libraries' if your app is not using some specific feature that your minimum SDK version missing.
Mainly, you'll miss out with material design components for the UI and some AACs (Android Architecture Component) capability like Lifecycle and ViewModel support etc.
Keep in mind that everything has trade-offs in software development, it's upon use-case that you're implementing whether XYZ feature should require something SDK provides out of the box or need to use some third party library or package.
Quick note: Everything falls under AndroidX hierarchy now (check here) and you can decide from change logs for appcompat here whether you should use it or not.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rohit S |
Solution 2 | Anas Abdullah Al |
Solution 3 | Jeel Vankhede |