android - Google App Engine : DuplicateFileException

标签 android google-app-engine gradle compiler-errors

使用我的后端已经一年没有问题了。今天,我在一台新计算机上进行了部署,突然之间我收到了duplicatefileexception

完整错误:

Error:Execution failed for task ':android:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK com/google/appengine/repackaged/org/apache/commons/codec/language/bm/sep_approx_spanish.txt
    File1: C:\Users\\.gradle\caches\modules-2\files-2.1\com.google.appengine\appengine-api-1.0-sdk\1.9.42\c972bc847992e5512eb4338a38cc2392e56760f6\appengine-api-1.0-sdk-1.9.42.jar
    File2: C:\Users\\.gradle\caches\modules-2\files-2.1\com.google.appengine\appengine-endpoints\1.9.42\5c25efed254f8f9846d04b156e68283055efd320\appengine-endpoints-1.9.42.jar

在Stack上有一个答案,说您要做的就是将它添加到gradle中:
dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
    compile 'com.google.appengine:appengine-endpoints:1.9.42'
    compile ('com.google.appengine:appengine-endpoints-deps:1.9.42'){
        exclude "sep_approx_spanish.txt" //added
    }
    compile 'javax.servlet:servlet-api:2.5'
    compile files('src/main/webapp/WEB-INF/lib/objectify-5.1.12.jar')
    compile files('src/main/webapp/WEB-INF/lib/guava-19.0.jar')
    compile files('src/main/webapp/WEB-INF/lib/gcm-server-1.0.2.jar')
}

但这给了我另一个错误:
Error:Could not find method exclude() for arguments [sep_approx_spanish.txt] on DefaultExternalModuleDependency{group='com.google.appengine', name='appengine-endpoints-deps', version='1.9.42', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.

我已经查看了我的客户端gradle和服务器,找不到任何地方要两次调用同一个库或类似的库。不知道发生了什么事。

在下面添加Android客户端和后端Gradle:

Android:
android {
    buildToolsVersion '25.0.0'
    compileSdkVersion 23
    defaultConfig {
        multiDexEnabled = true
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        instrumentTest.setRoot('tests')
    }
}

dependencies {
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    compile 'com.google.code.findbugs:jsr305:2.0.1'
    compile project(path: ':backend', configuration: 'android-endpoints')
}

// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
    file("libs/armeabi/").mkdirs();
    file("libs/armeabi-v7a/").mkdirs();
    file("libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
        if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if (outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}
task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', '.android/AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
    }

    classpath {
        plusConfigurations += [project.configurations.compile]
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}
// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");
        scopes = [COMPILE: [plus: [project.configurations.compile]]]

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value: "true")
                        }
                    }
                }
            }
        }
    }
}

后端:
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
    }
}

repositories {
    jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
    compile 'com.google.appengine:appengine-endpoints:1.9.42'
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.42'
    compile 'javax.servlet:servlet-api:2.5'
    compile files('src/main/webapp/WEB-INF/lib/objectify-5.1.12.jar')
    compile files('src/main/webapp/WEB-INF/lib/guava-19.0.jar')
    compile files('src/main/webapp/WEB-INF/lib/gcm-server-1.0.2.jar')
}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
}

最佳答案

尝试在您的“应用” build.gradle 文件中添加以下内容:

android {
    ...
    packagingOptions {
        ...
        exclude 'com/google/appengine/repackaged/org/apache/commons/codec/language/bm/sep_approx_spanish.txt'
    }
}

关于android - Google App Engine : DuplicateFileException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43066942/

相关文章:

python - 从 GQL 查询返回的实体数

java - 超过 3 列的 Google App-Engine Java 过滤

android - 如何在我的 gradle 插件中动态地将参数传递给 kapt 编译器?

android - NDK分辨率结果:项目设置:Gradle模型版本= 5.4.1,NDK版本为UNKNOWN错误

android - Gradle DSL 方法未找到 : 'compile()' - Dependencies are in Module level build. gradle 已经

java - ListView 内的复选框状态在 Android 中不能按相反顺序工作

Android 到 PC 使用普通 WiFi 网络共享文件

Android Volley 无法为使用 OkHttp3 作为其传输的特定请求禁用缓存

google-app-engine - GAE Go - 如何将私有(private)变量放入数据存储区?

android - 如何获取在 `BroadcastReceiver` 中定义的 `AndroidManifest.xml` 实例