【问题标题】:Unable to merge dex error in Android Studio 3.0.1 after adding google cloud storage dependencyAndroid Studio 3.0.1 添加谷歌云存储依赖后无法合并dex错误
【发布时间】:2018-08-29 14:07:18
【问题描述】:

我正在尝试将数据发送到 android 应用程序中的谷歌云存储桶,因此我正在尝试导入 com.google.cloud:google-cloud-storage:1.22.0 库。然而这会导致错误

Error:Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我尝试了来自this SO question 的多个答案,但都出现了相同的错误。尝试过的修复包括:

  • multiDexEnabled true 添加到 defaultConfig 并在依赖项中包含 android.support:multidex
  • 将 transitive=true 添加到导入 [implementation('com.google.cloud:google-cloud-storage:1.22.0'){transitive = true}]
  • 尝试使用 ./gradlew dependencies 检查传递依赖,但收到错误 Could not find com.android.tools.build:gradle:3.0.1

我使用的 build.gradle 最初来自 tensorflow example app

project.buildDir = 'gradleBuild' 
getProject().setBuildDir('gradleBuild')

buildscript {
    repositories {
        jcenter()
}
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'org.apache.httpcomponents:httpclient:4.5.4'
        }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

// set to 'bazel', 'cmake', 'makefile', 'none'
def nativeBuildSystem = 'none'

// Controls output directory in APK and CPU type for Bazel builds.
// NOTE: Does not affect the Makefile build target API (yet), which currently
// assumes armeabi-v7a. If building with make, changing this will require
// editing the Makefile as well.
// The CMake build has only been tested with armeabi-v7a; others may not work.
def cpuType = 'armeabi-v7a'

// Output directory in the local directory for packaging into the APK.
def nativeOutDir = 'libs/' + cpuType

// Default to building with Bazel and override with make if requested.
def nativeBuildRule = 'buildNativeBazel'
def demoLibPath = '../../../bazel-bin/tensorflow/examples/android/libtensorflow_demo.so'
def inferenceLibPath = '../../../bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so'



// If building with Bazel, this is the location of the bazel binary.
// NOTE: Bazel does not yet support building for Android on Windows,
// so in this case the Makefile build must be used as described above.
def bazelLocation = '/usr/local/bin/bazel'

// import DownloadModels task
project.ext.ASSET_DIR = projectDir.toString() + '/assets'
project.ext.TMP_DIR = project.buildDir.toString() + '/downloads'

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '26.0.2'

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            // Android demo app sources.
            java {
                srcDir 'src'
            }

            manifest.srcFile 'AndroidManifest.xml'
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = [project.ext.ASSET_DIR]
            jniLibs.srcDirs = ['libs']
        }

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

task buildNativeBazel(type: Exec) {
    workingDir '../../..'
    commandLine bazelLocation, 'build', '-c', 'opt', 'tensorflow/examples/android:tensorflow_native_libs', '--crosstool_top=//external:android/crosstool', '--cpu=' + cpuType, '--host_crosstool_top=@bazel_tools//tools/cpp:toolchain'
}

task buildNativeMake(type: Exec) {
    environment "NDK_ROOT", android.ndkDirectory
    // Tip: install ccache and uncomment the following to speed up
    // builds significantly.
    // environment "CC_PREFIX", 'ccache'
    workingDir '../../..'
    commandLine 'tensorflow/contrib/makefile/build_all_android.sh', '-s', 'tensorflow/contrib/makefile/sub_makefiles/android/Makefile.in',  \
         '-t', 'libtensorflow_inference.so libtensorflow_demo.so all'  \
         , '-a', cpuType //, '-T'  // Uncomment to skip protobuf and speed up subsequent builds.
}


task copyNativeLibs(type: Copy) {
    from demoLibPath
    from inferenceLibPath
    into nativeOutDir
    duplicatesStrategy = 'include'
    dependsOn nativeBuildRule
    fileMode 0644
}

tasks.whenTaskAdded { task ->
}

// Download default models; if you wish to use your own models then
// place them in the "assets" directory and comment out this line.
//apply from: "download-models.gradle"
//
// compile 'com.google.apis:google-api-services-appengine:v1-rev52-1.23.0' exclude module: 'httpclient'


dependencies {
    if (nativeBuildSystem == 'cmake' || nativeBuildSystem == 'none') {
        compile 'org.tensorflow:tensorflow-android:+'
    }
    implementation 'com.google.code.gson:gson:2.8.2'
    compileOnly 'com.google.auto.value:auto-value:1.5.1'
    annotationProcessor 'com.google.auto.value:auto-value:1.5.1'
    implementation 'com.google.cloud:google-cloud-storage:1.22.0' exclude module: 'httpclient'
    implementation 'com.google.apis:google-api-services-tasks:v1-rev48-1.23.0' exclude module: 'httpclient'
    implementation 'com.google.apis:google-api-services-discovery:v1-rev62-1.23.0' exclude module: 'httpclient'
    implementation 'com.google.protobuf:protobuf-java:3.5.1'
    implementation 'com.android.support:multidex:1.0.2'
    implementation files('libs/TarsosDSP-Android-2.4.jar')
}

有谁知道是什么导致了这个错误,或者我怎么能知道我为什么会得到它? (可能是我需要让./gradlew dependencies 运行,我并没有放弃我只是暂时离开它以避免陷入太多调试兔子洞)。

【问题讨论】:

    标签: android android-studio dependencies google-cloud-platform google-cloud-storage


    【解决方案1】:

    查看我在the Cloud Storage API docs 上忽略的友好蓝色注释

    (21/03/18 截屏)

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多