web-dev-qa-db-ja.com

AndroidでのtransformClassesAndResourcesWithProguardForRelease 'エラー

こんにちは私は私のプロジェクトのリリースバージョンを作成するのに苦労しています。私は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.** { *; }
11
Sanjana Nair

ProGuardファイルに次を追加します。

-ignorewarnings

like:

# 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...
......
11
user8690908

ProGuardファイルに次を追加します。

_-dontwarn com.viewpagerindicator.**_

提供したリンクを開いて、「警告」を3分の2ほど下で検索すると、次のメッセージが表示されます。

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_を示している場合、コンパイルされたクラスファイルはライブラリと矛盾しています。クラスファイルを再コンパイルするか、ライブラリを一貫したバージョンにアップグレードしてください

あなたはもっと読むことができます ここ

6
Daniel Stanley

私の場合、プロジェクトが複数のモジュールで構成されていたため、proguardファイルは完全に無視されました。 この答え によると、解決策は、問題を引き起こしているモジュールのgradleに以下を設定することでした:

defaultConfig {
    consumerProguardFiles 'proguard-rules.txt'
}

これには、アプリケーションのプロガードにモジュールのプロガードが含まれているようです。 dontwarnステートメントが考慮されます。

0
Raslanove

私を助けたのは、すべての依存関係を最新バージョンに更新することでした。

0
beretis