迁移到Gradle Plugin 3.0后编译时出现DexArchiveBuilderException

时间:2017-11-01 21:23:27

标签: android android-studio gradle android-gradle build.gradle

我最近将我们的Android应用程序的gradle插件从2.3.3升级到3.0.0。在解决了大部分编译问题后,我仍然受到以下异常的困扰:

com.android.build.api.transform.TransformException: 
com.android.builder.dexing.DexArchiveBuilderException: 
com.android.builder.dexing.DexArchiveBuilderException: 
Failed to process /Users/{user}/SourceCode/Android/{project_path}/build/intermediates/transforms/profilers-transform/debug/113.jar

{user}{project_path}字段是实际值的占位符。

我并不完全确定究竟发生了什么,但是从堆栈跟踪的外观来看,构建无法解决我们的第三方问题(Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing com/outbrain/OBSDK/HttpClient/OBHttpClient.class)。关于这一点的奇怪之处在于,如果我在内部构建项目,或者如果我为调试和发布构建并生成apks,则构建按预期工作。它只有当我尝试在模拟器上部署应用程序时才收到此错误。

非常感谢任何有关此错误发生原因的见解。

注意:我已经引用了Google文档(https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html),但我对此问题一无所知。

这是相关堆栈跟踪的输出:

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/{user}/SourceCode/Android/{project_path}/build/intermediates/transforms/profilers-transform/debug/113.jar
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:550)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.lambda$convertToDexArchive$1(DexArchiveBuilderTransform.java:488)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing com/outbrain/OBSDK/HttpClient/OBHttpClient.class

at com.android.builder.dexing.DxDexArchiveBuilder.getExceptionToRethrow(DxDexArchiveBuilder.java:143)
at com.android.builder.dexing.DxDexArchiveBuilder.convert(DxDexArchiveBuilder.java:89)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:545)
... 6 more

Caused by: com.android.dx.cf.code.SimException: stack: underflow
at com.android.dx.cf.code.ExecutionStack.throwSimException(ExecutionStack.java:341)
at com.android.dx.cf.code.ExecutionStack.peek(ExecutionStack.java:206)
at com.android.dx.cf.code.ExecutionStack.peekType(ExecutionStack.java:241)
at com.android.dx.cf.code.Simulator$SimVisitor.visitNoArgs(Simulator.java:427)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:584)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:103)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:790)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:745)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:350)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:309)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:150)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:102)
at com.android.builder.dexing.DxDexArchiveBuilder.dex(DxDexArchiveBuilder.java:107)
at com.android.builder.dexing.DxDexArchiveBuilder.convert(DxDexArchiveBuilder.java:86)
... 7 more

修改:将项目build.gradle添加到问题中。注意:为敏感信息添加了占位符:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://dl.bintray.com/optimizely/optimizely'
        }
    }
}

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

        // The Fabric Gradle plugin uses an open ended version to
        // react quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.+'

        classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'

        // Kotlin Support
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.51'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.jakewharton.hugo'
apply plugin: 'kotlin-android'

repositories {
    jcenter()
    maven {
        url 'https://maven.fabric.io/public'
    }
    maven {
        url "http://appboy.github.io/appboy-android-sdk/sdk"
    }
    maven {
        url  "http://dl.bintray.com/teads/TeadsSDK-android"
    }
    maven {
        url "https://jitpack.io"
    }
    flatDir {
        dirs 'libs'
    }
    google()
}

// Test Dependencies
dependencies {
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    testCompile 'org.robolectric:robolectric:3.0'
    testCompile 'org.robolectric:shadows-multidex:3.0'
    testCompile 'org.robolectric:shadows-play-services:3.0'
    testCompile 'org.easytesting:fest-assert-core:2.0M10'
    // testCompile 'org.easytesting:fest-assert:1.4'
    testCompile 'org.powermock:powermock-module-junit4:1.6.4'
    testCompile 'org.powermock:powermock-module-junit4-rule:1.6.4'
    testCompile 'org.powermock:powermock-api-mockito:1.6.4'
    testCompile 'org.powermock:powermock-classloading-xstream:1.6.4'
}

dependencies {

    def appCompatVersion = "25.3.1"
    def playServicesVersion = "11.0.4"

    compile project(':BRShared')
    compile project(':CastCompanionLibrary-android')
    wearApp project(':wear')

    compile fileTree(dir: 'libs', include: '*.jar')

    compile(name: 'sharethrough-android-sdk-v4.4.0', ext: 'aar')
    compile('com.optimizely:optimizely:+@aar') {
        transitive = true
    }

    compile 'com.android.volley:volley:1.0.0'
    compile "com.google.android.gms:play-services:$playServicesVersion"

    compile "com.android.support:support-v4:$appCompatVersion"
    compile "com.android.support:appcompat-v7:$appCompatVersion"
    compile "com.android.support:design:$appCompatVersion"
    compile "com.android.support:cardview-v7:$appCompatVersion"
    compile "com.android.support:recyclerview-v7:$appCompatVersion"
    compile "com.android.support:customtabs:$appCompatVersion"
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.android.support:multidex:1.0.1'

    compile('com.twitter.sdk.android:tweet-ui:2.3.1@aar') {
        transitive = true;
    }
    compile('com.twitter.sdk.android:twitter-core:2.3.0@aar') {
        transitive = true;
    }

    compile 'com.squareup.okhttp3:okhttp:3.4.2'
    compile 'com.squareup.picasso:picasso:2.5.2'

    compile 'com.appboy:android-sdk-ui:1.19.0'

    // Facebook
    compile 'com.facebook.stetho:stetho:1.3.0'
    compile 'com.facebook.android:audience-network-sdk:4.26.0'
    compile 'com.facebook.android:facebook-android-sdk:4.27.0'

    // Inneractive SDK
    compile(name: 'ia-mraid-kit-release-7.0.5', ext: 'aar')
    compile(name: 'ia-native-kit-release-7.0.5', ext: 'aar')
    compile(name: 'ia-sdk-core-full-release-7.0.5', ext: 'aar')
    compile(name: 'ia-video-kit-release-7.0.5', ext: 'aar')


    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.2@aar') {
        transitive = true;
    }

    compile 'com.jakewharton:butterknife:7.0.1'

    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.outbrain.obsdk:obsdk:2.1.1'
    compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.3'
    compile files('libs/bluekai.jar')

    // Reactive
    compile 'io.reactivex:rxjava:1.3.0'
    compile 'io.reactivex:rxandroid:1.2.1'

    // ExoPlayer
    compile 'com.google.android.exoplayer:exoplayer:r2.4.0'

    // AdobePass
    compile files('libs/novacorps-adobepass-client-1.1.0.jar')
    compile files('libs/nebula-config-1.3.0.jar')

    // Needed in libs directory to avoid missing MVPD model compile error
    compile files('libs/android_accessenabler-1.9.1.jar')

    // Android Spin Kit UI
    compile 'com.github.ybq:Android-SpinKit:1.1.0'

    // Teads SDK
    compile ('tv.teads.sdk:androidsdk:2.4.14:fullRelease@aar') {
        transitive = true;
    }

    // Material Ripple Layout
    compile 'com.balysv:material-ripple:1.0.2'

    compile 'org.aspectj:aspectjrt:1.8.1'

    // Moshi - JSON Object Mapping
    compile 'com.squareup.moshi:moshi:1.5.0'

    // GIF Image Library - For Animations
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
}

android {
    compileSdkVersion project.compile_sdk_version.toInteger()
    buildToolsVersion project.build_tools_version
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId {application_id}
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        versionCode 31500100
        versionName {version_name}
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        minSdkVersion 19

        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
    }
    signingConfigs {
        release {
            keyAlias {key_alias}
            keyPassword {key_password}
            storeFile file({file_name})
            storePassword {store_password}
        }
    }

buildTypes {
        debug {
            minifyEnabled false
            applicationIdSuffix '.debug'
            versionNameSuffix '-DEBUG'
            debuggable true

            buildConfigField "boolean", "DEBUG_FORCE_UNICORN_OFF", "false"
            buildConfigField "boolean", "DEBUG_STETHO", "true"

            // These are the values for the authorities and account types.
            resValue "string", "account_type", "{application_id}.debug.accounttype"
            resValue "string", "authority", "{application_id}.debug"

            resValue "string", "about_version_build", defaultConfig.versionName
            resValue "string", "about_version_suffix", "debug"
            resValue "string", "outbrain_test_mode", "true"
            resValue "bool", "enable_view_server", "true"
            resValue "bool", "hockey_app_auto_upload", "false"

            resValue "string", "base_feed_url", {base_feed_url}
            resValue "string", "path_config", "xmldata/configuration-androidtest"

            resValue "string", "google_now_check_credentials_url", "{google_check_credentials_url}"
            resValue "string", "google_now_add_credentials_url", "{google_add_credentials_url}"
            resValue "string", "google_now_add_activity_url", "{google_add_activity_url}"

            resValue "string", "com_appboy_push_gcm_sender_id", "{sender_id}"
            resValue "string", "com_appboy_api_key", "{api_key}"
        }
        release {
            ext.enableCrashlytics = true
            minifyEnabled false
            debuggable false
            signingConfig signingConfigs.release

            buildConfigField "boolean", "DEBUG_FORCE_UNICORN_OFF", "false"
            buildConfigField "boolean", "DEBUG_STETHO", "false"

            // Reference them again so they get overwritten by the flavor.
            resValue "string", "account_type", "{application_id}.accounttype"
            resValue "string", "authority", "{application_id}"

            resValue "string", "about_version_build", defaultConfig.versionName
            resValue "string", "about_version_suffix", "release"
            resValue "string", "outbrain_test_mode", "false"
            resValue "bool", "enable_view_server", "false"
            resValue "bool", "hockey_app_auto_upload", "true"

            resValue "string", "base_feed_url", "{base_feed_url}"
            resValue "string", "path_config", "xmldata/configuration-androidv4"
            resValue "string", "google_now_check_credentials_url", "{google_check_credentials_url}"
            resValue "string", "google_now_add_credentials_url", "{google_add_credentials_url}"
            resValue "string", "google_now_add_activity_url", "{google_add_activity_url}"

            resValue "string", "com_appboy_push_gcm_sender_id", "{sender_id}"
            resValue "string", "com_appboy_api_key", "{api_key}"
        }
        livesim {
            ext.enableCrashlytics = true
            versionNameSuffix '-LIVE-SIM'
            minifyEnabled false
            debuggable false
            signingConfig signingConfigs.release

            buildConfigField "boolean", "DEBUG_FORCE_UNICORN_OFF", "false"
            buildConfigField "boolean", "DEBUG_STETHO", "false"

            // Reference them again so they get overwritten by the flavor.
            resValue "string", "account_type", "{application_id}.accounttype"
            resValue "string", "authority", "{application_id}"

            resValue "string", "about_version_build", defaultConfig.versionName
            resValue "string", "about_version_suffix", "release"
            resValue "string", "outbrain_test_mode", "false"
            resValue "bool", "enable_view_server", "false"
            resValue "bool", "hockey_app_auto_upload", "true"

            resValue "string", "base_feed_url", "{base_feed_url}"
            resValue "string", "path_config", "xmldata/configuration-androidv4"
            resValue "string", "google_now_check_credentials_url", "{google_check_credentials_url}"
            resValue "string", "google_now_add_credentials_url", "{google_add_credentials_url}"
            resValue "string", "google_now_add_activity_url", "{google_add_activity_url}"

            resValue "string", "com_appboy_push_gcm_sender_id", "{sender_id}"
            resValue "string", "com_appboy_api_key", "{api_key}"

            // Fallback for sub projects
            matchingFallbacks = ['release']
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src/main']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
        livesim.setRoot('build-types/livesim')
    }
    dexOptions {
        jumboMode true
        preDexLibraries = false
        javaMaxHeapSize "6g"
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        def buildType = variant.variantData.variantConfiguration.buildType.name
        outputFileName = "{Application_Name}-" + (buildType == "release" || buildType == "livesim" ? "release-" : "") + "${variant.versionName}.apk"
    }
}

dependencies {
    compile 'com.android.support.constraint:constraint-layout:+'
}

1 个答案:

答案 0 :(得分:2)

我找到了问题的答案但是如果有人还在寻找答案,我会在这里发布我的解决方案:

事实证明,问题是在启用了Advanced Profiling字段的情况下在仿真器/物理设备上安装调试版本。这是Android Studio 3.0中启用的一项功能,允许开发人员从Android Profiler的输出中获取更精确和详细的信息。

对要求的描述有点误导imho。它标识了API版本小于 ver所需的内容。 26但事实并非如此(至少对我来说并非如此)。它似乎仅在API版本大于 ver时成功构建。 26如果您选择启用它。它可能与更新的Multi-Dex支持库有关,它在Advanced Profiler需要它时还没有刷新所有方法,但似乎没有任何关于最新情况的详细信息。

如果您在低于ver的设备上运行构建。 26(即Android O),尝试禁用运行配置中的字段(它位于“编辑运行配置”窗口中的“性能分析”选项卡下)。

Advanced Profiling Field in Run Configurations

希望有所帮助!