Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在启用proguard的发布模式下编译Android应用程序时出现问题_Android_Android Studio_Proguard_Android Proguard - Fatal编程技术网

在启用proguard的发布模式下编译Android应用程序时出现问题

在启用proguard的发布模式下编译Android应用程序时出现问题,android,android-studio,proguard,android-proguard,Android,Android Studio,Proguard,Android Proguard,我试图用proguard编译我的Android应用程序,但我遇到了以下错误,不知道如何修复它们。有人知道吗?在调试模式下,一切都可以正常编译 Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver] Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory]

我试图用proguard编译我的Android应用程序,但我遇到了以下错误,不知道如何修复它们。有人知道吗?在调试模式下,一切都可以正常编译

Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver]
Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory]
Note: duplicate definition of library class [org.apache.http.conn.ConnectTimeoutException]
Note: duplicate definition of library class [org.apache.http.params.HttpParams]
Note: duplicate definition of library class [android.net.http.SslCertificate$DName]
Note: duplicate definition of library class [android.net.http.SslError]
Note: duplicate definition of library class [android.net.http.SslCertificate]
    Note: android.support.v4.app.NotificationCompatJellybean accesses a declared field 'title' dynamically
          Maybe this is program field 'android.support.v4.app.NotificationCompat$Action { java.lang.CharSequence title; }'
          Maybe this is program field 'android.support.v7.appcompat.R$attr { int title; }'
          Maybe this is program field 'android.support.v7.appcompat.R$id { int title; }'
          Maybe this is program field 'android.support.v7.mediarouter.R$attr { int title; }'
          Maybe this is program field 'android.support.v7.mediarouter.R$id { int title; }'
          Maybe this is program field 'com.facebook.share.internal.VideoUploader$UploadContext { java.lang.String title; }'
          Maybe this is program field 'com.facebook.share.model.GameRequestContent { java.lang.String title; }'
          Maybe this is program field 'com.facebook.share.model.GameRequestContent$Builder { java.lang.String title; }'
          Maybe this is program field 'com.google.android.gms.games.internal.player.PlayerColumnNames { java.lang.String title; }'
          Maybe this is program field 'com.google.android.gms.vision.barcode.Barcode$ContactInfo { java.lang.String title; }'
          Maybe this is program field 'com.google.android.gms.vision.barcode.Barcode$UrlBookmark { java.lang.String title; }'
          Maybe this is program field 'com.google.api.client.util.PemReader$Section { java.lang.String title; }'
          Maybe this is program field 'com.android.app.R$attr { int title; }'
          Maybe this is program field 'com.android.app.R$id { int title; }'
          Maybe this is program field 'com.android.app.adapter.InAppListItem { java.lang.String title; }'
          Maybe this is library field 'android.R$attr { int title; }'
          Maybe this is library field 'android.R$id { int title; }'
          Maybe this is library field 'android.app.Notification$Action { java.lang.CharSequence title; }'
          Maybe this is library field 'android.preference.PreferenceActivity$Header { java.lang.CharSequence title; }'
        Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.HttpRequestInitializer
        Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.HttpExecuteInterceptor
        Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.GenericUrl
        Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.http.HttpResponse
        Warning:library class com.google.api.client.auth.oauth2.TokenRequest depends on program class com.google.api.client.util.GenericData
        Warning:library class com.google.api.client.auth.oauth2.TokenResponse depends on program class com.google.api.client.json.GenericJson
        Warning:library class com.google.api.client.auth.oauth2.TokenResponse depends on program class com.google.api.client.util.GenericData
        Warning:library class com.google.api.client.auth.openidconnect.IdToken depends on program class com.google.api.client.json.webtoken.JsonWebSignature$Header
        Warning:library class com.google.api.client.auth.openidconnect.IdToken depends on program class com.google.api.client.json.JsonFactory
        Warning:library class com.google.api.client.auth.openidconnect.IdToken depends on program class com.google.api.client.json.webtoken.JsonWebToken$Payload
        Warning:library class com.google.api.client.auth.openidconnect.IdToken$Payload depends on program class com.google.api.client.json.webtoken.JsonWebToken$Payload
        Warning:library class com.google.api.client.auth.openidconnect.IdToken$Payload depends on program class com.google.api.client.json.GenericJson
        Warning:library class com.google.api.client.auth.openidconnect.IdToken$Payload depends on program class com.google.api.client.util.GenericData
        Warning:library class com.google.api.client.auth.openidconnect.IdTokenVerifier depends on program class com.google.api.client.util.Clock
        Warning:library class com.google.api.client.auth.openidconnect.IdTokenVerifier$Builder depends on program class com.google.api.client.util.Clock
            Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpRequestExecutor'
            Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpRequestInterceptorList'
            Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.HttpResponseInterceptorList'
            Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.protocol.SyncBasicHttpContext'
            Note: the configuration explicitly specifies 'org.apache.http.**' to keep library class 'org.apache.http.util.EntityUtils'
            Note: there were 2 references to unknown classes.
                  You should check your configuration for typos.
                  (http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
            Note: there were 112 library classes explicitly being kept.
                  You don't need to keep library classes; they are already left unchanged.
                  (http://proguard.sourceforge.net/manual/troubleshooting.html#libraryclass)
            Note: there were 16 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 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 146 instances of library classes depending on program classes.
                     You must avoid such dependencies, since the program classes will
                     be processed, while the library classes will remain unchanged.
                     (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
            Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
            :app:transformClassesAndResourcesWithProguardForRelease FAILED
            Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
            > java.io.IOException: Please correct the above warnings first.
我的Gradle文件如下所示:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.test.app"
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 240
        versionName "2.4.0"
        // Enabling multidex support.
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android.txt')
            proguardFile 'proguard-app.txt'
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.http-client:google-http-client-gson:1.20.0'
    compile 'com.google.code.gson:gson:2.4'
    compile "com.android.support:appcompat-v7:23.1.1"
    compile 'com.google.android.gms:play-services:8.3.0'

    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile 'com.android.support:support-v13:23.1.0'
    compile files('libs/google-api-client-1.18.0-rc.jar')
    compile files('libs/google-api-client-android-1.18.0-rc.jar')
    compile files('libs/google-http-client-android-1.18.0-rc.jar')
    compile files('libs/AudienceNetwork.jar')
}
下面是我的proguard文件proguard-app.txt:

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-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.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-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.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-keepattributes Exceptions,InnerClasses,Signature

-keep class com.google.api.client.**
-keepclassmembers class com.google.api.client.** {
    *;
 }


-keep class com.google.android.gms.**
-keepclassmembers class com.google.android.gms.** {
    *;
 }
-keep class com.google.gson.**
-keepclassmembers class com.google.gson.** {
    *;
 }


-keep class com.google.ads.**
-keepclassmembers class com.google.ads.** {
    *;
 }

-keep class bolts.**
-keepclassmembers class bolts.** {
    *;
 }

-keep class com.google.api.client.** { *; }
-dontwarn com.google.api.client.*
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.*

-libraryjars libs
#-injars libs/AudienceNetwork.jar
#-injars libs/google-api-client-1.18.0-rc.jar
#-injars libs/google-api-client-android-1.18.0-rc.jar
#-injars libs/google-http-client-android-1.18.0-rc.jar


 # The official support library.
-keep class android.support.v4.** { *; }
-keepclassmembers class android.support.v4.** {
    *;
 }
-keep interface android.support.v4.** { *; }
-keep class android.support.v7.** { *; }
-keepclassmembers class android.support.v7.** {
    *;
 }
-keep interface android.support.v7.** { *; }

# Library JARs.
-keep class com.facebook.** {
   *;
}
-keepclassmembers class com.facebook.** {
    *;
 }
#这是ProGuard的配置文件。
# http://proguard.sourceforge.net/index.html#manual/usage.html
-keep public class*扩展android.app.Activity
-keep public class*扩展android.app.Application
-keep public class*扩展了android.app.Service
-keep public class*扩展了android.content.BroadcastReceiver
-keep public class*扩展了android.content.ContentProvider
-keep public class*扩展了android.view.view{
public(android.content.Context);
public(android.content.Context、android.util.AttributeSet);
public(android.content.Context,android.util.AttributeSet,int);
公共无效集*(…);
}
-keepclassswithmembers类*{
public(android.content.Context、android.util.AttributeSet);
}
-keepclassswithmembers类*{
public(android.content.Context,android.util.AttributeSet,int);
}
-keepclassmembers类*扩展了android.content.Context{
public void*(android.view.view);
public void*(android.view.MenuItem);
}
-keepclassmembers类*实现android.os.Parcelable{
静态**创建者;
}
-keepclassmembers类**.R$*{
公共静态;
}
-keepclassmembers类*{
@android.webkit.JavascriptInterface;
}
-keepattributes异常、内部类、签名
-保留com.google.api.client类**
-keepclassmembers类com.google.api.client.*{
*;
}
-保留com.google.android.gms类**
-keepclassmembers类com.google.android.gms.*{
*;
}
-保持类com.google.gson**
-keepclassmembers类com.google.gson.*{
*;
}
-保持类com.google.ads**
-keepclassmembers类com.google.ads.*{
*;
}
-保持等级螺栓**
-keepclassmembers类螺栓。**{
*;
}
-保持类com.google.api.client.*{*;}
-dontwarn com.google.api.client*
-保持类org.apache.http.*{*;}
-dontwarn org.apache.http*
-图书馆馆藏
#-injars libs/AudienceNetwork.jar
#-injars libs/google-api-client-1.18.0-rc.jar
#-injars libs/google-api-client-android-1.18.0-rc.jar
#-injars libs/google-http-client-android-1.18.0-rc.jar
#官方支持图书馆。
-keep类android.support.v4.*{*;}
-keepclassmembers类android.support.v4.*{
*;
}
-保留android.support.v4.*{*;}
-keep类android.support.v7.*{*;}
-keepclassmembers类android.support.v7.*{
*;
}
-保留android.support.v7.*{*;}
#图书馆的罐子。
-保持类com.facebook.*{
*;
}
-keepclassmembers class com.facebook.*{
*;
}
更换

compile files('libs/google-api-client-1.18.0-rc.jar')
compile files('libs/google-api-client-android-1.18.0-rc.jar')
compile files('libs/google-http-client-android-1.18.0-rc.jar')


已修复此问题。

在proguard-rules.pro文件中添加以下行

-keep class android.support.v4.** { *; }
-dontnote android.support.v4.**

你为什么要应用
com.google.gms.google服务
plugin?因为谷歌分析需要这个。请参阅“谢谢”链接,出于好奇问:)可能是这个和这个可以帮助您。不是真的,因为它没有解释排除哪些软件包或模块这对我有帮助。
-keep class android.support.v4.** { *; }
-dontnote android.support.v4.**