Google App Engine:DuplicateFileException

时间:2017-03-28 10:21:03

标签: 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
    }
}

1 个答案:

答案 0 :(得分:0)

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

# So all IP only paths continue to work
<VirtualHost *:80>
        DocumentRoot /var/www/html/
        ServerName 10.10.10.10          # Server's IP
        <Directory /var/www/html/>
                Options FollowSymLinks
                AllowOverride All
        </Directory>
</VirtualHost>

# So site2.dev points to its folder
<VirtualHost *:80>
        DocumentRoot /var/www/html/site2
        ServerName site2.dev
        <Directory /var/www/html/site2>
                Options FollowSymLinks
                AllowOverride All
        </Directory>
</VirtualHost>