Android Studio 0.8.6 change default build variant

2019-06-21 19:21发布

问题:

I recently updated Android Studio from 0.6 to 0.8.6, and it seems the ability to specify the default "run" configuration has been removed (or else moved to a location that I need help finding). I am able to to generate a signed APK in either debug or release mode (the generate wizard has been changed to allow me to select the build variant at this point) but can't seem to find out how to select a build variant for general use. In other words, when I click "run" gradle executes assembleRelease when I need to to run assembleDebug. Any idea of how to change this?

EDIT: When I select "debug" instead of "run" gradle still chooses to run assembleRelease, so I get this error

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.

Yet if I add the debuggable="true" attribute to my manifest, the build fails. Is my build.gradle correct?

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.+'
}

回答1:

The View menu > Tool Windows > Build Variants view lets you choose which flavor/build type is built by default for the modules in your project.



回答2:

Try using this for your gradle build file. I typically set the debuggable flag in the gradle file, not the manifest.

 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.+'
    }