kotlinandroid-studiogradlekotlin-multiplatform

Kotlin - new api warnings (e.g. removeFirst, removeLast) not working in my KMP project


The docs say following:

Consider removing @SuppressLint("NewApi") and lintOptions { disable 'NewApi' } if the lint option has been disabled.

Doesn't that mean that building a project should fail or at least show a warning, if none of the above 2 things are used? I don't get any warnings nor errors - everything builds fine. But my app crashes because I do use removeFirst in my code... I have a KMP project, maybe lint check does not work there? Does anyone know what could be the issue that I don't see warnings for the new api usage?

Project

My project is using API 35 and crashes on my device running API 34... But building my project does not fail nor show any lint warnings. Even running a lint check manually does not show any warning...

M project is a KMP project - so it is not android only. May there be something I need to consider in this case to get the warnings/errors? I don't want to search for functions that may create problems as I may oversee some so I really want that lint check to work...


Solution

  • The lint check only runs for the code placed in androidMain. Code in commonMain is not covered by this lint rule since most of the rules won't apply.

    You can verify this by placing mutableListOf<Int>().removeFirst() in your Android Activity where the linter should issue this error:

    Call requires API level 35 (current min is 24): java.util.List#removeFirst (Prior to API level 35, this call would resolve to a Kotlin stdlib extension function. You can use remove(index) instead.)

    Since this piece of code will be a problem wherever it is placed (though just resulting in a runtime error for the Android target), a lint check for the common code would also be important to have for KMP projects. I do not know of a way to activate this check, though.