Can't get installRelease gradle task to show up in Android Studio

时间:2015-07-08 15:43:12

标签: android android-studio gradle

I have assembleRelease, which works, as well as assembleDebug and installDebug.

This is the chunk from my build.gradle, which I thought would get the task to show up, but the list still does not have it. Toggling the build variant does not have any effect on the gradle tasks that are appearing.

Any ideas?

Thank-you!

edit 1 - My top level build.gradle file ("Project : trunk") contains

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
dependencies {
}

My app-level build.bradle file is

import java.util.regex.Pattern
apply plugin: 'com.android.application'
android {

    compileSdkVersion 19
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "com.xyz"
        minSdkVersion 16
        targetSdkVersion 17
    }
    dependencies {
        compile "com.google.android.gms:play-services:3.1.+"
        compile "ch.acra:acra:4.5.0"
    }

    signingConfigs {
        release {
            storeFile file('redact')
            keyAlias 'asdf'
            storePassword System.getenv("ANDROIDKEYPW")
            keyPassword System.getenv("ANDROIDKEYPW")

        }
        debug {
            keyAlias 'asdf'
            storeFile file('redact')
            storePassword System.getenv("ANDROIDKEYPW")
            keyPassword System.getenv("ANDROIDKEYPW")
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            debuggable false
            signingConfig signingConfigs.release

            //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true

        }
    }
    productFlavors {
    }
}

task incrementVersionCode << {
    println(":incrementVersionCode - Incrementing Version Code...")
    def manifestFile = file("src/main/AndroidManifest.xml")
    def patternVersionCode = Pattern.compile("versionCode=\"(\\d+)\"")
    def manifestText = manifestFile.getText()
    def matcherVersionCode = patternVersionCode.matcher(manifestText)
    matcherVersionCode.find()
    def mVersionCode = Integer.parseInt(matcherVersionCode.group(1))
    def mNextVersionCode = mVersionCode + 1
    def manifestContent = matcherVersionCode.replaceAll("versionCode=\"" + mNextVersionCode + "\"")
    println(":incrementVersionCode - current versionCode=" + mVersionCode);
    println(":incrementVersionCode - next versionCode=" + mNextVersionCode);
    manifestFile.write(manifestContent)
}
task incrementVersionName << {
    println(":incrementVersionName - Incrementing Version Name...")
    def manifestFile = file("src/main/AndroidManifest.xml")
    def patternVersionNumber = Pattern.compile("versionName=\"(\\d+)\\.(\\d+)\\.(\\d+)\"")
    def manifestText = manifestFile.getText()
    def matcherVersionNumber = patternVersionNumber.matcher(manifestText)
    matcherVersionNumber.find()
    def majorVersion = Integer.parseInt(matcherVersionNumber.group(1))
    def minorVersion = Integer.parseInt(matcherVersionNumber.group(2))
    def pointVersion = Integer.parseInt(matcherVersionNumber.group(3))
    def mVersionName = majorVersion + "." + minorVersion + "." + pointVersion
    def mNextVersionName = majorVersion + "." + minorVersion + "." + (pointVersion + 1)
    def manifestContent = matcherVersionNumber.replaceAll("versionName=\"" + mNextVersionName + "\"")
    println(":incrementVersionName - current versionName=" + mVersionName);
    println(":incrementVersionName - new versionName=" + mNextVersionName);
    manifestFile.write(manifestContent)
}
task release << {
    println(":release - Build and Version Increment")
}
task debug << {
    println(":debug - Build")
}
incrementVersionName.mustRunAfter build
incrementVersionCode.mustRunAfter build
assembleRelease {}.dependsOn incrementVersionCode
assembleRelease {}.dependsOn incrementVersionName

dependencies {
}

1 个答案:

答案 0 :(得分:5)

Add signingConfig signingConfigs.release to your release build type:

buildTypes {
    release {
        minifyEnabled true
        debuggable false
        signingConfig signingConfigs.release
    }

    // other good stuff here
}

Your release closure inside of signingConfigs creates a named signing configuration. However, release as a name does not cause it to automatically get used by the release build type. You could have named the signing configuration gregRocks, then used signingConfig signingConfigs.gregRocks in the release build type, and gotten the same results.