Gradle Warning: missing groovy return statement - android

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.

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
}

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.

I fixed this by adding the recommended suppression string from inspection:
//noinspection GroovyMissingReturnStatement
android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
...

I got rid of this warning when I specified both, minifyEnabled and shrinkResources.
buildTypes {
debug {
minifyEnabled false
shrinkResources false
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

It seems that this is an issue fixed in Android Studio 2.3:
https://code.google.com/p/android/issues/detail?id=223575

Related

Error:(12, 23) java: package org.apache.http does not exist

my android project doesn't contain build.gradle to put useLibrary 'org.apache.http.legacy'
Sample Build.gradle
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.Sample.App"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.1"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
debuggable false
jniDebuggable false
renderscriptDebuggable false
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
debuggable true
jniDebuggable true
renderscriptDebuggable true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
}

Add different proguard file for debug

I have a project with two modules. It exists a default configuration of build.gradle:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
And I want to add a different configuration (proguard and minifying) for debug compilation as follow:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles 'proguard-rules-debug.pro'
}
}
When I put this code in my project, it doesn't compile. The log show a message error for each reference to another module:
Error:(37, 42) error: package com.example does not exist
Full Gradle configuration of the two modules.
The app module:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
...
}
}
apply plugin: 'com.android.application'
...
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.3"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
}
repositories {
maven {
...
}
}
repositories{
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
...
dependencies {
...
}
The library module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
...
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}
I would try the following:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules-debug.pro'
}
}
Alternatively did you try putting the rules files into the build-types folders? You could put the proguard-rules.pro file into the build-types/release folder and the proguard-rules-debug.pro file into the build-types/debug folder.

Android Gradle sync failed (import project from github)

Hi guys i download a project from github and i imported in android studio , after imported am getting error
Gradle sync failed: Cause: assert localProps['keystore.props.file']
| |
| null
[ndk.dir:E:\sdk\ndk-bundle, sdk.dir:E:\sdk]
Consult IDE log for more details (Help | Show Log)
Gradle File:
signingConfigs {
release {
def Properties localProps = new Properties()
localProps.load(new FileInputStream(file('../local.properties')))
def Properties keyProps = new Properties()
assert localProps['keystore.props.file'];
keyProps.load(new FileInputStream(file(localProps['keystore.props.file'])))
storeFile file(keyProps["store"])
keyAlias keyProps["alias"]
storePassword keyProps["storePass"]
keyPassword keyProps["pass"]
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
signingConfig signingConfigs.release
}
publicBeta.initWith(buildTypes.release)
publicBeta {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
versionNameSuffix " Beta " + versionProps['betaNumber']
}
publicDebug.initWith(buildTypes.publicBeta)
publicDebug {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
versionNameSuffix " Debug Beta " + versionProps['betaNumber']
}
}
}
I realy don't know what to do.
Does anyone have any suggestions?.
In the root folder of your project, you should have keystore.properties and local.properties files.
keystore.properties should have something like this:
store=/path/to/your.keystore
alias=your_alias
pass=your_password
storePass=your_keystore_password
In local.properties, add the last line.
ndk.dir=/Users/username/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/username/Library/Android/sdk
# Add the line below
keystore.props.file=../keystore.properties
See a commit here or check the modified project.
Or if you need a quick dirty fix, just make the gradle script the same as a standard one by replacing the android block with this:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
When I got such an error, it was because I was using JDK8, while the imported github repo was using JDK7.
Also make sure you have "Android Support Repository" installed from SDK Manager > Extras.

Handheld multi flavor app with single wear project

My project was working fine when I had just a simple handheld app with one wear app.
Now, I've introduced three flavors to the handheld app and kept the same single flavor wear app.
The problem is that release builds are not being pushed to the wearable.
My project looks like this:
smartphone's build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 8
versionName "3.1.0"
applicationId "br.com.test"
}
signingConfigs {
...
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig = android.signingConfigs.release
}
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
zipAlignEnabled true
}
}
productFlavors {
generic {
applicationId "br.com.generic"
}
abc {
applicationId "br.com.teste.abc"
}
company {
applicationId "br.com.test.company"
}
}
}
dependencies {
genericWearApp project(path:':wear', configuration: 'genericRelease')
abcWearApp project(path:':wear', configuration: 'abcRelease')
companyWearApp project(path:':wear', configuration: 'companyRelease')
compile project(':common')
}
and wear's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
publishNonDefault true
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 8
versionName "3.1.0"
applicationId "br.com.test"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
zipAlignEnabled true
}
}
productFlavors {
generic {
applicationId "br.com.generic"
}
abc {
applicationId "br.com.teste.abc"
}
company {
applicationId "br.com.test.company"
}
}
}
dependencies {
compile project(':common')
}
Why does the wearable does not gets the app? Any tips?
I was only a matter of tricky details... This repo offers a really nice example and was enough to help me solve this:
https://github.com/vngrs/PomoPomoAndroid/

debuggable false in android studio 0.4.5

<application
android:debuggable="false"
get a error saying "Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one"
I deleted what is up in AndroidManifest and I add this in the build.gradle
android {
compileSdkVersion 18
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 3
versionName "1.2"
}
buildTypes {
debug {
debuggable true
jniDebugBuild true
}
release {
debuggable false
jniDebugBuild true
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('build/libs/GoogleAdMobAdsSdk-6.4.1.jar')
}
but still does not work when i upload to play store
thanks
This is what I used and it worked perfectly
buildTypes {
debug {
debuggable false
}
release {
runProguard false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

Categories

Resources