Gradle build task installRelease missing in Android project

眉间皱痕 提交于 2019-12-10 13:44:09

问题


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?


回答1:


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.




回答2:


For an edge case when you are not going to publish the app(testing of an obfuscated apk for example) you may skip signing with production key and do even simpler:

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


来源:https://stackoverflow.com/questions/33897802/gradle-build-task-installrelease-missing-in-android-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!