* 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 v
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 theandroid {}
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 syntaxkeystoreProperties['propertyName']
. Modify thesigningConfigs
block of your module'sbuild.gradle
file to reference the signing information stored inkeystoreProperties
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.