Guilherme Golfetto
Guilherme Golfetto

Reputation: 530

Can't create Signed APK

I have been developing an application with Android Studio, tested, and I'm ready to publish to Google Play.

When I tried to create a signed APK, after creating the keys, the gradle build stops with the following message:

Please correct the above warnings first.

After a lot of research, I found that the problem may be in the build.gradle (Module: app) and I read that is missing this this lines:

lintOptions {
    checkReleaseBuilds false
    abortOnError false
}

But, even with this lines, it wont works. Here is the message:

Error

EDIT:

heres my build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "br.com.companyname.appname"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "2018.05.11 v2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    implementation project(path: ':componentsutils')
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


    implementation group: 'org.apache.commons', name: 'commons-text', version: '1.2'
    implementation group: 'commons-io', name: 'commons-io', version: '2.4'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:palette-v7:27.1.1'
    implementation 'com.squareup.retrofit:retrofit:1.9.0'
    implementation 'com.squareup.okhttp:okhttp:2.7.5'
    implementation 'com.github.d-max:spots-dialog:0.4@aar'
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation 'br.com.livroandroid:android-utils:1.0.2'
    implementation 'com.android.support:exifinterface:27.1.1'
}

EDIT 2

Going deeper in the build error, I found this Stacktrace:

StackTrace error

Upvotes: 1

Views: 68

Answers (2)

TpoM6oH
TpoM6oH

Reputation: 8575

Looks like you have a problem with ProGuard configuration.

Here is the description of ProGuard on android developers site, basically it is a tool that does a few things, including removing of code that it thinks is unnecessary. The problem is that often it removes code that is necessary to run or even build, like in your case. To fix this problem you can do two things.

  1. Disable ProGuard:

Add

android {
    ...
    buildTypes {
        release {
            minifyEnabled false
            ...
        }
    }
    ...
}

to your app level build.gradle file.

  1. Provide rules, so ProGuard keeps necessary files.

In this case you keep your setup

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

And you need to edit the proguard-rules.pro file. It should be located in the same directory as your app level build.gradle file. Usually, every library provides proguard rules on their web site, for example retrofit has them at the bottom of the page. Go through all your libs and add all necessary rules to your proguard-rules.pro file.

Upvotes: 1

Khemraj Sharma
Khemraj Sharma

Reputation: 58934

I was having this error today and wasted hours. I did this

  1. Updated all app dependencies like google.gms and google.support libraries.
  2. Updated gradle wrapper version in gradle-wrapper.properties file.
  3. Updated gradle plugin version in project level build.gradle.

If you ask me where you find latest version

You will get suggestion in all of these three, just accept suggestion with alt + enter key.

Upvotes: 2

Related Questions