Skip to content

Commit 328436e

Browse files
committed
fix(kotlin-compiler): Fix Modifier.sentryTag() not found warning (#997)
* fix(kotlin-compiler): Fix Modifier.sentryTag() not found warning * Use local compiler plugin included build * Spotless * Changelog * Bump compose versions
1 parent 4e47c46 commit 328436e

File tree

7 files changed

+114
-98
lines changed

7 files changed

+114
-98
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Fix `Modifier.sentryTag()` not found warning ([#997](https://github.com/getsentry/sentry-android-gradle-plugin/pull/997))
8+
39
## 5.12.0
410

511
### Dependencies

examples/android-instrumentation-sample/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
alias(libs.plugins.kotlinAndroid)
44
alias(libs.plugins.kapt)
55
id("io.sentry.android.gradle")
6+
id("io.sentry.kotlin.compiler.gradle")
67
}
78

89
// useful for local debugging of the androidx.sqlite lib

examples/android-instrumentation-sample/src/main/java/io/sentry/samples/instrumentation/ui/ComposeActivity.kt

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,72 +11,77 @@ import androidx.compose.foundation.layout.fillMaxSize
1111
import androidx.compose.foundation.layout.padding
1212
import androidx.compose.foundation.shape.RoundedCornerShape
1313
import androidx.compose.foundation.text.BasicText
14+
import androidx.compose.runtime.Composable
1415
import androidx.compose.ui.Alignment
1516
import androidx.compose.ui.Modifier
1617
import androidx.compose.ui.draw.clip
1718
import androidx.compose.ui.graphics.Color
1819
import androidx.compose.ui.unit.dp
20+
import androidx.navigation.NavController
1921
import androidx.navigation.compose.NavHost
2022
import androidx.navigation.compose.composable
2123
import androidx.navigation.compose.rememberNavController
24+
import io.sentry.samples.instrumentation.ui.ComposeActivity.Destination
2225

2326
class ComposeActivity : ComponentActivity() {
2427

25-
override fun onCreate(savedInstanceState: Bundle?) {
26-
super.onCreate(savedInstanceState)
27-
setContent {
28-
val navController = rememberNavController()
28+
override fun onCreate(savedInstanceState: Bundle?) {
29+
super.onCreate(savedInstanceState)
30+
setContent {
31+
val navController = rememberNavController()
2932

30-
NavHost(
31-
navController = navController,
32-
startDestination = Destination.Home.route
33-
) {
34-
val pillShape = RoundedCornerShape(50)
33+
NavHost(navController = navController, startDestination = Destination.Home.route) {
34+
val pillShape = RoundedCornerShape(50)
3535

36-
composable(Destination.Home.route) {
37-
Column(
38-
modifier = Modifier.fillMaxSize(),
39-
horizontalAlignment = Alignment.CenterHorizontally,
40-
verticalArrangement = Arrangement.Center
41-
) {
42-
BasicText(
43-
modifier = Modifier
44-
.border(2.dp, Color.Gray, pillShape)
45-
.clip(pillShape)
46-
.clickable {
47-
navController.navigate(Destination.Details.route)
48-
}
49-
.padding(24.dp),
50-
text = "Home. Tap to go to Details."
51-
)
52-
}
53-
}
54-
composable(Destination.Details.route) {
55-
Column(
56-
modifier = Modifier.fillMaxSize(),
57-
horizontalAlignment = Alignment.CenterHorizontally,
58-
verticalArrangement = Arrangement.Center
59-
) {
60-
BasicText(
61-
modifier = Modifier
62-
.border(2.dp, Color.Gray, pillShape)
63-
.clip(pillShape)
64-
.clickable {
65-
navController.popBackStack()
66-
}
67-
.padding(24.dp),
68-
text = "Details. Tap or press back to return."
69-
)
70-
}
71-
}
72-
}
36+
composable(Destination.Home.route) {
37+
Column(
38+
modifier = Modifier.fillMaxSize(),
39+
horizontalAlignment = Alignment.CenterHorizontally,
40+
verticalArrangement = Arrangement.Center,
41+
) {
42+
HomeText(navController, pillShape)
43+
}
7344
}
45+
composable(Destination.Details.route) {
46+
Column(
47+
modifier = Modifier.fillMaxSize(),
48+
horizontalAlignment = Alignment.CenterHorizontally,
49+
verticalArrangement = Arrangement.Center,
50+
) {
51+
DetailsText(navController, pillShape)
52+
}
53+
}
54+
}
7455
}
56+
}
7557

76-
sealed class Destination(
77-
val route: String
78-
) {
79-
object Home : Destination("home")
80-
object Details : Destination("details")
81-
}
58+
sealed class Destination(val route: String) {
59+
object Home : Destination("home")
60+
61+
object Details : Destination("details")
62+
}
63+
}
64+
65+
@Composable
66+
fun HomeText(navController: NavController, pillShape: RoundedCornerShape) {
67+
BasicText(
68+
modifier =
69+
Modifier.border(2.dp, Color.Gray, pillShape)
70+
.clip(pillShape)
71+
.clickable { navController.navigate(Destination.Details.route) }
72+
.padding(24.dp),
73+
text = "Home. Tap to go to Details.",
74+
)
75+
}
76+
77+
@Composable
78+
fun DetailsText(navController: NavController, pillShape: RoundedCornerShape) {
79+
BasicText(
80+
modifier =
81+
Modifier.border(2.dp, Color.Gray, pillShape)
82+
.clip(pillShape)
83+
.clickable { navController.popBackStack() }
84+
.padding(24.dp),
85+
text = "Details. Tap or press back to return.",
86+
)
8287
}

examples/android-instrumentation-sample/src/main/java/io/sentry/samples/instrumentation/ui/MainActivity.kt

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,53 @@ import io.sentry.SpanStatus
1212
import io.sentry.TransactionOptions
1313
import io.sentry.samples.instrumentation.R
1414
import io.sentry.samples.instrumentation.SampleApp
15-
import io.sentry.samples.instrumentation.network.TrackService
1615
import io.sentry.samples.instrumentation.ui.list.TrackAdapter
17-
import kotlinx.coroutines.Dispatchers
1816
import kotlinx.coroutines.flow.collect
19-
import kotlinx.coroutines.flow.map
20-
import kotlinx.coroutines.withContext
2117

2218
class MainActivity : ComponentActivity() {
23-
override fun onCreate(savedInstanceState: Bundle?) {
24-
super.onCreate(savedInstanceState)
25-
setContentView(R.layout.activity_main)
19+
override fun onCreate(savedInstanceState: Bundle?) {
20+
super.onCreate(savedInstanceState)
21+
setContentView(R.layout.activity_main)
2622

27-
val list = findViewById<RecyclerView>(R.id.list)
28-
list.layoutManager = LinearLayoutManager(this)
29-
list.adapter = TrackAdapter()
23+
val list = findViewById<RecyclerView>(R.id.list)
24+
list.layoutManager = LinearLayoutManager(this)
25+
list.adapter = TrackAdapter()
3026

31-
lifecycleScope.launchWhenStarted {
32-
Sentry.getSpan()?.finish()
33-
val transaction = Sentry.startTransaction(
34-
"Track Interaction",
35-
"ui.action.load",
36-
TransactionOptions().apply { isBindToScope = true }
37-
)
38-
SampleApp.database.tracksDao()
39-
.all()
40-
.map {
41-
val remote = withContext(Dispatchers.IO) {
42-
TrackService.instance.tracks("6188aa82-3102-436a-9a68-513e6ad9efcb")
43-
}
44-
remote + it
45-
}
46-
.collect {
47-
(list.adapter as TrackAdapter).populate(it)
48-
transaction.finish(SpanStatus.OK)
49-
}
27+
lifecycleScope.launchWhenStarted {
28+
Sentry.getSpan()?.finish()
29+
val transaction =
30+
Sentry.startTransaction(
31+
"Track Interaction",
32+
"ui.action.load",
33+
TransactionOptions().apply { isBindToScope = true },
34+
)
35+
SampleApp.database
36+
.tracksDao()
37+
.all()
38+
// TODO: this service doesn't work anymore, need to find a replacement
39+
// .map {
40+
// val remote =
41+
// withContext(Dispatchers.IO) {
42+
// TrackService.instance.tracks("6188aa82-3102-436a-9a68-513e6ad9efcb")
43+
// }
44+
// remote + it
45+
// }
46+
.collect {
47+
(list.adapter as TrackAdapter).populate(it)
48+
transaction.finish(SpanStatus.OK)
5049
}
50+
}
5151

52-
findViewById<Toolbar>(R.id.toolbar).setOnMenuItemClickListener {
53-
if (it.itemId == R.id.action_add) {
54-
startActivity(Intent(this, EditActivity::class.java))
55-
return@setOnMenuItemClickListener true
56-
}
57-
if (it.itemId == R.id.action_compose) {
58-
startActivity(Intent(this, ComposeActivity::class.java))
59-
return@setOnMenuItemClickListener true
60-
}
61-
return@setOnMenuItemClickListener false
62-
}
52+
findViewById<Toolbar>(R.id.toolbar).setOnMenuItemClickListener {
53+
if (it.itemId == R.id.action_add) {
54+
startActivity(Intent(this, EditActivity::class.java))
55+
return@setOnMenuItemClickListener true
56+
}
57+
if (it.itemId == R.id.action_compose) {
58+
startActivity(Intent(this, ComposeActivity::class.java))
59+
return@setOnMenuItemClickListener true
60+
}
61+
return@setOnMenuItemClickListener false
6362
}
63+
}
6464
}

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ sample-androidx-recyclerView = "androidx.recyclerview:recyclerview:1.2.0"
6565
sample-androidx-lifecycle = "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
6666
sample-androidx-appcompat = "androidx.appcompat:appcompat:1.2.0"
6767

68-
sample-androidx-composeRuntime = "androidx.compose.runtime:runtime:1.1.1"
68+
sample-androidx-composeRuntime = "androidx.compose.runtime:runtime:1.5.4"
6969
sample-androidx-composeNavigation = "androidx.navigation:navigation-compose:2.5.2"
7070
sample-androidx-composeActivity = "androidx.activity:activity-compose:1.4.0"
71-
sample-androidx-composeFoundation = "androidx.compose.foundation:foundation:1.2.1"
72-
sample-androidx-composeFoundationLayout = "androidx.compose.foundation:foundation-layout:1.2.1"
71+
sample-androidx-composeFoundation = "androidx.compose.foundation:foundation:1.5.4"
72+
sample-androidx-composeFoundationLayout = "androidx.compose.foundation:foundation-layout:1.5.4"
7373

7474
sample-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "sampleCoroutines" }
7575
sample-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "sampleCoroutines" }

sentry-kotlin-compiler-plugin/src/kotlin2200/kotlin/io/sentry/compose/JetpackComposeTracingIrExtension22.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ class JetpackComposeTracingIrExtension22(private val messageCollector: MessageCo
8787

8888
val sentryModifierClassId = FqName("io.sentry.compose").classId("SentryModifier")
8989

90-
val sentryModifierCompanionClass =
91-
pluginContext.referenceClass(sentryModifierClassId)?.owner?.companionObject()
90+
val sentryModifierCompanionClass = pluginContext.referenceClass(sentryModifierClassId)?.owner
9291

9392
val sentryModifierTagFunction = sentryModifierClassId.callableId("sentryTag")
9493

settings.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ include(":examples:multi-module-sample:spring-boot-in-multi-module-sample2")
5454

5555
includeBuild("plugin-build")
5656

57-
includeBuild("sentry-kotlin-compiler-plugin")
57+
// this is needed so we can use kotlin-compiler-plugin directly in the sample app without publishing
58+
includeBuild("sentry-kotlin-compiler-plugin") {
59+
dependencySubstitution {
60+
substitute(module("io.sentry:sentry-kotlin-compiler-plugin")).using(project(":"))
61+
}
62+
}

0 commit comments

Comments
 (0)