【问题标题】:transformClassesAndResourcesWithProguardForRelease' error in AndroidAndroid 中的 transformClassesAndResourcesWithProguardForRelease 错误
【发布时间】:2016-03-03 20:07:03
【问题描述】:

您好,我正在努力为我的项目创建发布版本。我通过 SO / Google 帮助在 Progaurd 上尝试了很多东西,但我仍然无法创建发布版本。

有人可以帮我解决这个问题吗?我总是遇到这个问题:

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

这里是完整的详细错误:http://justpaste.it/perror 抱歉,我不得不把它作为链接,因为它很大。

以下是依赖项:

//compile fileTree(dir: 'libs', include: ['*.jar'])
 testCompile 'junit:junit:4.12'
 compile 'com.android.support:appcompat-v7:23.1.1'
 compile 'com.android.support:design:23.1.1'
 compile 'com.rengwuxian.materialedittext:library:2.1.4'
 compile 'com.squareup.picasso:picasso:2.5.2'
 compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
 compile 'org.apache.httpcomponents:httpcore:4.4.1'
 compile 'com.squareup.retrofit:retrofit:1.9.0'
 compile 'com.loopj.android:android-async-http:1.4.8'
 compile 'com.android.support:cardview-v7:23.1.1'
 compile 'com.android.support:recyclerview-v7:23.1.1'
 compile project(':pageIndicator')
 compile 'com.github.neopixl:PixlUI:v1.0.6'
 compile 'com.github.bumptech.glide:glide:3.6.1'

我的程序文件:

# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# 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:
-dontwarn com.google.code.**
-dontwarn  org.apache.**
-dontwarn  jp.wasabeef.recyclerview.**
-dontwarn  com.nostra13.universalimageloader.**
-dontwarn  org.acra.** 

#wasabeef recyclerview
-keep class jp.wasabeef.recyclerview.** { *; }
-keepattributes Signature
#HTTP Legacy
-keep class org.apache.** { *; }
-keepattributes Signature
#Universal Image Loader
-keep class com.nostra13.universalimageloader.** { *; }
-keepattributes Signature
#Acra
-keep class org.acra.**  { *; }
-keepattributes Signature
#Support libraries
-keep class com.android.** { *; }
-keepattributes Signature

# Keep the annotations
-keepattributes *Annotation*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''

-dontnote com.android.vending.licensing.ILicensingService

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
  public static <fields>;
}

# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep public class * {
    public protected *;
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}


-keep class com.splunk.** { *; }
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
    native <methods>;
}
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keep class com.splunk.** { *; }
-dontwarn rx.**

-dontwarn okio.**

-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }

-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.net.**

-dontwarn retrofit.**
-dontwarn retrofit.appengine.UrlFetchClient
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

-keepattributes Signature
-keepattributes *Annotation*

-keep class sun.misc.Unsafe { *; }
#your package path where your gson models are stored
-keep class com.ylg.others.** { *; }

【问题讨论】:

  • 看起来像是 gradle 文件的问题
  • 已知SDK版本、gradle版本和build tools版本不兼容时会出现这种问题:stackoverflow.com/questions/33877134/…我也遇到过同样的问题,一直没能解决它。我通过将minifyEnabled 设置为false 暂时修复了它。
  • @VedavyasBhat:如果我们这样做,它不会混淆我的代码吗?
  • @SanjanaNair 你找到解决这个问题的方法了吗?
  • @MuthuPandiyan:不。你有机会得到它吗?

标签: java android android-studio proguard android-proguard


【解决方案1】:

在您的 ProGuard 文件中添加:

-ignorewarnings

喜欢:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\Softwares\Developing\Android\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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile


-ignorewarnings

您不必指定像 com.viewpagerindicator.** 这样的任何包,这将抑制所有警告,Gradle Console 只会说:

......
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: there were 2 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)

Note: you're ignoring all warnings! 
Ignoring unused library classes...
  Original number of library classes: 4237
  Final number of library classes:    1317
Printing kept classes, fields, and methods...
Shrinking...
......

【讨论】:

    【解决方案2】:

    在您的 ProGuard 文件中添加:

    -dontwarn com.viewpagerindicator.**

    如果您打开您提供的链接并在大约三分之二处搜索“警告”,您会看到消息:

    Warning:com.viewpagerindicator.LinePageIndicator: can't find referenced method 'float ceil(float)' in library class android.util.FloatMath

    如果有任何警告 ProGuard 将停止并要求您先修复它们,或者如果您的代码有效,您可以选择使用 dontwarn 忽略它们。

    2017 年 5 月 1 日更新

    如果警告显示in program class,则可能是您编译的类文件不一致,请尝试将它们全部删除并重新构建您的项目。

    如果警告显示in library class 您编译的类文件与库不一致。尝试重新编译类文件或将库升级到一致版本

    您可以阅读更多here

    【讨论】:

    • 如果尝试使用找不到的方法,应用程序不会崩溃吗?
    • ^ 我拼命想弄清楚为什么 ProGuard 会拾取这些缺失的引用,而常规构建却没有,以及它们的威胁有多大。
    【解决方案3】:

    帮助我的是将所有依赖项更新到最新版本。

    【讨论】:

      【解决方案4】:

      在我的例子中,proguard 文件被完全忽略了,因为该项目由几个模块组成。根据this answer,解决方案是在导致问题的模块的gradle中设置以下内容:

      defaultConfig {
          consumerProguardFiles 'proguard-rules.txt'
      }
      

      这似乎在应用程序的 proguard 中包含了模块的 proguard。现在我的dontwarn 声明被考虑在内。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-18
        • 2016-06-16
        • 1970-01-01
        • 2019-09-29
        • 2017-08-29
        • 1970-01-01
        • 2015-12-08
        • 2017-12-16
        相关资源
        最近更新 更多