Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Warning: missing groovy return statement

I'm having the following warning in my gradle build file

Not all execution paths return a value

This inspection reports on missing groovy return statement at the end of methods returning

and this is the code in that file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "ac.company.srikar.quickhelpindia"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        android {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
    }
}

Can anyone tell what is the issue here and how to get rid of this warning.

like image 467
Srikar Reddy Avatar asked Mar 14 '15 04:03

Srikar Reddy


People also ask

Is Groovy required for gradle?

gradle is a Groovy script. Thus it can execute arbitrary code and access any Java library, build-specific Gradle DSL and the Gradle API.

What is Groovy language gradle?

The Gradle build language Gradle provides a domain specific language, or DSL, for describing builds. This build language is available in Groovy and Kotlin. A Groovy build script can contain any Groovy language element. A Kotlin build script can contain any Kotlin language element.


3 Answers

With Android Studio 2.2 I had to add a return void before the final bracket in the android section.

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
        }

        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        standard {
            applicationId "com.example.app.standard"
        }

        free {
            applicationId "com.example.app.free"
        }
    }

    // `return void` removes the lint error: `Not all execution paths return a value`.
    return void
}
like image 197
Soren Stoutner Avatar answered Nov 04 '22 22:11

Soren Stoutner


I have been getting this same warning and I think it is incorrect. I have read through the gradle documentation and it does not appear that a return type is needed. However, the warnings bug me and the only way I could get rid of it was to add return true.

buildTypes {
    android {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            return true
        }
    }
}

I doubt this is the "correct" solution; however, it does remove the warnings and it doesn't cause any issues.

like image 36
mattfred Avatar answered Nov 05 '22 00:11

mattfred


I fixed this by adding the recommended suppression string from inspection:

//noinspection GroovyMissingReturnStatement
android {
    compileSdkVersion 25
    buildToolsVersion "23.0.3"
...
like image 12
JL West Avatar answered Nov 05 '22 00:11

JL West