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.
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)
Message "Using 'android:onClick' on older version of the platform is broken" appears from version androidx.appcompat:appcompat:1.3.0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.