【发布时间】: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 生成任务 installDebug 和 installRelease,因为我将 debug 和 release 定义为 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