【问题标题】:proguardRelease FAILED when compiling apk with assembleRelease in Android Studio在Android Studio中使用assembleRelease编译apk时proguardRelease FAILED
【发布时间】:2015-02-17 07:26:09
【问题描述】:

我正在尝试在 Android Studio 1.0.1 中将我的应用程序编译为 assembleRelease 并收到以下消息:

FAILURE: Build failed with an exception.

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

应用程序在调试模式下完美编译和运行,并且 assembleRelease 与 Android Studio 0.8 配合使用。

proguard-rules.pro 文件为空。 build.gradle 文件和完整错误如下所示。

有人可以帮忙吗?

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion '19.1'

    defaultConfig {
        applicationId "com.xxx.xxx"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
        absolutePaths false
        lintConfig file("lint.xml")
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'aars'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.urbanairship:urbanairship-lib:+@aar'
    compile 'com.google.android.gms:play-services:6.1.+'
    compile 'me.grantland:autofittextview:0.1.1@aar'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'net.danlew:android.joda:2.3.4@aar'
    compile 'com.android.support:support-v4:21.0.0'
    compile 'com.android.support:support-v13:21.0.0'
    compile 'com.squareup.okio:okio:1.0.0@jar'
    compile 'net.danlew:android.joda:2.4.0'
    compile 'de.greenrobot:eventbus:2.2.1'
    compile 'se.emilsjolander:stickylistheaders:2.5.0'
    compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.sothree.slidinguppanel:library:2.0.2'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'de.greenrobot:eventbus:2.4.0'
}

错误是

13:40:19: Executing external task 'assembleRelease'...
:app:preBuild
:app:preReleaseBuild
:app:checkReleaseManifest
:app:preDebugBuild
:app:prepareComAndroidSupportSupportV132100Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42100Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices6171Library UP-TO-DATE
:app:prepareComSothreeSlidinguppanelLibrary202Library UP-TO-DATE
:app:prepareComUrbanairshipUrbanairshipLib510Library UP-TO-DATE
:app:prepareMeGrantlandAutofittextview011Library UP-TO-DATE
:app:prepareNetDanlewAndroidJoda240Library UP-TO-DATE
:app:prepareSeEmilsjolanderStickyScrollViewItems110Library UP-TO-DATE
:app:prepareSeEmilsjolanderStickylistheaders250Library UP-TO-DATE
:app:prepareReleaseDependencies
:app:compileReleaseAidl
:app:compileReleaseRenderscript
:app:generateReleaseBuildConfig
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources
:app:mergeReleaseResources
:app:processReleaseManifest
:app:processReleaseResources
:app:generateReleaseSources
Note: <path_to_my_project>/app/src/main/java/com/xxx/xxx/fragments/MatchCenterFragment.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:app:compileReleaseJava
:app:lintVitalRelease
:app:compileReleaseNdk
:app:proguardRelease
Warning: com.ooyala.android.player.WidevineLibPlayer: can't find superclass or interface com.widevine.drmapi.android.WVEventListener
( more com.ooyala.* warnings )
Warning: com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning: com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning: com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpsURLConnection: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpURLConnection
Warning: com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpsURLConnection: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpURLConnection
Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Files
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class java.nio.file.Path
Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning: there were 234 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 4 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)
:app:proguardRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app: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

Total time: 14.674 secs
Please correct the above warnings first.
13:40:35: External task execution finished 'assembleRelease'.

【问题讨论】:

  • 构建输出有许多关于错误引用的警告,尽管它称它们为“警告”,但最终看起来它们是致命错误。
  • @ScottBarta 但它在调试中工作,所以这似乎是proguard的问题,我不知道如何调试。

标签: android-studio proguard


【解决方案1】:

将此添加到 ProGuard 设置文件(如 proguard-rules.pro)

-dontwarn okio.**

【讨论】:

  • 这一行放在哪里
  • @septemberboy7 放入 proguard 设置文件,如 'proguard-rules.pro'
  • 对导致此问题的每个库都使用 dontwarn。正确答案 - 点赞
  • @hoi 请求用一些详细信息解释答案。为什么这个声明是必需的?它是做什么的?
  • @Chitrang 我按照描述“如果您的代码在没有缺少类的情况下工作正常,您可以使用 '-dontwarn' 选项抑制警告。
【解决方案2】:

我不得不用

禁用proguard
minifyEnabled false

不是最好的解决方案,但它确实有效。

【讨论】:

  • 小心使用 minifyEnabled false,它将禁用保护您的应用程序并减小 apk 大小。
  • 如果你将 minifyEnabled 设置为 false,proguard 不会混淆你的代码!通常,您必须在发布模式下将其设置为 true。
  • 如果你反编译应用程序,所有人都可以看到你的代码,不是解决方案是安全问题,minifyEnabled false 仅用于开发
  • 这将在生产中寻找你的生命
  • 不要这样做,正如上面每个人所说,你不是在这里解决问题,你只是通过禁用 Proguard 来避免它
【解决方案3】:

将此添加到 ProGuard 设置文件(如 proguard-rules.pro)

-ignorewarnings 

【讨论】:

  • 拯救了我的一天!像魅力一样工作。我得到了他的 transformclassesandresourceswithproguardforUat 错误
【解决方案4】:

我在使用 Gradle 1.1.0 时遇到了同样的问题。它记得一些我已经移动的旧类引用,我无法构建 apk。

尝试构建 > 清理

它帮助了我,现在我可以再次构建 apk。

【讨论】:

    【解决方案5】:

    我想你已经解决了你的问题。无论如何,请参阅此链接:https://stackoverflow.com/a/29858070/3864698

    计划针对 Gradle 插件 1.4 版进行修复。所以我们必须稍等片刻。

    【讨论】:

      猜你喜欢
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多