问题
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