Android项目中缺少Gradle构建任务installRelease

use*_*768 6 android gradle build.gradle android-gradle-plugin

Gradle似乎在我正在进行的项目中丢失了构建类型.我可以重新创建一个小问题,如下所示.我有以下文件:

build.gradle
local.properties
src/main/AndroidManifest.xml
Run Code Online (Sandbox Code Playgroud)

的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 {

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

local.properties:

sdk.dir=/path/to/android-sdk-linux
Run Code Online (Sandbox Code Playgroud)

的src/main/AndroidManifest.xml中:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example"/>
Run Code Online (Sandbox Code Playgroud)

我希望摇篮生成任务installDebuginstallRelease,因为我定义debugrelease作为buildTypes.但事实并非如此.该命令gradle tasks产生:

: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
------------------
...
Run Code Online (Sandbox Code Playgroud)

出了什么问题?为什么没有任务installRelease

Ami*_*pta 14

首先,您需要keystore在根项目中创建.您需要在build.gradle中提供这些详细信息.

如果需要,您可以创建两个signingConfigs调试和释放.

最后buildTypes链接到那个.

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
            }
        }
Run Code Online (Sandbox Code Playgroud)

然后installRelease也将在gradle任务中提供

希望这对你有所帮助.