Android Gradle AGP8 部署
添加插件
- Kotlin DSL
- Groovy DSL
- 在 settings.gradle 文件中添加基调听云仓库。
pluginManagement {
repositories {
maven ( url = "https://nexus2.tingyun.com/nexus/content/repositories/snapshots/" )
//maven(url = "./repo")// 本地集成需将 repo 文件夹复制到项目根目录
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven ( url = "https://nexus2.tingyun.com/nexus/content/repositories/snapshots/" )
//maven(url = "./repo")// 本地集成需将 repo 文件夹复制到项目根目录
}
}
- 在 Project 级别的 build.gradle 文件中添加基调听云插件。
plugins {
id("com.android.application") version "8.1.0" apply false //demo used
id("com.networkbench.gradleplugin.agp8on") version "2.17.7" apply false
//若项目仍使用 classpath 依赖,可以使用以下配置
//classpath("com.networkbench:newlens-gradle-plugin:2.17.7")
}
- 在 App 级别的 build.gradle 文件中添加以下内容。
id("newlens")// 放在 id("com.android.application") 下面
dependencies {
implementation("com.networkbench:tingyun-ea-agent-android:2.17.7")
implementation("com.networkbench.newlens.agent.android2:nbs.newlens.nativecrash:2.0.8")// 采集native carsh 需集成此包
implementation("com.networkbench:nbs.newlens.android.log:1.0.2")// 日志回捞需集成此包
// 采集 OOM 数据需要 kotlin-gradle-plugin 插件 1.3+ ,并依赖 androidx.core:core-ktx、androidx.appcompat:appcompat、androidx.lifecycle:lifecycle-process、com.squareup.okio:okio 等库
implementation("com.networkbench:tingyun-javaleak:1.0.2")// 采集 OOM 需集成此包
implementation("org.bouncycastle:bcprov-jdk15to18:1.78.1")// 启用国密加密需集成此包
implementation("org.bouncycastle:bcpkix-jdk15to18:1.78.1")// 启用国密加密需集成此包
}
- 在 settings.gradle 文件中添加基调听云仓库。
pluginManagement {
repositories {
maven { url "https://nexus2.tingyun.com/nexus/content/repositories/snapshots/" }// 添加基调听云仓库
//maven { url uri('./repo') }// 本地集成需将 repo 文件夹复制到项目根目录
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven { url "https://nexus2.tingyun.com/nexus/content/repositories/snapshots/" }// 添加基调听云仓库
//maven { url uri('./repo') }// 本地集成需将 repo 文件夹复制到项目根目录
}
}
- 在 Project 级别的 build.gradle 文件中添加基调听云插件。
plugins {
id 'com.android.application' version "8.1.0" apply false //demo used
id 'com.networkbench.gradleplugin.agp8on' version "2.17.7" apply false //添加基调听云插件
//若项目仍使用 classpath 依赖,可以使用以下配置
//classpath "com.networkbench:newlens-gradle-plugin:2.17.7"
}
- 在 App 级别的 build.gradle 文件中添加以下内容。
apply plugin:'newlens'// 放在 apply plugin: 'com.android.application' 下面
dependencies {
implementation "com.networkbench:tingyun-ea-agent-android:2.17.7"
implementation "com.networkbench.newlens.agent.android2:nbs.newlens.nativecrash:2.0.8"// 采集native carsh 需集成此包
implementation "com.networkbench:nbs.newlens.android.log:1.0.2" // 日志回捞需集成此包
// 采集 OOM 数据需要 kotlin-gradle-plugin 插件 1.3+ ,并依赖 androidx.core:core-ktx、androidx.appcompat:appcompat、androidx.lifecycle:lifecycle-process、com.squareup.okio:okio 等库
implementation "com.networkbench:tingyun-javaleak:1.0.2" // 采集 OOM 需集成此包
implementation "org.bouncycastle:bcprov-jdk15to18:1.78.1"// 启用国密加密需集成此包
mplementation "org.bouncycastle:bcpkix-jdk15to18:1.78.1"// 启用国密加密需集成此包
}
添加基调听云SDK
-
获取基调听云 App Key。
-
初始化 SDK。
i. 在 Application 中的 onCreate() 方法初始化Android SDK。
//"Appkey" 请从基调听云平台获取
//"Host" 为基调听云平台「Redirect」服务器地址,无需添加协议头
// setStartOption(7) 设置首次启动开启网络、用户体验、崩溃采集,仅首次启动生效
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host").setStartOption(7).start(this.getApplicationContext());ii. SDK默认以HTTPS上传数据,若服务端只支持HTTP,需设置 「setHttpEnabled(true)」。
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host").setHttpEnabled(true).setStartOption(7).start(this.getApplicationContext());