-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
195 lines (167 loc) · 6.07 KB
/
build.gradle.kts
File metadata and controls
195 lines (167 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import com.android.build.api.artifact.SingleArtifact
import com.android.build.api.variant.impl.VariantImpl
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.extensions.stdlib.capitalized
plugins {
id("com.android.application")
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}
android {
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "io.sentry.samples.android"
defaultConfig {
applicationId = "io.sentry.samples.android"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 2
versionName = project.version.toString()
externalNativeBuild {
cmake {
// Android 15: As we're using an older version of AGP / NDK, the STL is not 16kb page
// aligned yet
// Our example code doesn't use the STL, so we simply disable it
// See https://developer.android.com/guide/practices/page-sizes
arguments.add(0, "-DANDROID_STL=none")
}
}
ndk { abiFilters.addAll(Config.Android.abiFilters) }
}
lint {
disable.addAll(
listOf(
"Typos",
"PluralsCandidate",
"MonochromeLauncherIcon",
"TextFields",
"ContentDescription",
"LabelFor",
"HardcodedText",
)
)
}
buildFeatures {
// Determines whether to support View Binding.
// Note that the viewBinding.enabled property is now deprecated.
viewBinding = true
compose = true
buildConfig = true
prefab = true
}
composeOptions { kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() }
dependenciesInfo {
// Disables dependency metadata when building APKs.
includeInApk = false
// Disables dependency metadata when building Android App Bundles.
includeInBundle = false
}
externalNativeBuild { cmake { path("CMakeLists.txt") } }
signingConfigs {
getByName("debug") {
storeFile = rootProject.file("debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}
buildTypes {
getByName("debug") {
addManifestPlaceholders(mapOf("sentryDebug" to true, "sentryEnvironment" to "debug"))
}
getByName("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.getByName("debug") // to be able to run release mode
isShrinkResources = true
addManifestPlaceholders(mapOf("sentryDebug" to false, "sentryEnvironment" to "release"))
}
}
kotlin { compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 }
androidComponents.beforeVariants {
it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType)
}
androidComponents.onVariants { variant ->
val taskName = "toggle${variant.name.capitalized()}NativeLogging"
val toggleNativeLoggingTask =
project.tasks.register<ToggleNativeLoggingTask>(taskName) {
mergedManifest.set(variant.artifacts.get(SingleArtifact.MERGED_MANIFEST))
rootDir.set(project.rootDir.absolutePath)
}
project.afterEvaluate {
(variant as? VariantImpl<*>)?.taskContainer?.assembleTask?.configure {
finalizedBy(toggleNativeLoggingTask)
}
(variant as? VariantImpl<*>)?.taskContainer?.installTask?.configure {
finalizedBy(toggleNativeLoggingTask)
}
}
}
@Suppress("UnstableApiUsage") packagingOptions { jniLibs { useLegacyPackaging = true } }
}
dependencies {
implementation(
kotlin(Config.kotlinStdLib, org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION)
)
implementation(projects.sentryAndroid)
implementation(projects.sentryAndroidFragment)
implementation(projects.sentryAndroidTimber)
implementation(projects.sentryCompose)
implementation(projects.sentryKotlinExtensions)
implementation(projects.sentryOkhttp)
// how to exclude androidx if release health feature is disabled
// implementation(projects.sentryAndroid) {
// exclude(group = "androidx.lifecycle", module = "lifecycle-process")
// exclude(group = "androidx.lifecycle", module = "lifecycle-common-java8")
// exclude(group = "androidx.core", module = "core")
// }
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.fragment.ktx)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.foundation.layout)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.recyclerview)
implementation(libs.coil.compose)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.retrofit)
implementation(libs.retrofit.gson)
implementation(libs.sentry.native.ndk)
implementation(libs.timber)
implementation(libs.camerax.core)
implementation(libs.camerax.camera2)
implementation(libs.camerax.lifecycle)
implementation(libs.camerax.view)
debugImplementation(libs.leakcanary)
}
abstract class ToggleNativeLoggingTask : Exec() {
@get:Input abstract val rootDir: Property<String>
@get:InputFile abstract val mergedManifest: RegularFileProperty
override fun exec() {
isIgnoreExitValue = true
val manifestFile = mergedManifest.get().asFile
val manifestContent = manifestFile.readText()
val match = regex.find(manifestContent)
if (match != null) {
val value = match.groupValues[1].toBooleanStrictOrNull()
if (value != null) {
val args = mutableListOf<String>()
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
args.add(0, "cmd")
args.add(1, "/c")
}
args.add("${rootDir.get()}/scripts/toggle-codec-logs.sh")
args.add(if (value) "enable" else "disable")
commandLine(args)
super.exec()
}
}
}
companion object {
private val regex =
Regex(
"""<meta-data\s+[^>]*android:name="io\.sentry\.session-replay\.debug"[^>]*android:value="([^"]+)""""
)
}
}