ProGuard构建失败“未解析的引用”

时间:2015-09-25 01:15:28

标签: android proguard android-build android-proguard

我一直在研究我的应用程序的最新版本,它测试得很好,但是当我发布ProGuard版本时,我收到很多错误,主要是因为无法找到org.apache.http.*,我就是不要在我的项目中使用。我在整个项目中搜索了该文本但找不到它。我添加了一些依赖项,但我认为都没有使用HTTP。

我如何找出为什么 ProGuard正在抱怨并正确解决?它说我可以用“--stacktrace选项”运行,但我无法弄清楚如何做到这一点。

我感谢任何帮助,因为我发现ProGuard常常令人困惑。

构建输出:

Warning: com.google.android.gms.internal.zzw$zza: can't find superclass or interface org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzj: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification
Warning: com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning: com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzqj: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning: com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateParseException
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzy: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzy: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzby: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.tagmanager.zzby: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.ClientProtocolException
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpHost
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.message.BasicHttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
Warning: there were 148 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 program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning: there were 1 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
:GradeTrackerPro:proguardRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':MyApp:proguardRelease'.
> java.io.IOException: Please correct the above warnings first.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

来自我的Gradle文件:

android {
    compileSdkVersion 23
    buildToolsVersion "23"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')


        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'),
                        'proguard-rules.pro'
            }
        }

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }


    // to ignore warnings and strings not converted to all languages
    android {
        lintOptions {
            checkReleaseBuilds false
            // Or, if you prefer, you can continue to check for errors in release builds,
            // but continue the build even when errors are found:
            abortOnError false
        }
    }

我的proguard-rules.pro文件:

-keep class !android.support.v7.internal.view.menu.MenuBuilder, !android.support.v7.internal.view.menu.SubMenuBuilder, android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-dontwarn com.opencsv.bean.**

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable  # these last two lines keep info for debugging

# added these because proguard was complaining. Not sure where they could be referenced!



# For Flurry
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*, EnclosingMethod
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int) ;
}
# Google Play Services library
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents() ;
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}

2 个答案:

答案 0 :(得分:18)

在将buildTool更新为23.0之前,我从未遇到过这个问题。我可以在我的应用程序中使用这个较新版本的构建工具看到的唯一解决方法是,您需要将其添加到Progaurd.txt文件中。

-dontwarn android.support.v4.**
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

如果您在项目中使用Apache的Http,则还需要包含以下行:

-keepnames class org.apache.** {*;}
-keep public class org.apache.** {*;}    
-dontwarn org.apache.commons.logging.LogFactory
-dontwarn org.apache.http.annotation.ThreadSafe
-dontwarn org.apache.http.annotation.Immutable
-dontwarn org.apache.http.annotation.NotThreadSafe

请告诉我这是否有助于解决您的问题。

答案 1 :(得分:1)

如果您的应用使用旧的apache HttpClient,则必须将以下内容添加到build.gradle文件中:

useLibrary&#39; org.apache.http.legacy&#39;

如下所述:https://www.youtube.com/watch?v=yYU4DHLwoRk