Android gradle build script returns error 137 in p

2019-01-26 21:01发布

问题:

I am trying to build an Android project on our Debian build server with gradlew.

Each time I run it the build fails on the preDexDebug step with error 137 and the following error. I tried the stacktrace but this didn't give me any more information, except that it is an unhandled exception. In the console I can see the preDexDebug build step fail at 39%.

:Carpool:preDexDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Carpool:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
        /opt/android-sdk-linux/build-tools/19.0.3/dx --dex --output /var/lib/jenkins/jobs/Project/workspace/com.app.space/Carpool/build/pre-dexed/debug/classes-c1baba1a2bb3528538a151852945d1f7047c7393.jar /var/lib/jenkins/jobs/Project/workspace/com.app.space/Carpool/build/exploded-aar/com.google.android.gms/play-services/4.0.30/classes.jar
  Error Code:
        137

The build script:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.android.support:gridlayout-v7:19.1.0'
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services:4.0.30'
}

Any ideas on the cause of this problem, workarounds or additional checks I could do?

回答1:

The problem was due to memory problems on the build server. Switching to a build server with more memory has fixed the problem.



回答2:

Yes, I have met this issue. I found out the problem is that dx.bat could not run because of config memory error. Change "set defaultXmx=-Xmx1024m" to "set defaultXmx=-Xmx512m" and run again. Ref link I found it: https://code.google.com/p/vs-android/issues/detail?id=15. Hope this help.