Android Studio:如何获得一致签名的发布 APK?

Android Studio: How can I get the aligned signed release APK?

我正在使用 Android Studio,对于其他项目,当我尝试生成签名的 APK 时,我得到了 app-release.apk 文件,但遇到了更多麻烦。

但是在这个特定的项目中,我只能得到一个 app-release-unaligned.apk 文件。

与我的其他项目的主要区别在于使用了 transloadit jar 和 org.apache.httpcomponents 库,为此我必须在我的 gradle 文件中记下 packagingOptions 字段。

这是我的 build.grade 文件

apply plugin: 'com.android.application'

android {
    signingConfigs {
    }
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.bambinotes.bambinotessnap"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENCE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    compile files('libs/transloadit-1.0.2.jar')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.anupcowkur:reservoir:2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.mcxiaoke.volley:library:1.0.16'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
    compile 'com.android.support:support-v4:22.2.0'
}

** 更新**

我刚刚发现我遇到的错误是什么,Android Studio 在另一个文件夹中打开取景器,该文件夹生成应用程序调试和应用程序发布未对齐文件(我们可以将其视为中间文件),app-release.apk 文件是目录结构中的两个文件夹。

尽管我为知道我遇到麻烦的原因而感到尴尬,但我会留下这个问题,看看以后是否会发生这种情况。

您需要将签名配置添加到您的 Gradle 文件中,请参阅此答案了解更多信息 How to create a release signed apk file using Gradle?

app-release.apk 文件在应用程序文件夹中。

有时 Android studio 会显示未对齐文件所在的另一个目录,因此您只需查找新创建的文件即可。