无法在 android studio 中生成签名的 apk

Posted

技术标签:

【中文标题】无法在 android studio 中生成签名的 apk【英文标题】:Unable to generate signed apk in android studio 【发布时间】:2016-09-11 20:08:31 【问题描述】:

我正在尝试生成已签名的 apk 以供发布。但它一直在失败,并在消息框中显示以下警告:

Error:Execution failed for task ':msapp_V_520:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.

我试图通过在我的 proguard-rules.pro 文件中添加 -dontwarn-dontnote 来解决这个问题。很少有警告已经消失,但仍然出现错误。我没有得到解决这些警告和生成 apk 的确切方法。这就是我在消息框中得到的:

Note: there were 6 references to unknown classes.
      You should check your configuration for typos.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 4 classes trying to access generic signatures using reflection.
      You should consider keeping the signature attributes
      (using '-keepattributes Signature').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 80 unkept descriptor classes in kept class members.
      You should consider explicitly keeping the mentioned classes
      (using '-keep').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)
Note: there were 17 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 1 class casts of dynamically created class instances.
      You might consider explicitly keeping the mentioned classes and/or
      their implementations (using '-keep').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclasscast)
Note: there were 4 accesses to class members by means of introspection.
      You should consider explicitly keeping the mentioned class members
      (using '-keep' or '-keepclassmembers').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember)
Warning:there were 4 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
:msapp_V_520:transformClassesAndResourcesWithProguardForRelease FAILED
Error:Execution failed for task ':msapp_V_520:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.

proguard-rules.pro 文件

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\user\SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the javascript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview 
#   public *;
#
-dontwarn com.nostra13.example.universalimageloader.**
-dontnote com.nostra13.example.universalimageloader.**
-dontwarn com.facbook.**
-dontnote com.facbook.**
-dontwarn com.ikimuhendis.ldrawer.**
-dontnote com.ikimuhendis.ldrawer.**
-dontwarn com.loadindicators.adrianlesniak.library.**
-dontnote com.loadindicators.adrianlesniak.library.**
-dontwarn com.handmark.pulltorefresh.library.**
-dontnote com.handmark.pulltorefresh.library.**
-dontwarn com.pullToRefresh.**

build.gradle 文件

buildscript 
    repositories 
        maven  url 'https://maven.fabric.io/public' 
    

    dependencies 
        classpath 'io.fabric.tools:gradle:1.+'
    

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories 
    maven  url 'https://maven.fabric.io/public' 


android 
    signingConfigs 
        config 
            storeFile file('keystorePath')
            storePassword 'xyz...'
            keyAlias 'xyz...'
            keyPassword 'somePwd'
        
    
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig 
        applicationId "com.example..."
        minSdkVersion 14
        targetSdkVersion 20
        useLibrary 'org.apache.http.legacy'
        compileOptions 
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        
        signingConfig signingConfigs.config
    
    buildTypes 
        release 
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        
        debug 
            signingConfig signingConfigs.config
        
    
    dexOptions 
        incremental true
    
    productFlavors 
    


dependencies 
    compile project(':comnostra13exampleuniversalimageloaderHomeActivity')
    compile project(':nineoldandroid')
    compile project(':libraryActionbar')
    compile project(':pullToRefresh')
    compile project(':facebook')
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile files('libs/AF-Android-SDK-v2.3.1.19.jar')
    compile files('libs/classes.jar')
    compile files('libs/CleverTapAndroidSDK-v1-20150903.jar')
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile project(':LoadIndicatorLibrary')
    compile 'com.nispok:snackbar:2.11.+'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') 
        transitive = true;
    

【问题讨论】:

尝试清理所有项目! @NiravRanpara 也尝试过..但仍然收到相同的警告消息。 请参考link。希望对你有帮助。 @DhruvVaishnav onkar 给出的答案,您的链接有相同的答案,我试过了。我也在使用 buildToolsVersion 23.0.3 和插件版本 2.0.0 。因此,在按照答案中的建议进行更改后,我无法计算 classes-proguard\release\classes.jar 的哈希值 【参考方案1】:

当 SDK、构建工具和 Gradle 插件的版本不匹配(在兼容性方面)时,会发生此错误。解决方案是验证您是否使用它们的最新版本。 gradle 插件放在项目的 build.gradle 文件中。其他版本在模块的 build.gradle 文件中。对于example,对于SDK 23,您必须使用Build Tools 23.0.1 和gradle plugins version 1.3.1。强>

更改设置后清理项目。 refer this question

【讨论】:

以上是关于无法在 android studio 中生成签名的 apk的主要内容,如果未能解决你的问题,请参考以下文章

Android Studio 无法在 proguard 错误配置中生成签名的 APK

无法在 Android Studio 中生成签名的 APK,因为缺少 proguard-rules.txt

在 Android Studio 中生成签名 APK 时签名版本之间的区别 - V1(Jar 签名)和 V2(完整 APK 签名)?

无法在 android studio 中生成使用 react native 制作的 apk 项目

在Visual Studio中构建的代码将无法在TFS中生成

无法在 Android Studio 上生成签名包