【问题标题】:Gradle build task installRelease missing in Android projectAndroid项目中缺少Gradle构建任务installRelease
【发布时间】:2016-02-27 03:19:58
【问题描述】:

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

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"/>

我希望 Gradle 生成任务 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
------------------
...

出了什么问题?为什么任务installRelease 不可用?

【问题讨论】:

  • 不要使用类路径 'com.android.tools.build:gradle:+'。 gradle 插件发生了变化,这样你的构建脚本就会出现问题。
  • 不是+总是使用最新的gradle插件吗?这就是我使用它的原因。听起来我错了。 (看起来 com.android.tools.build:gradle:1.5.0 现在是“正确的”。)
  • 在依赖项中使用+是否可取?
  • 使用最新版本并不意味着使用最好的版本。一个好的做法是有一个可复制的构建。如果您使用“+”,您将来将无法复制相同的构建。依赖项也一样。

标签: android gradle android-gradle-plugin build.gradle


【解决方案1】:

首先要发布,您需要在根项目中创建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
            }
        }

那么installRelease 也将在gradle 任务中可用

希望这对您有所帮助。

【讨论】:

  • 谢谢!这样可行。答案可以稍微简化:您可以从buildType.debug 中删除signingConfig signingConfigs.debug。 (将 signingConfigs.debug 重命名为 signingConfigs.release 可能也有意义。)
  • @user2768 很高兴为您提供帮助。我只创建了调试签名配置,所以我使用相同的发布也只是为了向你展示。
  • 使用默认的signingConfigs.debug不是更好吗,因为这将包含调试签名密钥?
【解决方案2】:

对于不打算发布应用程序的边缘情况(例如测试混淆的 apk),您可以跳过使用生产密钥进行签名并做更简单的事情:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-11
    • 2021-08-01
    相关资源
    最近更新 更多