2015-03-14 11 views
43

Mam następujące ostrzeżenie w moim Gradle plik buildGradle Ostrzeżenie: brakuje Groovy return

Not all execution paths return a value

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

i jest to kod w pliku

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' 
    } 
} 

Czy ktoś może powiedzieć, co jest wydać tutaj i jak pozbyć się tego ostrzeżenia.

+0

Jaka jest rzeczywista wyjście z gradle? Jak to działa? –

+0

Nie skonfigurowałem typu debugowania, może to jest problem? – Opal

+0

@tim_yates Nie używam tego. Po otwarciu pliku build.gradle modułu wyświetla się żółty komunikat ostrzegawczy w pobliżu paska przewijania. Ponadto, po najechaniu myszą na "release", "minifyEnabled", "proguardFiles", "getDefaultProguardFile" lub "compile", wyświetla się komunikat "nie można rozwiązać symbolu". –

Odpowiedz

16

Otrzymuję to samo ostrzeżenie i myślę, że jest niepoprawny. Przeczytałem dokumentację gradle i nie wydaje mi się, że potrzebny jest typ zwrotu. Jednak ostrzeżenia mnie zaniepokoiły i jedynym sposobem, w jaki mogłem się tego pozbyć, było dodanie return true.

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

Wątpię, czy to jest "poprawne" rozwiązanie; jednak usuwa ostrzeżenia i nie powoduje żadnych problemów.

+3

Dziękuję za to, zgodziłem się, że wolałbym * poprawne * rozwiązanie, ale i tak cieszę się, że pozbyłem się ostrzeżeń. – Jon

+0

Dobrze, ale ja wolę 'return null', ponieważ absencja zwrotu oznacza, że ​​nic nie zwracam. – Androiderson

+3

Lub 'return void', ponieważ to naprawdę nie ma znaczenia. – Jon

9

Pozbyłem się tego ostrzeżenia, gdy podałem oba, minifyEnabled i shrinkResources.

buildTypes { 
    debug { 
     minifyEnabled false 
     shrinkResources false 
    } 

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

Próbowałem i to nie działa. Nie rozumiem, dlaczego to działałoby. –

50

Z Android Studio 2.2 musiałem dodać return void przed końcowym wspornika w sekcji android.

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 
} 
+0

Naprawiłoby to tylko błąd, dodając 'return void' na końcu bloku ** defaultConfig **. –

+0

Andrew, jak wygląda twój 'defaultConfig'? –

+0

'' 'defaultConfig { multiDexEnabled prawdziwy minSdkVersion 16 // noinspection OldTargetApi targetSdkVersion 22 powrót void // usuwa błąd niestrzępiącą: 'Nie wszystkie ścieżki wykonanie zwraca wartość' }' '' ' –

12

Naprawiłem to dodając zalecany ciąg tłumienia z inspekcji:

//noinspection GroovyMissingReturnStatement 
android { 
    compileSdkVersion 25 
    buildToolsVersion "23.0.3" 
... 
Powiązane problemy