com.android.builder.dexing.DexArchiveMergerException:无法合并dex

时间:2019-12-11 14:24:55

标签: android android-studio-3.0

在Android Studio 3.6中

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.3.50'

    repositories {
        maven { url 'https://maven.fabric.io/public' }
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'io.fabric.tools:gradle:1.25.4'
        classpath "com.jaredsburrows:gradle-license-plugin:0.8.41"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

在app / build.gradle中:

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        manifestPlaceholders = [
                fabricApiKey: keystoreProperties['FabricApiKey'] != null
                        ? keystoreProperties['FabricApiKey']
                        : ""
        ]
        multiDexKeepFile file('multidex-keep.txt')
    }

但是在构建时出现错误:

> Task :app:transformClassesWithMultidexlistForDebug

> Task :app:mergeDexDebug FAILED
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
    at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
    at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:720)

1 个答案:

答案 0 :(得分:1)

更改为

        foreach ( $customer_orders->orders as $customer_order ) {
            $order      = wc_get_order($customer_order); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
            $item_count = $order->get_item_count() - $order->get_item_count_refunded();

                // first get product id
            foreach($order->get_items() as $order_key => $order_value) {
              $product_id = $order_value->get_data()['product_id'];
            }
                // get image
                if (isset($product_id)) {   
                    $image = wp_get_attachment_image_src( get_post_thumbnail_id($product_id));
                }
            ?>
            <div class="product_list">
                <div class="product_item">
                    <div class="product_home">
                        <div class="text-center">
                            <a href="<?php echo esc_url($order->get_view_order_url()); ?>" title="<?php echo esc_html(_x('#', 'hash before order number', 'woocommerce') . $order->get_order_number()); ?>">

                              <?php if (isset($image)) { ?>
                                                        <img src="<?php echo $image[0] ?>" />
                                                    <?php } ?>

                            </a>
                        </div>
                        <div class="content_product_home">
                            <a href="<?php echo esc_url($order->get_view_order_url()); ?>" title="<?php echo esc_html(_x('#', 'hash before order number', 'woocommerce') . $order->get_order_number()); ?>">
                                <h4> Zamówienie
                                    <?php echo esc_html(_x('#', 'hash before order number', 'woocommerce') . $order->get_order_number()); ?>
                                </h4>
                            </a>

                            <p>
                                <?php echo $order->get_formatted_order_total() ?><span class="per_month">including tax</span></p>

                        </div>
                        <div class="text-center">
                            <a href="<?php echo esc_url($order->get_view_order_url()); ?>" class="btn btn-more" title="Details">Details</a>
                        </div>
                    </div>
                </div>
            </div>
        <?php } ?>