Gradle displays a warning, although set to SuppressWarnings

I have an Android app imported into Android Studio. It includes some Java libraries. Everything is still working.

Next method:

@SuppressWarnings("deprecation") private Drawable getDrawable() { if(Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) return activity.getResources().getDrawable(R.drawable.separator_gradient, activity.getTheme()); else return activity.getResources().getDrawable(R.drawable.separator_gradient); } 

A depreciation warning is always displayed:

 :androidAnsatTerminal:compileDebugJava C:\...\src\main\java\de\ansat\terminal\activity\widgets\druckAssistent\FahrkartenArtSelector.java:131: warning: [deprecation] getDrawable(int) in Resources has been deprecated return activity.getResources().getDrawable(R.drawable.separator_gradient); ^ 

1 warning

This is not the only @SuppressWarnings ("deprecation") method in my project. In other places, a warning is not printed ...

For instance:

  @SuppressWarnings("deprecation") private void setBackgroundToNull(ImageView imgRight) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { imgRight.setBackgroundDrawable(null); } else { imgRight.setBackground(null); } } 

From my AndroidManifest:

 <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="21" /> 

How can I get rid of this warning? I do not want to turn warnings around the world or anything like that.

EDIT: If I just call getDrawable with the Subject parameter, this happens on the SDK15 device because of this:

 java.lang.NoSuchMethodError: android.content.res.Resources.getDrawable at de.ansat.terminal.activity.widgets.druckAssistent.FahrkartenArtSelector$3.getDrawable(FahrkartenArtSelector.java:128) 
+5
source share
3 answers

I found that for unknown reasons, this code raises a warning:

 private Drawable getShadow(Context context) { @SuppressWarnings("deprecation") final Drawable drawable = context.getResources().getDrawable(R.drawable.shadow_top); return drawable; } 

So far, this equivalent code is not working:

 private Drawable getShadow(Context context) { final int resId = R.drawable.shadow_top; @SuppressWarnings("deprecation") final Drawable drawable = context.getResources().getDrawable(resId); return drawable; } 

Extracting the helper method also seems to work and solves the problem for me:

 @SuppressWarnings("deprecation") private Drawable getDrawable(Context context, int resId) { return context.getResources().getDrawable(resId); } 
+1
source

do this with @SuppressWarnings ("all") to test

0
source

@SuppressWarnings annotation is for Java compiler warnings. For lint warnings use

 @SuppressLint("NewApi") 

or

 @TargetApi(android.os.Build.VERSION_CODES.JELLY_BEAN) 
0
source

All Articles