Unable to switch to debug build variant in Android Studio

后端 未结 16 720
不知归路
不知归路 2021-02-01 14:22

I\'ve switched to release build variant and configured signingConfigs. Now when I try to check the debug build variant from the drop down menu it switches immediately back to th

相关标签:
16条回答
  • 2021-02-01 14:59

    Unrelated to your build.gradle file,

    Sharing hoping it might help someone else -

    I was having similar issue it was because one of the line in build.gradle -

    android {
        ...
        publishNonDefault true // remove this line and it should work!
    }
    

    Here you can get more detail about publishNonDefualt -


    It is also possible to publish all variants of a library. We are planning to allow this while using a normal project-to-project dependency (like shown above), but this is not possible right now due to limitations in Gradle (we are working toward fixing those as well). Publishing of all variants are not enabled by default. The snippet below enables this feature:


    0 讨论(0)
  • 2021-02-01 15:00

    Just need to cut ".idea" Folder and paste it outside Project root folder( For Back up if you need).These files will be auto regenerated. On Opening the project it"ll ask add module (app) to your project. You can ignore the same.

    It set set default build variant to be "debug". You can see build variant tab on left corner or hover on "Monitor" Symbol on left bottom to get build variant option.

    0 讨论(0)
  • 2021-02-01 15:01

    I had a similar problem where most of the Build menu items were greyed out.

    'Sync project with Gradle files' didn't fix.

    I noticed a 'Build Variants' toggle button on the bottom left of Android Studio (v 3.1.2) and with this was finally able to choose the variant I needed.

    Maybe this will work for you too.

    0 讨论(0)
  • 2021-02-01 15:03

    I have this question too. My solution is checkout to the branch which i had changed the build variants. And at that branch, I can change from release back to debug. Then just checkout to current branch and everything is OK. It seems to be a Android Studio bug.

    0 讨论(0)
  • 2021-02-01 15:04

    Maybe you have got your solution to this, just in case, i provide my solution here.


    For Android Studio 2.x

    It may because that you compile your dependent project using:

    compile project('module_a')
    

    Above setting will force your project to compile the release version of your modules. Just change it to below:

    releaseCompile project(path: ':module_a', configuration: 'release')
    debugCompile project(path: ':module_a', configuration: 'debug')
    

    For Android Studio 3.x

    You don't need to explicitly specify the build variant for a "module project". Just using

    implementation project(':library') 
    

    will automatically help select the correct build variant.

    Here is a detailed explanation: https://developer.android.com/studio/build/?utm_source=android-studio#variant_aware


    For Android Studio 3.x Upgraded from 2.x

    Delete the .idea folder under your project root directory and restart your Android Studio.

    Below is the GUI screenshot:

    Hope it helps!

    0 讨论(0)
  • 2021-02-01 15:04

    I tried all the above to no effect. Eventually stumbled across File > Invalidate Caches/Restart... for other reasons and found it worked for me.

    0 讨论(0)
提交回复
热议问题