1. Description

The Sensosrdata Android Tracking SDK Plugin has made significant functional updates since version v4.0.0-beta to adapt to AGP 8.0+ (Android Gradle Plugin), including:

  1. Compatibility of AGP 8.0+ Instrumentation API and Transform API;
  2. Support for Gradle Plugins DSL integration;
  3. Optimized plugin configuration, please refer to the Plugin Configuration section for specific details.

2. Gradle Plugins DSL Integration

2.1. Add Maven Repository

Add Maven Repository in settings.gradle file:

pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() //Maven 仓库 		//... } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() //Maven 仓库 		//... } } ...
GROOVY

2.2. Declare plugin path

Add Sensosrdata plugin declaration in project/build.gradle:

plugins { id 'com.android.application' version '7.3.1' apply false //demo used id 'com.android.library' version '7.3.1' apply false //demo used id 'org.jetbrains.kotlin.android' version '1.7.20' apply false id 'org.jetbrains.kotlin.jvm' version '1.7.20' apply false 	//... 	//添加神策插件路径声明,4.0.0-beta 是插件版本号  id 'com.sensorsdata.analytics.android' version "4.0.0-beta" apply false }
GROOVY

2.3. Use the plugin

Use the plugin in app/build.gradle:

plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' 	//... 	//使用神策插件 id 'com.sensorsdata.analytics.android' }
GROOVY

3. Common Plugin Configuration

3.1. Changes in Plugin 4.0.0+

In order to simplify plugin configuration and adapt to AGP 8.0+, the following plugin configurations have been removed since Plugin 4.0.0+:

  • disablePlugin
  • disableMultiThreadBuild
  • disableIncrementalBuild
  • disableJar
  • disableTrackPush
  • disableCheckSDK
  • autoHandleWebView
ConfigurationReason for deletion and replacement
  • disablePlugin
Redundant configuration. Can be replaced by not using plugins.
  • disableMultiThreadBuild
Cannot be applied in AGP 8.0+.
  • disableIncrementalBuild
Cannot be applied in AGP 8.0+.
  • disableJar
Cannot be applied in AGP 8.0+.
  • disableTrackPush
Please use disableModules instead.
  • disableCheckSDK
Please use disableModules instead.
  • autoHandleWebView
Please use disableModules instead.


Attention

  • If the project involves the above configuration, you can choose not to upgrade to Plugin 4.0.0+.
  • If the project uses AGP 8.0+, an alternative method needs to be selected.

3.2. debug

The default value is false.

Represents whether to enable the debug mode.

If the debug mode is enabled, detailed log information will be printed during the compilation.

sensorsAnalytics { 	debug = true }
CODE

3.3. exclude

Blacklist, you can use exclude to specify which class or package not to process.

Configuration example:

sensorsAnalytics {      exclude = ['a.b.c', 'a.b.c.A'] }
CODE

Don't process a specific class or all classes under a package.

3.4. Enable UC Browser integration

Used for annotation insertion in the UC Browser kernel.

sensorsAnalytics {      addUCJavaScriptInterface = true }
CODE

3.5. sensorsAnalytics.isHookOnMethodEnter

Whether to insert code when entering a method, the default value is false. This configuration only applies to plugin version 3.1.9 and above.

If you need to configure it, add the following configuration to the gradle.properties in the project:

sensorsAnalytics.isHookOnMethodEnter = true
CODE

3.6. disableModules

Used to indicate the disabled modules, which will not be instrumented. This configuration only applies to plugin version 4.0.0+, and currently supports the following configurations:

  1. AUTOTRACK
  2. PUSH
  3. WEB_VIEW

Especially when using the modularized dependency approach to integrate SensorsData SDK, be sure to disable certain modules, such as:

sensorsAnalytics {     disableModules = ['PUSH'] }
CODE

The above configuration indicates that no instrumentation will be applied to the "push" module.