【问题标题】:IntelliJ+Gradle+Android. switch between Debug and Release buildtypesIntelliJ+Gradle+Android。在 Debug 和 Release 构建类型之间切换
【发布时间】:2015-01-02 23:35:24
【问题描述】:

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

Someone说要执行installRelease,但我的gradle android任务中只出现installDebug,我没有运行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

我该怎么办?

【问题讨论】:

    标签: android intellij-idea android-gradle-plugin


    【解决方案1】:

    你需要在 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"
        }
    }
    

    【讨论】:

    • 谢谢。我在 build.gradle 文件中添加了两个 buildType,但仍然无法在 IntelliJ 中切换它们。它只提供assembleRelease、assembleDebug来生成每个apk。我想直接部署和运行(+调试)。
    猜你喜欢
    • 2013-06-06
    • 1970-01-01
    • 2021-06-09
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多