Skip to content

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:

build.gradle
buildscript {
    repositories {
        maven {
            url "https://artifactory.productscience.app/releases"
        }
    }
    dependencies { ... }
}

allprojects {
    repositories {
        maven {
            url "https://artifactory.productscience.app/releases"
        }
    }
}
build.gradle.kts
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:

settings.gradle
...
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven {
            url "https://artifactory.productscience.app/releases"
        }
    }
}
settings.gradle.kts
...
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

build.gradle
buildscript {
    repositories { ... }
    dependencies {
        classpath "com.productscience.transformer:transformer-plugin:0.16.28"
        classpath "com.productscience.transformer:transformer-instrumentation:0.16.28"
    }
}
...
build.gradle.kts
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

app/build.gradle
plugins {
    id "com.android.application"
    id "kotlin-android"
}
apply plugin: "com.productscience.transformer.plugin"
...
app/build.gradle.kts
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:

proguard-rules.pro.
-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.

app/build.gradle
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
        }
    }
}
app/build.gradle.kts
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.