有时使用dexdebug构建失败了吗?

时间:2015-12-23 12:27:32

标签: android gradle build dex

我正在使用Gradle构建我的应用程序并添加了几个库,如Play Services和ChartBoost。我还在我的android multiDexEnabled true中设置了build.gradle。我正在使用Android Studio IDE和LibGDX框架。

然而,有时它会成功建立,有时它会因dexDebug错误而失败。要清楚,我不会改变任何我只是建立几次的东西,然后它突然建立成功。可能导致这种情况的原因是什么?

这几天困扰着我。我试图修复此错误,但我没想到这种不一致的行为。所以我不停地改变一些东西,做一个单独的构建,当我终于开始工作时,我继续编写代码,当我想构建并再次出现dexDebug错误时,我开始重新开始,可能会破坏完全应用程序,直到我打破它,并有幸第一次正确构建。有时需要3或4次尝试才能成功构建。

项目build.gradle

buildscript {
    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = 'bouncerandbreak'
        gdxVersion = '1.6.4'
        roboVMVersion = '1.5.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.4.0'
        aiVersion = '1.5.0'
    }

    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile project(":BaseGameUtils")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        //compile 'com.google.android.gms:play-services:8.1.0'
        compile 'com.google.android.gms:play-services-ads:8.1.0'
        //compile files('libs/AdMobAppTracker.jar')
        //compile files('libs/AppTracker.jar')
        compile files('libs/chartboost.jar')
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
    }
}

tasks.eclipse.doLast {
    delete ".project"
}

Android模块build.gradle

android {
    signingConfigs {
        debug {
            storeFile file('path')
            keyAlias 'DebugKeyStore'
            keyPassword 'keypass'
            storePassword 'storepass'
        }
        release {
            storeFile file(path)
            keyAlias 'ReleaseKeyStore'
            keyPassword 'keypass'
            storePassword 'storepass'
        }
    }
    buildToolsVersion "23.0.0"
    compileSdkVersion 23

    defaultConfig {
        // Enabling multidex support.
        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')
    }
}
// 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', 'com.buckriderstudio.bounceandbreak.android/com.buckriderstudio.bounceandbreak.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")
                        }
                    }
                }
            }
        }
    }
}
dependencies {
}

1 个答案:

答案 0 :(得分:0)

该问题您的一些jar文件无法编译。您应该转到项目的build.gradle(app level)文件,并检查库依赖项。如果您使用的是jar文件,可以尝试删除所有文件并逐个添加并检查。如果你这样做,你可以确定哪一个导致错误。

在我的项目中,我也是这样做的,我尝试删除所有jar文件,并将这些文件替换为mavin存储库中的依赖项。并确保在“build.gradel”文件中检查它们是否没有版本冲突。