Android Studio构建版本apk失败

时间:2017-02-16 04:37:30

标签: android android-studio gradle windows-10

这是适用于带有Windows 10的android studio 2.2.3。

为我的应用程序gradle构建版本apk时失败。

构建调试apk时,一切正常。

我重新安装了android studio。我还重建了这个项目,并对构建进行了很多清理。

我尝试更改依赖项的版本。 使用内置的java jdk,以及来自oracle的当前java jdk。 更改jackOptions会启用true和false。 启用Minified enabled和sip align true和false。 改变我的proguard文件。 使用不同大小的堆。 我关闭了Android studio并从主项目目录中删除了.gradle并再次打开了项目并重建了它。

我在gradle控制台中注意到Executing java进程一直在重启。不确定这是否重要,并且在该行之前它表明StoredItem为null。两者都有信息标签。

我已经有这个问题好几个星期,我已经在互联网上搜索过了。

这是堆栈跟踪。

Error:23:04:00.648 [ERROR] [org.gradle.BuildExceptionReporter] 
23:04:00.648 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
23:04:00.648 [ERROR] [org.gradle.BuildExceptionReporter] 
23:04:00.649 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
23:04:00.649 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':askGodWhy:transformClassesWithPreJackPackagedLibrariesForFreeRelease'.
23:04:00.649 [ERROR] [org.gradle.BuildExceptionReporter] > java.lang.UnsupportedOperationException (no error message)
23:04:00.653 [ERROR] [org.gradle.BuildExceptionReporter] 
23:04:00.653 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
23:04:00.654 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':askGodWhy:transformClassesWithPreJackPackagedLibrariesForFreeRelease'.
23:04:00.655 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
23:04:00.656 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
23:04:00.663 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
23:04:00.664 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
23:04:00.671 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
23:04:00.675 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
23:04:00.681 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
23:04:00.696 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
23:04:00.704 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
23:04:00.704 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
23:04:00.704 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
23:04:00.704 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
23:04:00.705 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
23:04:00.705 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
23:04:00.705 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
23:04:00.705 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
23:04:00.705 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
23:04:00.705 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
23:04:00.706 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
23:04:00.706 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
23:04:00.707 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
23:04:00.707 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
23:04:00.708 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:153)
23:04:00.709 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.Factories$1.create(Factories.java:22)
23:04:00.709 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
23:04:00.709 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
23:04:00.710 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:150)
23:04:00.711 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
23:04:00.711 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:98)
23:04:00.748 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:92)
23:04:00.749 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
23:04:00.749 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
23:04:00.749 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:92)
23:04:00.749 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83)
23:04:00.749 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:99)
23:04:00.753 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:46)
23:04:00.754 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
23:04:00.754 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:58)
23:04:00.755 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
23:04:00.755 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:48)
23:04:00.756 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
23:04:00.756 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:81)
23:04:00.761 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:46)
23:04:00.761 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
23:04:00.762 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
23:04:00.762 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.762 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
23:04:00.763 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.764 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
23:04:00.764 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.765 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
23:04:00.765 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.766 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
23:04:00.767 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
23:04:00.768 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.util.Swapper.swap(Swapper.java:38)
23:04:00.768 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
23:04:00.769 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.769 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
23:04:00.769 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.769 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
23:04:00.769 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
23:04:00.769 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.771 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
23:04:00.771 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
23:04:00.771 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.772 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
23:04:00.772 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
23:04:00.772 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
23:04:00.773 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:237)
23:04:00.773 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
23:04:00.773 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
23:04:00.774 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.UnsupportedOperationException
23:04:00.777 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.ide.common.process.ProcessInfoBuilder$JavaProcessInfoImpl.getExecutable(ProcessInfoBuilder.java:349)
23:04:00.777 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:74)
23:04:00.777 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:49)
23:04:00.777 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackCli(AndroidBuilder.java:1834)
23:04:00.778 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJack(AndroidBuilder.java:1645)
23:04:00.778 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.builder.internal.compiler.JackConversionCache.convertLibrary(JackConversionCache.java:99)
23:04:00.779 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.tasks.JackPreDexTransform.runJack(JackPreDexTransform.java:174)
23:04:00.779 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.tasks.JackPreDexTransform.transform(JackPreDexTransform.java:119)
23:04:00.779 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:178)
23:04:00.779 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:174)
23:04:00.779 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)
23:04:00.780 [ERROR] [org.gradle.BuildExceptionReporter]    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter]    ... 70 more
23:04:00.781 [ERROR] [org.gradle.BuildExceptionReporter] 

这是我的全局gradle文件。

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XX:MaxHeapSize=256m -Xmx256m"
        }
    }
    repositories {
        jcenter()
    }
}

这是我的gradle文件。

apply plugin: 'com.android.application'

android {
    signingConfigs {
        try {
            Release_KeyStore {
                keyAlias 'release_keystore'
                storePassword KEYSTORE_PASSWORD
                keyPassword KEY_PASSWORD
                storeFile file('Path_to_Release_Keystore.jks')
            }
        }
        catch (ex) {
            throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.")
        }
    }
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    defaultConfig {
       applicationId "MyAppId"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 6
        versionName "1.0.6"
        multiDexEnabled true
        signingConfig signingConfigs.Release_KeyStore
        resValue 'string', 'app_name', '"MyApp"'
        resValue 'string', 'app_directory', '"MyAppDirectory"'
        resValue 'string', 'banner_ad_unit_id', BANNER_AD_UNIT_ID
        resValue 'string', 'interstitial_ad_unit_id', INTERSTITIAL_AD_UNIT_ID
        resValue 'string', 'environment', ENVIRONMENT_RELEASE

        jackOptions {
            enabled false
            jackInProcess false
        }
    }
    dexOptions {
        javaMaxHeapSize "6g"
        jumboMode = true
    }
    buildTypes {
        debug {
            applicationIdSuffix '.debug'
            versionNameSuffix '-DEBUG'
            debuggable true
            jniDebuggable true
            renderscriptDebuggable true
            minifyEnabled false
            resValue 'string', 'app_name', '"MyApp"'
            resValue 'string', 'app_directory', '"MyAppDirectory"'
            resValue 'string', 'banner_ad_unit_id', BANNER_AD_UNIT_ID_TEST
            resValue 'string', 'interstitial_ad_unit_id', INTERSTITIAL_AD_UNIT_ID_TEST
            resValue 'string', 'environment', ENVIRONMENT_DEBUG

            jackOptions {
                enabled false
                jackInProcess false
            }
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.Release_KeyStore
            zipAlignEnabled true
            debuggable false
            renderscriptDebuggable false
            resValue 'string', 'app_name', '"MyApp"'
            resValue 'string', 'app_directory', '"MyAppDirectory"'
            resValue 'string', 'banner_ad_unit_id', BANNER_AD_UNIT_ID
            resValue 'string', 'banner_ad_unit_id', INTERSTITIAL_AD_UNIT_ID
            resValue 'string', 'environment', ENVIRONMENT_RELEASE

            jackOptions {
                enabled false
                jackInProcess false
            }
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    productFlavors {
        free {
            applicationId "MyAppId"
            minSdkVersion 16
            targetSdkVersion 25
            versionCode 6
            versionName "1.0.6"
            multiDexEnabled true
            signingConfig signingConfigs.Release_KeyStore
            resValue 'string', 'app_name', '"MyApp"'
            resValue 'string', 'app_directory', '"MyAppDirectory"'
            resValue 'string', 'banner_ad_unit_id', BANNER_AD_UNIT_ID
            resValue 'string', 'interstitial_ad_unit_id', INTERSTITIAL_AD_UNIT_ID
            resValue 'string', 'some_key', SOME_KEY
            resValue 'string', 'environment', ENVIRONMENT_RELEASE
        }
        paid {
            applicationId "MyAppId"
            minSdkVersion 16
            targetSdkVersion 25
            versionCode 6
            versionName "1.0.6"
            multiDexEnabled true
            signingConfig signingConfigs.Release_KeyStore
            resValue 'string', 'app_name', '"MyApp"'
            resValue 'string', 'app_directory', '"MyAppDirectory"'
            resValue 'string', 'some_key', SOME_KEY
            resValue 'string', 'environment', ENVIRONMENT_RELEASE
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
    sourceSets {
        main {
            res.srcDirs = ['src/main/res/layouts/pages',
                           'src/main/res/layouts/components',
                           'src/main/res/layouts',
                           'src/main/res'
            ]
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
task debug << {
    configurations.compile.each { println it }
}
// only needed for SNAPSHOT builds
repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
    //compile project(':library')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'junit:junit:4.12'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.google.android.gms:play-services-ads:10.0.1'
    compile 'com.googlecode.json-simple:json-simple:1.1.1'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.squareup.okhttp3:okhttp:3.6.0'
    compile 'com.squareup.okio:okio:1.11.0'
    compile 'com.fasterxml.jackson.core:jackson-core:2.8.6'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.6'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.6'
    compile 'com.jakewharton.timber:timber:4.3.0'
    compile 'org.slf4j:slf4j-api:1.7.21'
    compile 'com.github.tony19:logback-android-core:1.1.1-6'
    compile('com.github.tony19:logback-android-classic:1.1.1-6') {
        // workaround issue #73
        exclude group: 'com.google.android', module: 'android'
    }
}

这是我的proguard文件。

-keepattributes *Annotation*,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-keep class org.codehaus.** { *; }
-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
    public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; 
}
-keep class com.fasterxml.jackson.databind.ObjectMapper {
    public <methods>;
    protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
    public ** writeValueAsString(**);
}
-keep class com.fasterxml.jackson.annotation.** { *; }

#All my Dto classes for serializing and de-serializing service requests.
-keep public class MyDtoClasses.** {
  public void set*(***);
  public *** get*();
}

-keep class okhttp3.** { *; } 
-keep interface okhttp3.** { *; } 
-dontwarn okhttp3.**

-dontskipnonpubliclibraryclasses
-optimizationpasses 5
-printmapping map.txt
-flattenpackagehierarchy
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes EnclosingMethod

-keep public class * extends android.app.Application
-keep public class * extends android.app.Activity
-keep public class * extends android.app.PreferenceActivity
-keep public class * extends android.view.View
-keep public class * extends android.widget.BaseAdapter
-keep public class * implements android.view.View.OnTouchListener

-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 android.os.Parcelable$Creator CREATOR;
}

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

-dontobfuscate
-keep public class com.google.android.gms.* { public *; }
-dontwarn javax.mail.**
-dontwarn javax.naming.Context
-dontwarn javax.naming.InitialContext
-dontwarn junit.framework.TestCase
-dontwarn junit.framework.TestSuite
-dontwarn junit.runner.BaseTestRunner
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn java.nio.file.**
-dontwarn java.lang.management.**
-dontwarn java.beans.**

如果我需要提供任何其他内容,请告诉我。

1 个答案:

答案 0 :(得分:0)

首先感谢@Zaki的所有帮助。

我将我的解决方案移到了更新的计算机上并收到了更多错误,比如我的代码使用的java.util库只适用于api 24及更高版本。

我将我的android工作室改为使用打包的java 8版本。

当我切换到java 8时,我已经启用了插孔并且版本为8,但这打破了发布版本的所有内容。

然后我将其从true切换为false。

jackOptions {
                enabled false
            }

然后我将其设置为8到7。

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

只要您的代码和项目中包含的库适用于Java 7,您的代码就应该构建用于发布。