Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global signingConfig for multi-project build

Tags:

android

gradle

I'm using project structure like this:

root
  |--build.gradle
  |--settings.gradle
  |
  |--child1
  |    |--build.gradle
  |
  |--child2
       |--build.gradle

In both child projects build.gradle contains the following:

apply plugin: 'android'

...

android {
    ...

    signingConfigs {
        release {
            storeFile file("release.keystore")
            storePassword "pass"
            keyAlias "alias"
            keyPassword "pass"
        }
    }

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

How can I move signingConfigs part to the root project to reduce code duplication?

like image 473
Sergey Ch. Avatar asked Dec 22 '13 17:12

Sergey Ch.


People also ask

How to add signingconfigs for all Beta variants of a program?

So far the only solutions I could find is either putting the signingConfigs in the buildTypes so all Beta variants would have the same signingConfigs: buildTypes { beta { signingConfigs.beta } release { signingConfigs.release } } Alternatively, using the flavors, in which case all free variants would have the same signingConfigs:

How to use signingconfigs with Jenkins build script?

and now the signingconfigs work with the run button on the toolbar. For a default keystore the local.properties looks like In your Jenkins build script, you need to create a symbolic link from local.properties to where the properties file is on your build server.

How do I use MSBuild to build multiple projects faster?

You can use MSBuild to build multiple projects faster by running them in parallel. To run builds in parallel, you use the following settings on a multi-core or multiple processor computer:

Does the signingconfig on the mergedflavor actually sign the assembled apps?

Setting the signingConfig on the mergedFlavor does not actually sign the assembled apps. In my case, everything works fine and I sign up Google Market apps without any problems. This seems to be working fine for me as well.


1 Answers

I have try this code and it works. Be aware do not use signingConfigs in android-library project.

subprojects {

afterEvaluate {
    def isAndroidProject = project.plugins.hasPlugin('android')
    def isLibraryProject = project.plugins.hasPlugin('android-library')
    if (isAndroidProject || isLibraryProject) {
        android {
            compileSdkVersion 19
            buildToolsVersion 19.0.1

            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_7
                targetCompatibility JavaVersion.VERSION_1_7
            }

            if (isAndroidProject) {
                signingConfigs {
                    release {
                        storeFile file("${rootDir}/platform.keystore")
                        storePassword "android"
                        keyAlias "platform"
                        keyPassword "android"
                    }
                }

                buildTypes {
                    release {
                        signingConfig signingConfigs.release
                        minifyEnabled true
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), "${project.projectDir}/proguard-project.txt"
                    }
                }

                android.applicationVariants.all { variant ->
                    variant.outputs.each  { output ->
                        def buildType = variant.buildType.name
                        if (buildType.equals('release')) {
                            def fileName = "${project.name}.apk";
                            output.outputFile = new File(output.outputFile.parent, fileName)

                            output.assemble.doLast {
                                copy {
                                    from output.outputFile.getAbsolutePath()
                                    into "../apks/"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
like image 104
Tinker Sun Avatar answered Nov 10 '22 09:11

Tinker Sun