的IntelliJ +摇篮+ Android系统。在Debug和Release buildtypes之间切换

时间:2015-01-02 08:58:49

标签: android intellij-idea android-gradle

我想通过在IntelliStudio 14中切换两个构建类型来在真实设备中运行或调试,就像在VisualStudio中一样。

Someone表示要执行installRelease,但只有installDebug出现在我的gradle android任务中,我无法运行gradlew installRelease因为任务不存在。

错误消息如下所示。非常期待。 Task 'installRelease' not found in root project 'u2020'. Some candidates are: 'uninstallRelease'.

build.gradle如下所示。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.14.2'
    }
}

// Manifest version information!
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

apply plugin: 'com.android.application'

repositories {
    jcenter()
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'

compile 'com.squareup.dagger:dagger:1.2.2'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'

compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.8.0'
debugCompile 'com.squareup.retrofit:retrofit-mock:1.8.0'

compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.jakewharton.timber:timber:2.5.0'
debugCompile 'com.jakewharton.madge:madge:1.1.1'
debugCompile 'com.jakewharton.scalpel:scalpel:1.1.1'

compile 'io.reactivex:rxjava:1.0.3'
compile 'io.reactivex:rxandroid:0.23.0'

compile 'com.etsy.android.grid:library:1.0.3'
}

def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))

def isTravis = "true".equals(System.getenv("TRAVIS"))
def preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    dexOptions {
        // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
        preDexLibraries = preDexEnabled && !isTravis
    }

    defaultConfig {
        applicationId "net.bapul.demo.u2020"
        minSdkVersion 15
        targetSdkVersion 21

        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"

        buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
        buildConfigField "String", "BUILD_TIME", "\"${buildTime}\""
    }
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

        debug {
            applicationIdSuffix '.dev'
            versionNameSuffix '-dev'
        }
    }

    lintOptions {
        abortOnError false
    }
}

原始代码来自JakeWharton的演示应用程序,gradle文件可以在这里找到:https://github.com/JakeWharton/u2020/blob/master/build.gradle

我该怎么办?

1 个答案:

答案 0 :(得分:0)

您需要在app模块的build.gradle中添加这些行

buildTypes {       
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

如果您希望为应用程序提供发布密钥库,请在下面的代码中签名。

signingConfigs {
    release {
        storeFile file("../../alphakeystore.jks")
        storePassword "123456"
        keyAlias "MyApp"
        keyPassword "123456"
    }
}