android studio: release apk is not signed

前端 未结 7 1980
误落风尘
误落风尘 2021-02-04 02:07

* 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

相关标签:
7条回答
  • 2021-02-04 02:14

    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.

    0 讨论(0)
  • 2021-02-04 02:28

    Go to File\Project Structure

    Done! ;)

    0 讨论(0)
  • 2021-02-04 02:28

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

    signingConfig signingConfigs.config
    
    0 讨论(0)
  • 2021-02-04 02:29

    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".

    0 讨论(0)
  • 2021-02-04 02:29

    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 讨论(0)
  • 2021-02-04 02:35

    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
            }
        }
    
    0 讨论(0)
提交回复
热议问题