【问题标题】:Android Studio 0.8.6 change default build variantAndroid Studio 0.8.6 更改默认构建变体
【发布时间】:2014-10-24 11:28:41
【问题描述】:

我最近将 Android Studio 从 0.6 更新到 0.8.6,似乎指定默认“运行”配置的功能已被删除(或者移动到我需要帮助查找的位置)。我能够在调试或发布模式下生成签名的 APK(生成向导已更改为允许我此时选择构建变体)但似乎无法找到如何为一般选择构建变体采用。换句话说,当我单击“运行”时,当我需要运行 assembleDebug 时,gradle 会执行 assembleRelease。知道如何改变这个吗?

编辑:当我选择“调试”而不是“运行”时,gradle 仍然选择运行assembleRelease,所以我收到此错误

Cannot debug application com.caseybrooks.scripturememory on device lge-vs985_4g-VS9854Gc824b3f1.
This application does not have the debuggable attribute enabled in its manifest.
If you have manually set it in the manifest, then remove it and let the IDE automatically assign it.
If you are using Gradle, make sure that your current variant is debuggable.

但是,如果我将 debuggable="true" 属性添加到我的清单中,则构建会失败。我的 build.gradle 是否正确?

apply plugin: 'android'

android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19
}
signingConfigs {
    release {
        storeFile file('C:/Users/Casey/Documents/android/scripturememory/scripturememory_keystore')
        keyAlias 'scripturememory_keystore'
        storePassword '***********'
        keyPassword '**********'
    }
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        signingConfig signingConfigs.release
    }
}
productFlavors {
}
sourceSets {
    main {
        java.srcDirs = ['src/main/java']
    }
}
}

dependencies {
compile project(':library')
compile project(':AndroidBibleTools')
compile 'com.android.support:appcompat-v7:19.+'
}

【问题讨论】:

  • 您要找的是build options menu吗?
  • 不,我没有在该菜单中看到任何更改构建变体的选项。

标签: android gradle android-studio


【解决方案1】:

“视图”菜单 >“工具窗口”>“构建变体”视图可让您选择默认为项目中的模块构建的风味/构建类型。

【讨论】:

    【解决方案2】:

    尝试将其用于您的 gradle 构建文件。我通常在 gradle 文件中设置 debuggable 标志,而不是清单。

     buildscript {
            repositories {
                mavenCentral()
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:0.12.2'
            }
        }
    
        apply plugin: 'com.android.application'
    
        repositories {
            mavenCentral()
        }
    
        android {
        compileSdkVersion 19
        buildToolsVersion '19.1.0'
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 19
        }   
         packagingOptions {
                exclude 'META-INF/DEPENDENCIES'
                exclude 'META-INF/LICENSE'
                exclude 'META-INF/NOTICE'
                exclude 'META-INF/ASL2.0'
            }
        signingConfigs {
            release {
                storeFile file('C:/Users/Casey/Documents/android/scripturememory/scripturememory_keystore')
                keyAlias 'scripturememory_keystore'
                storePassword '***********'
                keyPassword '**********'
            }
        }
            buildTypes {
                debug {
                    applicationIdSuffix '.dev'
                    debuggable true
                    jniDebugBuild true
                    runProguard false
                }
                beta {
                    applicationIdSuffix '.beta'
                    debuggable true
                    jniDebugBuild true
                    runProguard false
                }
                release {
                    debuggable false
                    jniDebugBuild false
                    runProguard false
                    signingConfig signingConfigs.release
                }
            }
        sourceSets {
            main {
                java.srcDirs = ['src/main/java']
            }
        }
        }
    
        dependencies {
        compile project(':library')
        compile project(':AndroidBibleTools')
        compile 'com.android.support:appcompat-v7:19.+'
        }
    

    【讨论】:

    • 这对我很有用。我有另一种名为“dev”的产品风味(出于各种其他原因),并且在风味中设置调试值效果很好。谢谢!
    • 谢谢。这就是我搜索的内容。如果你想调试一个发布版本,你应该在'release'分支中写'debuggable true',直到你真正制作一个签名的APK,你应该避免调试信息。
    猜你喜欢
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    相关资源
    最近更新 更多