我将构建签名的 apk 时出错

Posted

技术标签:

【中文标题】我将构建签名的 apk 时出错【英文标题】:error when i will build a signed apk 【发布时间】:2016-06-13 16:39:53 【问题描述】:

我在构建签名的 apk 时遇到错误。我做了很多事情,但没有任何帮助......我将发布带有错误的消息。也许是我的错?

Information:Gradle tasks [:app:assembleRelease]
:app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:checkReleaseManifest
:app:preDebugBuild UP-TO-DATE
:app:prepareComandroidSupportAnimatedVectorDrawable2340Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72340Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2340Library UP-TO-DATE
:app:prepareComAndroidSupportMediarouterV72300Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72340Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42340Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2340Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAds902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAuth902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAuthBase902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesCast902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesDrive902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesFitness902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGames902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGcm902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesIdentity902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesIid902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesNearby902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPanorama902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPlus902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesTagmanager902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerApi902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesTasks902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesVision902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWallet902Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWearable902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseAnalytics902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseAnalyticsImpl902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseAuth902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseAuthCommon902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseAuthModule902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseCommon902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseConfig902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseCrash902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseDatabase902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseDatabaseConnection902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseIid902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseMessaging902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseStorage902Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseStorageCommon902Library UP-TO-DATE
:app:prepareReleaseDependencies
:app:compileReleaseAidl
:app:compileReleaseRenderscript
:app:generateReleaseBuildConfig
:app:mergeReleaseShaders
:app:compileReleaseShaders
:app:generateReleaseAssets
:app:mergeReleaseAssets
:app:generateReleaseResValues
:app:generateReleaseResources
:app:mergeReleaseResources
:app:processReleaseManifest
:app:processReleaseResources
:app:generateReleaseSources
:app:incrementalReleaseJavaCompilationSafeguard
:app:compileReleaseJavaWithJavac
:app:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources
:app:lintVitalRelease
:app:prePackageMarkerForRelease
:app:transformClassesWithDexForRelease
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
:app:transformClassesWithDexForRelease FAILED
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 2 mins 41.454 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console

这些是错误

错误 1:

Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

错误 2:

Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

我希望任何人都可以帮助我解决这个可怕的错误

【问题讨论】:

错误:.dex文件中的方法引用数不能超过64K。在developer.android.com/tools/building/multidex.html 了解如何解决此问题 那个^以及To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties 或者,修复您的 Google Play 服务依赖项,使其不包含所有项。请参阅此页面上的第二个蓝色框。 developers.google.com/android/guides/… multidex ***.com/questions/32407985/… 在 multidex 之前修复 Google play 服务,不过 【参考方案1】:

错误 1 ​​清楚地说明了原因。这是解决方案

查看您的应用程序的直接和传递依赖项 - 确保您在应用程序中包含的任何大型库依赖项的使用方式都超过了添加到应用程序中的代码量。一个常见的反模式是包含一个非常大的库,因为一些实用方法很有用。减少应用代码依赖通常可以帮助您避免 dex 引用限制。

使用 ProGuard 删除未使用的代码 - 为您的应用配置 ProGuard 设置以运行 ProGuard,并确保您为发布构建启用了收缩功能。启用压缩可确保您不会随 APK 一起发送未使用的代码。

也在你的 build.gradle 添加这个

defaultConfig 
// Other settings here
multiDexEnabled true

【讨论】:

只有 multiDexEnabled true 不启用 Multidex,不过 它有帮助!谢谢!!

以上是关于我将构建签名的 apk 时出错的主要内容,如果未能解决你的问题,请参考以下文章

构建 APK 时出错:算法 HmacPBESHA256 不可用

Android - 使用 apktool 将项目构建为 APK 文件时出错

签名分发 iOS 应用程序时出错“无法为签名者构建自签名根的链”

由于 proguard 规则,生成签名 APK 时出错

创建签名的 apk 时构建失败

我如何生成使用Firebase Auth的签名APK?]