Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

android - command git finished with non-zero exit value 128

When I migrate Android project from Eclipse to Android Studio, use travis ci to build the project, it has the following errors.

FAILURE: Build failed with an exception.
* Where:
Build file '/home/travis/build/Logan676/seadroid/app/build.gradle' line: 20
* What went wrong:
A problem occurred evaluating project ':app'.
Process 'command 'git'' finished with non-zero exit value 128

the build.gradle file is

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.13.0'
        }
    }
    apply plugin: 'com.android.application'

    repositories {
        jcenter()
    }

    /*
     * Gets the version name from the latest Git tag
     */
    def getVersionName = { ->
        def stdout = new ByteArrayOutputStream()
        exec {
            // LINE 20 IS HERER!!!!!!!!!!!!!
            commandLine 'git', 'describe', '--tags' 
            standardOutput = stdout
        }
        return stdout.toString().trim()
    }
    def getVersionCode = { ->
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine 'git', 'rev-list', '--count', "HEAD"
            standardOutput = stdout
        }
        return Integer.valueOf(stdout.toString().trim())
    }


    dependencies {
        compile 'com.android.support:support-v4:21.0.+'
        compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
        compile 'com.inkapplications.viewpageindicator:library:2.4.3'
        compile 'com.github.kevinsawicki:http-request:5.6'
        compile 'commons-io:commons-io:2.4'
        compile 'com.google.guava:guava:18.0'
        compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
        compile project(':libraries:NewQuickAction')
        compile project(':libraries:MarkdownView')
        compile project(':libraries:PullToRefresh')
    }

    android {
        compileSdkVersion rootProject.ext.compileSdkVersion
        buildToolsVersion rootProject.ext.buildToolsVersion

        defaultConfig {
            minSdkVersion rootProject.ext.minSdkVersion
            targetSdkVersion rootProject.ext.targetSdkVersion
            versionCode getVersionCode()
            versionName getVersionName()
        }

        lintOptions {
            abortOnError false
        }

        signingConfigs {
            release {
                // Signing code for manual signing
                //storeFile file(System.console().readLine("
$ Enter keystore path: "))
                //storePassword System.console().readPassword("
$ Enter keystore      password: ").toString()
                //keyAlias System.console().readLine("
$ Enter key alias: ")
                //keyPassword System.console().readPassword("
$ Enter key password:    ").toString()
            }
        }

        buildTypes {
            release {
                //signingConfig signingConfigs.release
                runProguard true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            }
        }
    }

I guess it caused by not installed git error. But I don`t know how to fix it. Maybe it needs some script to automatically install git. So anyone can help me modify the Gradle file as showed above.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I catch revision in revision property from git command output in the code (code universal for unix /first exec/ and windows /second exec/, command git must work from console)

def os = System.getProperty("os.name").toLowerCase()
def revision = new ByteArrayOutputStream()
if (!os.contains("windows")) {
    exec {
        executable "/bin/sh"
        args "-c", "echo -n `git rev-list HEAD | wc -l | sed 's/^[ ^t]*//'`"
        standardOutput = revision;
    }
} else {
    exec {
        executable "cmd"
        args "/c", "git rev-list HEAD | find /c /v """
        standardOutput = revision;
    }
    revision = revision as String
    revision = revision.trim()
};

You can change code for you needed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...