Gradle Build Instructions - Android
1. Credentials
Product Science shared access credentials (productscience.properties
file) via Bitwarden sent.
Please place it in the root directory of your project.
2. Add Product Science maven repository
In build.gradle
add the maven build info to the repositories for project and subprojects:
buildscript {
repositories {
maven {
url "https://artifactory.productscience.app/releases"
}
}
dependencies { ... }
}
allprojects {
repositories {
maven {
url "https://artifactory.productscience.app/releases"
}
}
}
buildscript {
repositories {
maven {
url "https://artifactory.productscience.app/releases"
}
}
dependencies { ... }
}
allprojects {
repositories {
maven {
url "https://artifactory.productscience.app/releases"
}
}
}
If the project is configured to prefer settings repositories maven source should be added to settings file:
...
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven {
url "https://artifactory.productscience.app/releases"
}
}
}
...
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven {
url "https://artifactory.productscience.app/releases"
}
}
}
In another case, if allprojects
is not present in top level build.gradle
then add it in the top of the file.
3. Add Product Science plugin to classpath
buildscript {
repositories { ... }
dependencies {
classpath "com.productscience.transformer:transformer-plugin:0.16.28"
classpath "com.productscience.transformer:transformer-instrumentation:0.16.28"
}
}
...
buildscript {
repositories { ... }
dependencies {
classpath("com.productscience.transformer:transformer-plugin:0.16.28")
classpath("com.productscience.transformer:transformer-instrumentation:0.16.28")
}
}
...
Please label your build with the PSi Plugin Version from above i.e.
MyAppPSi0.9.1.apk
so our AI can learn how its dynamic instrumentation is performing on the build.
4. Apply the Product Science Plugin
Apply plugin to app/build.gradle
plugins {
id "com.android.application"
id "kotlin-android"
}
apply plugin: "com.productscience.transformer.plugin"
...
plugins {
id("com.android.application")
id("kotlin-android")
id("com.productscience.transformer.plugin")
}
...
5. Add Proguard rules
If the application uses obfuscation/shrinking add a new ProGuard rule to your project. To achieve it add the next line to the R8/ProGuard configuration file:
-keep class com.productscience.transformer.module.** { *; }
-keep class com.productscience.** { *; }
Your project may use the other proguard file name.
More information about R8/ProGuard configuration can be found here: https://developer.android.com/studio/build/shrink-code
6. Build your app
Now you can build your app with Gradle, i.e.:
./gradlew assemble
Please label your build with the Plugin Version from above i.e.
MyApp_PSi-0.14.2.apk
so our AI can learn how its dynamic instrumentation is performing on the build.
Enabling the plugin by build type
For plugin versions greater than 0.12.1,
you can integrate Product Science pipeline into your gradle build
selectively apply the plugin to a given build type by adding a productScience
block
at the top level of your app/build.gradle
file.
Inside the proguard block, add a block corresponding to the build type (must have the same name) and set enabled
to true
.
plugins {
id "com.android.application"
id "kotlin-android"
}
apply plugin: "com.productscience.transformer.plugin"
productScience {
psiRelease {
enabled true
}
}
android {
...
buildTypes {
psiRelease {
minifyEnabled true
}
release {
minifyEnabled true
}
}
}
plugins {
id("com.android.application")
id("kotlin-android")
id("com.productscience.transformer.plugin")
}
productScience {
create("psiRelease") {
isEnabled = true
}
}
android {
...
buildTypes {
create("psiRelease") {
isMinifyEnabled = true
}
getByName("release") {
isMinifyEnabled = true
}
}
}
If the productScience
block is missing or empty, the plugin will be applied to all build types.
If one or more build types appear in the productScience
block,
the plugin will be applied only to those build types that have enabled
set to true.