无法创建签名 APK

Can't create Signed APK

我一直在使用 Android Studio 开发一个应用程序,已经过测试,我准备发布到 Google Play。

当我尝试创建签名 APK 时,在创建密钥后,gradle 构建停止并显示以下消息:

Please correct the above warnings first.

经过大量研究,我发现问题可能出在 build.gradle(模块:app)中,我读到缺少这一行:

lintOptions {
    checkReleaseBuilds false
    abortOnError false
}

但是,即使有这条线,它也不会起作用。这是消息:

编辑:

这是我的 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'
}

编辑 2

深入构建错误,我发现了这个 Stacktrace:

我今天遇到了这个错误,浪费了好几个小时。我这样做了

  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.

如果你问我在哪里可以找到最新版本

这三项你都会得到建议,只需按alt + enter键接受建议即可。

您的 ProGuard 配置似乎有问题。

Here 是 android 开发者网站上对 ProGuard 的描述,基本上它是一个做一些事情的工具,包括删除它认为不必要的代码。问题是它通常会删除 运行 甚至构建所需的代码,就像您的情况一样。 要解决此问题,您可以做两件事。

  1. 禁用 ProGuard:

添加

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

到您的应用级别 build.gradle 文件。

  1. 提供规则,以便 ProGuard 保留必要的文件。

在这种情况下,您保留设置

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

并且您需要编辑 proguard-rules.pro 文件。它应该与您的应用级别 build.gradle 文件位于同一目录中。通常,每个图书馆都会在其网站上提供混淆规则,例如 retrofit 将它们放在页面底部。浏览所有库并将所有必要的规则添加到 proguard-rules.pro 文件。