Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build task installRelease missing in Android project

Gradle seems to have lost a build type in a project I am working on. I can recreate a minimal problem as follows. I have the following files:

build.gradle
local.properties
src/main/AndroidManifest.xml

build.gradle:

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

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 1
        targetSdkVersion 23
    }

    buildTypes {
        debug {

        }
        release {

        }
    }
}

local.properties:

sdk.dir=/path/to/android-sdk-linux

src/main/AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example"/>

I would expect Gradle to generate tasks installDebug and installRelease, since I define debug and release as buildTypes. However, this isn't the case. The command gradle tasks produces:

:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

...

Install tasks
-------------
installDebug - Installs the Debug build.
installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build.
uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
uninstallRelease - Uninstalls the Release build.

Verification tasks
------------------
...

What is going wrong? Why isn't task installRelease available?

like image 636
user2768 Avatar asked Nov 24 '15 15:11

user2768


People also ask

Where is build Gradle file in Android Studio?

The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.

What is build task in Gradle?

The work that Gradle can do on a project is defined by one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.

Does Gradle build run all tasks?

The build scripts of all projects which are part of the build are executed. Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory.


1 Answers

For release first you need to create keystore in root project. And you need to provide those details in build.gradle.

You can create two signingConfigs debug & release both if you want.

At last in buildTypes link to that.

android {
        signingConfigs {
        debug {
          keyAlias 'alias'
          keyPassword 'password'
          storeFile file('../xyz.jks')
          storePassword 'password'
        }
      }
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        defaultConfig {
            minSdkVersion 1
            targetSdkVersion 23
        }

        buildTypes {
            debug {
              signingConfig signingConfigs.debug
            }
            release {
             signingConfig signingConfigs.debug
            }
        }

Then installRelease will be also available in gradle Task

Hope this be helpful for you.

like image 88
Amit Gupta Avatar answered Oct 17 '22 19:10

Amit Gupta