I'm getting these warnings in my android build.
Warning:(19, 9) Attribute `layout_marginVertical` is only used in API level 26 and higher (current min is 24)
Warning:(20, 9) Attribute `layout_marginHorizontal` is only used in API level 26 and higher (current min is 24)
Clearly our app's layouts make use of layout_marginVertical
and layout_marginHorizontal
attributes, which were introduced in API level 26. The warning makes it sound like these attributes won't work on level 24 devices, but indeed they work perfectly. I would like to understand why I'm getting these warnings, despite there seeming to be nothing wrong.
One obvious solution is to use the "longhand": marginTop
and marginBottom
instead of marginVertical
, but I'm hoping to continue to use these "short" parameters if possible, to improve readability and reduce repetition.
Were these attributes undocumented for level 24? Or is there some kind of backward compatibility at play? If so, why the warning?
We are using:
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="26" />
Update: Setting targetSdkVersion="24"
seems to fix the warnings, and the desired margins continue to work. This solves my immediate problem, but I'm left confused about why a level 26 feature works on level 24, and why targeting level 26 causes warnings. What do I do if I want to target level 26?
layout_marginHorizontal
worked on pre-26 devices? I have the same "problem" now. Actually,layout_marginHorizontal
even works on Android 4.4 – HuelvatargetSdkVersion
is recommended. To my understanding:android:minSdkVersion="min_sdk_version_required_to_install_the_app"
android:targetSdkVersion="sdk_version_that_the_app_works_well"
android:buildSdkVersion="latest_sdk_available"
. As you mentioned,android:layout_marginVertical
still works with some magic. But if you want to get rid of the warning without lowering thetargetVersion
, you can usetools:targetApi="26"
ortools:ignore="UnusedAttribute"
to suppress the warning. – Proximity