I was searching online for this pretty basic question and couldn't find the answer. Does Jetpack Compose only work on sdk 31, or it's it able to work on previous Android versions? If it is semi backwards compatible, how do I use it in previous versions?
Asked
Active
Viewed 3,001 times
1 Answers
4
Choose API level 21 or higher. Source here.
Edit: Your build gradle will look like this:
android {
compileSdk 31
defaultConfig {
minSdk 21
targetSdk 31

Code Poet
- 6,222
- 2
- 29
- 50
-
Why then, when I have it compile in sdk 30 does it say some dependencies need 31. I didn't add any dependencies, just the ones Android Studio has by default – Joshua Miller Nov 13 '21 at 12:53
-
@JoshuaMiller: Your errors are from your `compileSdkVersion`. That is unrelated to the `minSdkVersion` that your question is about. – CommonsWare Nov 13 '21 at 13:14
-
1@CommonsWare: So what does that mean, you can only compile it in sdk 31? I don't really understand your answer. If you can only compile it in sdk 31, then how can they claim to support down to api 21 – Joshua Miller Nov 13 '21 at 13:33
-
@JoshuaMiller: `compileSdkVersion` and `minSdkVersion` are only loosely related. See https://stackoverflow.com/q/24510219/115145 and https://stackoverflow.com/q/26694108/115145, among other resources. – CommonsWare Nov 13 '21 at 13:53
-
1@CommonsWare: I guess my question is why would we have the min sdk be 21 if the compose stuff just doesn't work on anything less than 31? Or, if it does support down to 21, how do I change the dependencies to allow it, as the default project Android Studio makes doesn't work and gives dependencies errors, only fixed when I increase the complieSDK to 31 – Joshua Miller Nov 14 '21 at 02:16
-
Probably best to open a new question with an explanation of what doesn't work. This is off topic here. – Code Poet Nov 14 '21 at 11:23
-
1But it is supposed to work down to API level 21? – Joshua Miller Nov 14 '21 at 15:14
-
@Code Poet: I can't, people downvoted instead of answering. I also don't have a clear answer, does it run on versions less than API 31? From my testing, it seems not, but the website says that it should, I can't tell whether it can or not – Joshua Miller Nov 14 '21 at 15:30
-
Yes, it works down to Api 21, which is what I told you in my answer. So if it does not work for you, open another question. – Code Poet Nov 14 '21 at 16:18
-
Choose level API level 21 or higher is different depending on which one you do, min sdk, compile, or Target, each has different effects – Joshua Miller Nov 14 '21 at 21:23
-
@JoshuaMiller use minSdk = 21 and compileSdk =31 – Gabriele Mariotti Nov 15 '21 at 14:28
-
I've edited my answer to make it clearer. – Code Poet Nov 15 '21 at 16:10
-
1<3, thankss! Out of curiosity, if you can only compile it in SDK 31, why would we set the minSDK to 21. If it needs to be compiled in 31, why does it give the illusion of being able to build in lower skds – Joshua Miller Nov 15 '21 at 18:13