Proguard问题:java.lang.RuntimeException ProGuardTransform

时间:2017-01-30 16:29:20

标签: android proguard

一直想弄清楚这个问题。我有点像Android菜鸟,我可以处理代码但是当涉及到配置问题时,我有点迷失。我已经继承了这个项目,但尚未找到解决方案。

构建APK时,我遇到了一个模糊的proguard问题。如果我从发布版本变体的Gradle配置中删除proguard和minifyEnabled,则APK构建正常,尽管它比应该大10 mb更大。

release {
    debuggable false
    //minifyEnabled true
    //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    signingConfig signingConfigs.release
    zipAlignEnabled true
    multiDexEnabled true
}

更多背景知识,这个项目已经更新了大约两年,现在我已经将一些工具更新到最新版本(Gradle,Android Studio,Android 7)。

我得到的警告之一是关于弃用。这会导致这个问题吗?我已经看过了一些弃用问题而且他们不能快速修复,所以我现在正在跳过它,除非有人确定这会引导我找到某种解决方案。

如果您需要更多信息,请告诉我,但我认为已经有很多信息了。我没有发布proguard文件,因为我已尝试使用minifyEnabled设置并注释掉proguardFiles getDefaultProguardFile...,但错误仍然存​​在。我可能错了,但我认为没有配置文件就会运行proguard。无论如何,如果你也需要,请告诉我。

以下错误消息。

注意:

1 - 不知道okio.Okio问题的来源,因为我无法找到该库的踪迹,并且我多次清理了构建文件夹。它必须是项目依赖项之一的一部分!?

2 - ***表示我删除了一些文字以保留我工作的公司名称为匿名。

Error:11:11:26.628 [ERROR] [system.err] Note: Some input files use or override a deprecated API.
11:11:26.628 [ERROR] [system.err] Note: Recompile with -Xlint:deprecation for details.
11:11:30.516 [ERROR] [system.err] Note: Some input files use or override a deprecated API.
11:11:30.516 [ERROR] [system.err] Note: Recompile with -Xlint:deprecation for details.
11:11:30.516 [ERROR] [system.err] Note: Some input files use unchecked or unsafe operations.
11:11:30.516 [ERROR] [system.err] Note: Recompile with -Xlint:unchecked for details.
11:11:35.088 [ERROR] [system.err] Note: /Users/***/Development/***/***-android/***/src/main/java/com/***/***/activities/***MainActivity.java uses or overrides a deprecated API.
11:11:35.088 [ERROR] [system.err] Note: Recompile with -Xlint:deprecation for details.
11:11:37.322 [ERROR] [system.err] Note: there were 11 duplicate class definitions.
11:11:37.322 [ERROR] [system.err]       (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
11:11:38.451 [ERROR] [system.err] Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
11:11:38.451 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.Files
11:11:38.451 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.Files
11:11:38.451 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.Files
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.Path
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.Path
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.Path
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.Path
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption
11:11:38.452 [ERROR] [system.err] Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
11:11:45.207 [ERROR] [system.err] Warning: there were 14 unresolved references to classes or interfaces.
11:11:45.207 [ERROR] [system.err]          You may need to add missing library jars or update their versions.
11:11:45.207 [ERROR] [system.err]          If your code works fine without the missing classes, you can suppress
11:11:45.207 [ERROR] [system.err]          the warnings with '-dontwarn' options.
11:11:45.207 [ERROR] [system.err]          (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
11:11:45.227 [ERROR] [org.gradle.BuildExceptionReporter] 
11:11:45.227 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
11:11:45.227 [ERROR] [org.gradle.BuildExceptionReporter] 
11:11:45.227 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
11:11:45.227 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':***:transformClassesAndResourcesWithProguardForStagingRelease'.
11:11:45.227 [ERROR] [org.gradle.BuildExceptionReporter] > Job failed, see logs for details
11:11:45.228 [ERROR] [org.gradle.BuildExceptionReporter] 
11:11:45.228 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
11:11:45.228 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':***:transformClassesAndResourcesWithProguardForStagingRelease'.
11:11:45.228 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
11:11:45.229 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.RuntimeException: Job failed, see logs for details
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.transforms.ProGuardTransform.transform(ProGuardTransform.java:196)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:178)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:174)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173)
11:11:45.230 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    ... 14 more
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.io.IOException: Please correct the above warnings first.
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at proguard.Initializer.execute(Initializer.java:473)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at proguard.ProGuard.initialize(ProGuard.java:233)
11:11:45.231 [ERROR] [org.gradle.BuildExceptionReporter]    at proguard.ProGuard.execute(ProGuard.java:98)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:54)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:254)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.transforms.ProGuardTransform.access$000(ProGuardTransform.java:63)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.transforms.ProGuardTransform$1.run(ProGuardTransform.java:173)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.builder.tasks.Job.runTask(Job.java:49)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:223)
11:11:45.232 [ERROR] [org.gradle.BuildExceptionReporter] 

Gradle的配置文件。

顶级应用配置

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    repositories {
        mavenCentral()
        maven { url '// For some reason this only works when in the top level build.gradle!' }
        maven { url 'http://files.couchbase.com/maven2' }
        flatDir { dirs '../***/libs' }
    }
}
```

## App project config
```
apply plugin: 'com.android.application'

dependencies {
    compile project(':***')
}

android {

    buildToolsVersion "23.0.3"
    compileSdkVersion 25

    defaultConfig {
        applicationId "com.***.***"

        // Code is compatible with Android 5 onwards.  There are all kinds of issues on KitKat.
        minSdkVersion 20

        // targetSdkVersion is 22 so that Dangerous permissions are granted when app is installed
        targetSdkVersion 25
        versionCode 29
        versionName "3.3.1"
    }

    signingConfigs {
        release
    }

    buildTypes {
        debug {
            debuggable true
        }
        release {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.release
            zipAlignEnabled true
            multiDexEnabled true
        }
    }

    productFlavors {
        development
        production
        staging
    }

    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
    }
}

// Load the signing config from release.properties
def props = new Properties()
props.load(new FileInputStream(rootProject.file("release.properties")))
android.signingConfigs.release.storeFile rootProject.file(props.keyStore)
android.signingConfigs.release.storePassword props.keyStorePassword
android.signingConfigs.release.keyAlias props.keyAlias
android.signingConfigs.release.keyPassword props.keyAliasPassword

库配置(此库是我们的)

apply plugin: 'com.android.library'

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    // bug reports
    compile 'com.bugsnag:bugsnag-android:+'
    compile fileTree(include: '**/*.jar', dir: 'libs')
    // Used for the tour. Pulls in support-v4.
    compile project(':viewpagerindicator')
    // Used for the FragmentPagerAdapter used in the tour
    compile 'com.android.support:support-v13:25.1.0'

    // Couchbase
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.couchbase.lite:couchbase-lite-android:1.3.1'

    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.4'
    compile 'com.github.tony19:logback-android-classic:1.1.1-4'
    // Used for maps
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.google.zxing:core:3.1.0'
    compile 'com.mobsandgeeks:android-saripaar:1.0.3'
    compile('com.spothero.volley:volley-jackson-extension:1.0.1') {
        exclude group: 'com.fasterxml.jackson.core'
    }
    compile 'joda-time:joda-time:2.6'
    compile 'org.roboguice:roboguice:2.0'
    compile('org.simpleframework:simple-xml:2.7.1') {
        exclude group: 'stax', module: 'stax-api'
        exclude group: 'xpp3', module: 'xpp3'
    }
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'io.card:android-sdk:5.3.0'
    compile(name:'ScanditBarcodeScanner', ext:'aar')
}

android {
    buildToolsVersion "23.0.3"
    compileSdkVersion 25
    defaultConfig {
        // Code is compatible with Android 5 onwards.  There are all kinds of issues on KitKat.
        minSdkVersion 20

        // targetSdkVersion is 22 so that Dangerous permissions are granted when app is installed
        targetSdkVersion 25
        versionCode 29
        versionName "3.3.1"
    }

    // workaround for "duplicate files during packaging of APK" issue
    // see https://groups.google.com/d/msg/adt-dev/bl5Rc4Szpzg/wC8cylTWuIEJ
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    useLibrary 'org.apache.http.legacy'
}

2 个答案:

答案 0 :(得分:1)

No idea where the okio.Okio这是一个ionio库,由你的gradle中的一个依赖项使用,它可能是com.spothero.volley:volley-jackson-extension,因为这是一个齐射的扩展,它在那里使用okHttp

要删除此警告,您可以在proguard中添加此警告:-dontwarn okio.**

答案 1 :(得分:0)

Juste在proguard文件中添加忽略警告:

-ignorewarnings