3

I'm developing an Android app on Android Studio and I'm calling a method from API level 19. My build.gradle looks like this:

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.2'

    productFlavors {
        // Define separate dev and prod product flavors.
        dev {
            // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
            // to pre-dex each module and produce an APK that can be tested on
            // Android Lollipop without time consuming dex merging processes.
            minSdkVersion 21
        }
        prod {
            // The actual minSdkVersion for the application.
            minSdkVersion 16
        }
    }

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 16
        multiDexEnabled true
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
}

I have no lint.xml files in my project, so no lint checks are overriden.

The problem is that the lint check "Calling new methods on older versions." doesn't find the method call for API level 19. If I open the build variants panel and select prodDebug or prodRelease the method gets underlined in red, but the project builds well. How can I get Android Studio to effectively show the aforementioned method in the analyze result or to block me from correctly building the project?

Edit I found a way to search for methods not complying with the minimum SDK. By going to the Gradle panel on the right and running the lint task, an HTML report is generated, which finally shows the API 19 call along with other calls. Why is this not implemented into Android Studio?

Since this still does not work in Android Studio per se, but rather in Gradle, I'm not closing the question yet.

Gonzalo
  • 3,674
  • 2
  • 26
  • 28
  • Duplicate of https://stackoverflow.com/questions/39710692/how-to-enable-lint-error-in-android-studio-for-message-call-requires-api-level – Flow Mar 01 '18 at 20:01

1 Answers1

1

Gradle won't tell you if you are using the methods that are not supported in you minSDK if your compiled SDK version is not the minimum one. read more about it

So simply the solution is use lint feature i.e inspectcode

right click , either on project/class then => analyze=>inspectCode

Community
  • 1
  • 1
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
  • If a set the compileSdkVersion in build.gradle to 16, high API resources such as `android:Widget.Material.Spinner.Underlined`(declared in an xml resource targeting api level 21) are not found. Moreover, I think that no matter the target SDK, if you declare a minimum API, then checks should be simple as comparing every method call's api level to that of the declared minimum and add the ones that don't meet the requirement to the final inspection results. I really wonder how is this not working properly up to this date. – Gonzalo Oct 05 '16 at 18:27
  • @Gonzalo you are right but this one the case where you have used suppress annotation or build checks which helps to escape from compile time checks so when there are lots of build and annotation added in a big project then simple way is use analyze feature to find where they are – Pavneet_Singh Oct 06 '16 at 05:21