Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to switch to debug build variant in Android Studio

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 the release build variant. So I'm not able to run my app in debug mode any more.

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'realm-android'  android {     signingConfigs {         config {             ...         }     }      compileSdkVersion rootProject.compileSdkVersion     buildToolsVersion rootProject.buildToolsVersion      defaultConfig {         applicationId "com.kost.foo"         minSdkVersion rootProject.minSdkVersion         targetSdkVersion rootProject.targetSdkVersion         versionCode 2         versionName "1.1"         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"         ndk {             abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'         }         externalNativeBuild {             cmake {                ...             }         }     }      buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'             debuggable true             signingConfig signingConfigs.config         }     }      sourceSets {         main.java.srcDirs += 'src/main/kotlin'         main {             jniLibs.srcDirs = ['src/main/jni']         }     }      externalNativeBuild {         cmake {             path 'src/main/jni/CMakeLists.txt'         }     } }  kapt {     generateStubs = true }  repositories {     maven { url 'https://github.com/linchaolong/stetho-realm/raw/master/maven-repo' }     mavenCentral()  } 

I've tried to revert all changes in build.gradle as it was before configuring, but with no luck.

Any ideas how to fix the issue?

like image 847
AlexKost Avatar asked Mar 07 '17 14:03

AlexKost


People also ask

Where is build variants in Android Studio?

To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar. For projects without native/C++ code, the Build Variants panel has two columns: Module and Active Build Variant.

What is Productflavors Android?

Android Product Flavors are used to create different app versions. App versions can be free or paid. They can have different themes and texts. They can use different environments or APIs. Let's assign two product flavors free and paid in our application.


2 Answers

I had a similar problem where most of the Build menu items were greyed out. 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.

Choose variant from here

Maybe this will work for you too.

like image 73
paws Avatar answered Oct 05 '22 13:10

paws


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:

enter image description here

Hope it helps!

like image 27
shizhen Avatar answered Oct 05 '22 12:10

shizhen