23

* I have rephrased the post since originally posted *

When I try to run a just-built release apk, I get an error "the apk for your currently selected variant ... is not signed." This is in the Edit Configuration popup. Here are my steps:

  1. In the Build Variants tab, select "release"
  2. In the menu, choose Build -> Generate Signed APK
  3. In the popup, fill in the fields for the key store and passwords.
  4. In the second panel, change the destination folder to ...\app\build\outputs\apk (see note * below)
  5. Observe notification in upper right of studio: APK(s) generated successfully.
  6. In the menu, click Run -> Run App.
  7. I get an "Edit configuration" popup with the error "The apk for your currently selected variant ... is not signed.

So, why this error? The APK generated appears to be valid. I have successfully posted it to the Android Store (alpha testing only) and verified that stack dumps are obfuscated.

What I can't do is download it (step 6 above) to my device. I guess that's ok since I can download the debug version just fine.

(*) Android Studio defaults the output for the release apk to a higher, presumably more convenient directory. However I find it harder to manage the consistency of generated files when they are scattered about so I prefer all the generated apks in one place.

Peri Hartman
  • 17,906
  • 17
  • 49
  • 85

8 Answers8

39

Go to File\Project Structure

Signing Tab

Flavor Tab

Build Type

Done! ;)

Patzu
  • 1,630
  • 1
  • 21
  • 35
22

Set signing config in project structure.

  1. File -> Project Structure...
  2. Select Modules/app (or other module)
  3. Click Signing tab and fill in.
    Key Alias and Key Password comes first. Not same order in "Generate Signed APK" dialog.
  4. Click Build Types tab and select release.
    Select "config" in Signing config dropdown list.
  5. Click OK to close Project Structure.
  6. Run -> Run app

Run (or Debug) app seems to use apks built with "Buiild -> Build APK". So, we should set signing config if build variants of app module is "release".

Toris
  • 2,158
  • 10
  • 14
11

Add this line to your release {...} inside build.gradle

signingConfig signingConfigs.config
Ronny Shibley
  • 1,622
  • 18
  • 23
8

First, Create a keystore file if there isn't one.

  1. Click Build from the dropdown menu
  2. Select Generate Signed APK
  3. Click Next
  4. Click Create New Keystore
  5. Fill out the form for keystore path, alias, password for keystore and alias, at least one field in the certificate area.
  6. Click OK
  7. A keystore file will be created in the specified keystore path.

Second update the app build gradle file to someting like this one to include the signing config.

android {
    signingConfigs {
        config {
            keyAlias 'mykeyalias'
            keyPassword 'android'
            storeFile file('/Users/yourname/path/to/the/android/project/folder/android_project_folder_name/app/debug.keystore')
            storePassword 'android'
        }
    }
    buildTypes {
        debug {
            applicationIdSuffix = ".debug"
            versionNameSuffix "-debug"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
}

Third, build and run the app, done.

s-hunter
  • 17,762
  • 11
  • 67
  • 105
3

In https://developer.android.com/studio/publish/app-signing#secure-shared-keystore it is written that you shouldn't keep credentials information in build.gradle and VCS. So create a signing config file (Build > Generate Signed APK...), then do so.

Create a file named keystore.properties in the root directory of your project. This file should contain your signing information, as follows:

storePassword=myStorePassword
keyPassword=mykeyPassword
keyAlias=myKeyAlias
storeFile=myStoreFileLocation

In your module's build.gradle file, add code to load your keystore.properties file before the android {} block.

// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")

// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()

// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    ...
}

You can refer to properties stored in keystoreProperties using the syntax keystoreProperties['propertyName']. Modify the signingConfigs block of your module's build.gradle file to reference the signing information stored in keystoreProperties using this syntax.

android {
    signingConfigs {
        config {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    ...
}

Optionally in build.gradle you can add:

buildTypes {
    release {
        ...
        signingConfig signingConfigs.config
    }
}

Now you may make a signed apk. Don't forget to exclude keystore.properties from VCS.

CoolMind
  • 16,738
  • 10
  • 131
  • 165
0

Try add this in your build file:

buildTypes {
release {
        signingConfig signingConfigs.release
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled false
    }
}
0

I had the same issue turned out I misconfigured the signingConfigs property.

Specifically, I thought I didn't have a password for the key where I actually had set it. After adding the missing information, it worked.

signingConfigs {
        config {
            keyAlias 'key0'
            storeFile file('C:/Users/xxx/xxx/keystore/xxx.jks')
            storePassword '123'
            keyPassword '123' // this was missing
        }
    }
Edric
  • 18,215
  • 11
  • 68
  • 81
pseudozach
  • 196
  • 2
  • 10
0

Add this code in the build.gradle

buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
        debug {
            minifyEnabled false
            signingConfig signingConfigs.debug
        }
    }
Rishabh Kumar
  • 1,981
  • 3
  • 7
  • 21