Why does Android Studio lint not recognize my minSdkVersion

760 views Asked by At

Android Studio (version 4.1.1) is displaying warnings in my xml layout files for views that use onClick (warning id: UsingOnClickInXml, older versions of the platform do not properly support resolving Android:onClick). These also show up in lint warnings when I run the code inspector. It appears that Android Studio doesn't use the minSdkVerion (16) that I set in my build.gradle (app) file.

    <Button
        android:id="@+id/btn_Splash_PrivacyPolicy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClick" //This gets highlighted with the warning
        android:text="@string/dialog_button_privacyPolicy"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        />

Here is an excerpt from my build.gradle (app) file:

android {
    compileSdkVersion 30
    buildToolsVersion '30.0.3'
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 30
        ...
        }
    ...
}

This appears to be preserved in my merged AndroidManifest.xml (I'm not directly setting a minSdkVerion in the manifest, only in the build.gradle file). Excerpt from merged AndroidManifest.xml

<manifest
  ...
  <uses-sdk
    android.minSdkVersion="16"
    android.targetSdkVersion="30" />
  ...

Example of how I use onClick in the associated Activity :

    public void onClick(View view){
        if (view.getId() == R.id.btn_SplashOK) {
            if (mCheckBox_SplashDontShowAgain.isChecked()) {
                sendIntentInfoBack(Constants.DONT_SHOW_AGAIN);
            } else {
                sendIntentInfoBack(Constants.DO_SHOW_AGAIN);
            }
        } else if (view.getId() == R.id.btn_Splash_PrivacyPolicy){
            Toolset.showPrivacyPolicyDialog(getSupportFragmentManager());
        }
    }

The app appears to function correctly, but I'm concerned AS / lint doesn't recognize the minSdkVersion I've set.

I've tried:

  1. Build->Clean Project
  2. Build->Rebuild Project
  3. Build->Make Project
  4. File->Invalidate Caches/Restart
  5. Changing minSdkVersion to 17, sync, change back to 16, sync
  6. Re-running Analyze->Inspect Code several times

I've reviewed:

Android Studio not picking up the minSdkVersion - not applicable; I've set the value in the correct file.

Android Lint erroneously thinks min SDK version is 1 - not applicable? I was unable to find "Clear Lint Markers" in AS, per the answer; out of date? (answer from 2012)

My Questions:

  1. Is this a problem/should I be concerned?
  2. Is there a way to fix AS / lint to accurately use the minSdkVersion I've set?
1

There are 1 answers

1
user16101988 On

Message "Using 'android:onClick' on older version of the platform is broken" appears from version androidx.appcompat:appcompat:1.3.0