proguard android studio 中的错误,无法使用 minifyenabled true 构建我的项目
Posted
技术标签:
【中文标题】proguard android studio 中的错误,无法使用 minifyenabled true 构建我的项目【英文标题】:Error in proguard android studio, cant build my project with minifyenabled true 【发布时间】:2019-07-14 01:34:06 【问题描述】:我正在使用 android studio 3.1.3, 在使用 proguard 生成签名 apk 时出现以下错误
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to realm-android-library-object-server.aar (io.realm:realm-android-library-object-server:5.8.0) 1ms
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to material-ripple.aar (com.balysv:material-ripple:1.0.2)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to dexter.aar (com.karumi:dexter:5.0.0)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to carousel.aar (com.azoft.carousellayoutmanager:carousel:1.2.4) 1ms
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to recyclerview-v7.aar (com.android.support:recyclerview-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to recyclerview-v7.aar (com.android.support:recyclerview-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to RippleEffect.aar (com.github.emanzanoaxa:RippleEffect:52ea2a0ab6) 1ms
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to recyclerview-v7.aar (com.android.support:recyclerview-v7:27.1.1) 1ms
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to recyclerview-v7.aar (com.android.support:recyclerview-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to cardview-v7.aar (com.android.support:cardview-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to md-toast.aar (com.valdesekamdem.library:md-toast:0.9.0)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to number-picker.aar (com.shawnlin:number-picker:2.4.4) 1ms
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to appcompat-v7.aar (com.android.support:appcompat-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to appcompat-v7.aar (com.android.support:appcompat-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to appcompat-v7.aar (com.android.support:appcompat-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to appcompat-v7.aar (com.android.support:appcompat-v7:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to android-pdf-viewer.aar (com.github.barteksc:android-pdf-viewer:3.1.0-beta.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to pdfium-android.aar (com.github.barteksc:pdfium-android:1.9.0)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to support-v4.aar (com.android.support:support-v4:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to support-v4.aar (com.android.support:support-v4:27.1.1) 1ms
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to support-v4.aar (com.android.support:support-v4:27.1.1)
Apply org.gradle.api.internal.artifacts.transform.VariantAttributeMatchingCache$1@293fc229 to support-v4.aar (com.android.support:support-v4:27.1.1)
我已将我的代码和错误放在以下链接中
https://pastebin.com/JGDaGz5D
还有我的proguard文件
https://pastebin.com/6LgFX14J
【问题讨论】:
发布完整的日志和您的 proguard 文件 - 您在此处发布的内容没有错误。通常你可以安全地忽略 proguard 问题来构建签名的 apk - 但你需要在文件中抑制它们 在您发布您的 proguard 文件后查看我编辑的答案。 【参考方案1】:将此代码放入您的 progard 文件中
# Proguard Configuration for Realm (http://realm.io)
# For detailed discussion see: https://groups.google.com/forum/#!topic/realm-java/umqKCc50JGU
# Additionally you need to keep your Realm Model classes as well
# For example:
# -keep class com.yourcompany.realm.** *;
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class *
-dontwarn javax.**
-dontwarn io.realm.*
-keep class cz.msebera.android.httpclient.** *;
-keep class com.loopj.android.http.** *;
*
【讨论】:
如果它有帮助,请给予权利,我将获得 15 个学分【参考方案2】:如果您在项目中使用领域,请尝试将其添加到 proguard 文件中。
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class *
-keep class sun.misc.*
-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient
-keep class cz.msebera.android.httpclient.** *;
-keep class com.loopj.android.http.** *;
-dontwarn javax.**
-dontwarn io.realm.**
-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslError
-dontwarn android.webkit.WebViewClient
【讨论】:
以上是关于proguard android studio 中的错误,无法使用 minifyenabled true 构建我的项目的主要内容,如果未能解决你的问题,请参考以下文章
Proguard 在 android Studio 中开箱即用?这是啥意思?
如何在 android studio gradle 中降级 proguard 版本?
在 android studio 中找不到 proguard-project.txt
在 Android Studio 中使用 ProGuard 时我无法构建应用程序