Sputnik is a multi tool gradle plugin to help with common tedious tasks to do with gradle things.
It can :
- Generate the 'versionName', 'versionCode' and apk file name for a project.
- Add relevant proguard file to the application.
- Perform checkstyle, findbugs, lint and PMD code quality checks during the build process of the application.
To enable Sputnik to change the versionCode/Name of your project, update your defaultConfig
block to add sputnik dot calls for both
sputnik.versionName "1.0"
sputnik.versionCode 1
To give sputnik access to the name of the application so that it can rename the APK file as follows {appName}-{versionName}
you must explicitly pass the value in with sputnik.appName(app_name_goes_here)
.
You can change the format of the outputted APK file with sputnik.apkName('${appName}-${versionName}')
Acceptable parameters are :
- appName
- projectName
- flavorName
- buildType
- versionName
- versionCode
- commitHash
Available proguard files can be found at sputnik/resources/proguard
or by running the gradle task listProguard
to print the
various keys for each proguard file that can be used. By default Sputnik will add the projects proguard-rules.pro
file, or if it
is a library project the proguard-library.pro
file will be added. It will also add the standard Android proguard file proguard-android.txt
,
but the optimized version proguard-android-optimize.txt
is also available for your proguarding pleasure.
To add proguard files to your project :
sputnik.proguard {
include "android-optimize", "android-v7", "android-design"
exclude "android"
}
The exclude call isn't needed unless there is a file you explicitly want to exclude. e.g. if you want to add the optimized Android proguard file instead of the standard version.
Then all you need to do is enable proguard within your projects buildType
buildType {
release {
minifyEnabled true
shrinkResources true
}
}
You can also delete the default proguardFiles getDefaultProguardFile...
call as the proguard files will be applied using Sputnik from now on.
Sputnik by default will enable all code quality checks. To disable add the following to your build.gradle
sputnik.enableQuality(false)
Sputnik can be added to your project either from Bintray or Gradle's Plugin Portal.
####Gradle Plugin Portal
To add Sputnik to a project, update the root build.gradle
buildscript to include the following:
buildscript {
repositories {
// If you want to download from the Gradle Plugin Portal
maven { url "https://plugins.gradle.org/m2/" }
// If you want to download from jCenter
jcenter()
}
dependencies {
classpath 'com.tapadoo.android:sputnik:0.8.0'
}
}
You then need to apply the plugin to the projects build.gradle
apply plugin: 'com.tapadoo.android.sputnik'
And that's it. Happy Sputniking.
See the LICENSE file for license rights and limitations.