13

A little background. I have been building/debugging/testing my simple App for a few months with no problems. Build/install on AVD or my actual S9 phone. All worked just fine for months. Now, ready for my first beta release to the Play Store (my first app ever). So, I followed instructions on 'signing' my app. That worked and I uploaded my app bundle to the Play Store. Now I can't build/debug/install at all in Android Studio anymore.

Error: The apk for your currently selected variant (app-release-unsigned.apk) is not signed. Please specify a signing configuration for this variant (release).

enter image description here

Debug (Shift+F9) produces the above error and shows the "Edit configuration" dialog.

enter image description here

I click on the "Fix" button and from there I have no idea what to do. Or how to use these different build configurations.

enter image description here

build.gradle

apply plugin: 'com.android.application'

android {
    signingConfigs {
        debug {
            storeFile file(var)
            storePassword 'xxx'
            keyAlias = 'xxx'
            keyPassword 'xxx'
        }
    }
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.birdersdiary.mobile"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "b1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Once I click on the "FIX" button I am taken to the "Run/Debug Configurations" dialog. And from there it is completely oblivious to me what needs to happen in order to Fix the problem.

Any assistance greatly appreciated.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
JJJones_3860
  • 1,382
  • 2
  • 15
  • 35
  • 1
    You should set singing config for buildType release on your build.gradle. Post your app build.gradle if you need further help – Rick Sanchez Nov 30 '19 at 00:13
  • Thanks. I posted my build.gradle as requested. – JJJones_3860 Nov 30 '19 at 01:44
  • 1: you can modify build version flow below image [image](https://i.stack.imgur.com/A18B4.png) – MKD Jul 14 '21 at 02:55
  • Please do not edit solution announcements into the question. Accept (i.e. click the "tick" next to it) one of the existing answer, if there are any. You can also create your own answer, and even accept it, if your solution is not yet covered by an existing answer. Compare https://stackoverflow.com/help/self-answer – Yunnosch Sep 27 '21 at 06:32

4 Answers4

19

You can solve this problem by doing any of the following

  1. You need to switch your build variant back to debug you can do this by holding Ctrl+Alt+A on windows or CMD+ALT+A on mac then typing variant in the search bar, select build variant, this would show the build variant option in the left side of your android studio screen then you should select the variant that has debug appended to the name.

  2. If you want to use a release version you need to instruct android studio how to find the keys to sign the apk Add this to your app-level build.gradle file

    apply plugin: 'com.android.application'
    
    android {
     signingConfigs {
        debug {
            storeFile file(var)
            storePassword 'xxx'
            keyAlias = 'xxx'
            keyPassword 'xxx'
        }
        release {
            storeFile file(var)
            storePassword 'xxx'
            keyAlias = 'xxx'
            keyPassword 'xxx'
        }
    }
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.birdersdiary.mobile"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "b1.0"
        testInstrumentationRunner     "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
     }
    
    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    }
    

replace the placeholders with the actual value.

oziomajnr
  • 1,671
  • 1
  • 15
  • 39
  • Thanks oziomajnr; however, since this is my first app, I will need more specifics please, as I don't completely understand your response. I have posted my build.gradle above. – JJJones_3860 Nov 30 '19 at 01:46
  • I modified your build.gradle file @JJJones_3860 – oziomajnr Nov 30 '19 at 12:18
  • Your assistance is much appreciated. I believe the problem is in my making clear how all of this build/variant/signing configs are new and vague to me. I haven't a clue. I have made the modifications to my build.gradle as you show above, and the problem still persists. Ctl+Alt+A does nothing. However, Shft+Shft opens the search and I type in 'build variant' and I do get the Build Variants toolbar on the left side. It only shows 'app/release', no debug. So, still stuck in the same place. Problem not resolved. Please assume I know nothing about this stuff. – JJJones_3860 Nov 30 '19 at 16:37
  • 1
    There are so many moving parts here that, to the novice, it is mind-boggling. – JJJones_3860 Nov 30 '19 at 16:39
  • yes 1st option worked `tool window bar ` have tab called `build variant` there we have to select debug – Mohd Qasim Jan 30 '21 at 04:41
18

You should se the singing config after defining it. Though I guess name it something other than debug if you're going to use it for release:

buildTypes {
        release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

           signingConfig signingConfigs.debug
        }
    }
Rick Sanchez
  • 4,528
  • 2
  • 27
  • 53
  • thanks, but I need very primitive step-by-step. I am still stuck in the same place. I do not grasp what you are suggesting that I do to solve this problem. – JJJones_3860 Nov 30 '19 at 16:38
  • You have defined the config, but you need to set it. Note that I added a signingConfig line to buildType from your build.gradle – Rick Sanchez Nov 30 '19 at 17:10
  • Thanks again Rick. And sorry for being so dense. I don't understand these configs at all. I can tell you that I got around this issue just now by randomly trying things and finally under "run/debug configurations" I set "Deploy" from "Default APK" to "APK from app bundle". That problem is gone, but now, while the AVD comes up, it doesn't run/work. Sigh... – JJJones_3860 Nov 30 '19 at 18:00
  • I just need to know how to build a debug apk again and install it on my AVD for testing. That is all I need right now. – JJJones_3860 Nov 30 '19 at 18:12
  • 1
    Got it working again. Had to wipe the data of the AVD and do a cold boot. All seems to be working now. Fingers crossed. – JJJones_3860 Nov 30 '19 at 18:31
6

Please confirm all the below points are fine.

  1. In the left project panel
  • Click on the app and open Open Module Settings
  • Select Module in the let panel and select app
  • In the right panel you can see 3 tabs (Properties, Default Config, and Signing Configs)
  1. In signing Configs check below thinks (if you don not have one, please create new key)
  • set your jks file location in Store File
  • set store password alias and key password as well

enter image description here

  1. In Default Config - just check only application id is correct of yours

  2. Now in the left panel check do below thinks

  • Select Build Variants and scroll down to Signing Config
  • Check you have selected any or please select into $signingConfigs.release

enter image description here

Surendar D
  • 5,554
  • 4
  • 36
  • 38
4

On the left side of android studio, there is Build Variants. Changing from release to debug worked for me.

Build Variants

iamanbansal
  • 2,412
  • 2
  • 12
  • 20