How to create a release signed apk file using Gradle?

前端 未结 30 1700
既然无缘
既然无缘 2020-11-22 13:48

I would like to have my Gradle build to create a release signed apk file using Gradle.

I\'m not sure if the code is correct or if I\'m missing a parameter when doing

30条回答
  •  日久生厌
    2020-11-22 13:58

    (In reply to user672009 above.)

    An even easier solution, if you want to keep your passwords out of a git repository; yet, want to include your build.gradle in it, that even works great with product flavors, is to create a separate gradle file. Let's call it 'signing.gradle' (include it in your .gitignore). Just as if it were your build.gradle file minus everything not related to signing in it.

    android {
        signingConfigs { 
            flavor1 {
                storeFile file("..")
                storePassword ".."
                keyAlias ".."
                keyPassword ".."
            }
            flavor2 {
                storeFile file("..")
                storePassword ".."
                keyAlias ".."
                keyPassword ".."
            }
        }
    }
    

    Then in your build.gradle file include this line right underneath "apply plugin: 'android'"

     apply from: 'signing.gradle'
    

    If you don't have or use multiple flavors, rename "flavor1" to "release" above, and you should be finished. If you are using flavors continue.

    Finally link your flavors to its correct signingConfig in your build.gradle file and you should be finished.

      ...
    
      productFlavors {
    
          flavor1 {
              ...
              signingConfig signingConfigs.flavor1
          }
    
          flavor2 {
              ...
              signingConfig signingConfigs.flavor2
          }
      }
    
      ...
    

提交回复
热议问题