Assigned
Status Update
Comments
th...@gmail.com <th...@gmail.com> #2
Similar to https://issuetracker.google.com/issues/216663009 , but I think this warrants a bug, as
* it causes issues far down-stream,
* is hard to catch on release builds due to how deep into the callstack the exception occurs, away from stringResource (which can get obfuscated away)
* the fact that the developer is guided into using the buggy function call by AndroidStudio,
* there are multiple points of failure (suggestion, linting, compiler, and stringResource should possibly even check for bad context right after invocation)
* it causes issues far down-stream,
* is hard to catch on release builds due to how deep into the callstack the exception occurs, away from stringResource (which can get obfuscated away)
* the fact that the developer is guided into using the buggy function call by AndroidStudio,
* there are multiple points of failure (suggestion, linting, compiler, and stringResource should possibly even check for bad context right after invocation)
Description
Version used: androidx.glance:glance-appwidget:1.0.0-alpha05
Devices/Android versions reproduced on:
Physical GS8 API 28
stringResource should be implemented for Glance or appropriate build exceptions and linting need to be added. AndroidStudio currently guides developers into using it, leading to difficult-to-catch breaks in runtime.
stringResource is suggested in AndroidStudio under "Extract string resource" Context Action list (see image).
Repro:
Create a Text() within an @Component\nfun Content member of GlanceAppWidget
Add a string literal argument.
Open the Context Actions for the line and select "Extract string resource".
String will be replaced by inappropriate use of stringResource, which leads to runtime exception and crash in widget
Desired behavior:
1) Context action should implement LocalContext.current.getString instead of stringResource
2) stringResource should be caught by linter
3) stringResource should be caught by compiler
4) alternatively, stringResource should be re-implemented for Glance.
Creating a stringResource in a Glance widget leads directly to an Exception in the runtime with the following callstack:
Error in Glance App Widget
java.lang.IllegalStateException: CompositionLocal LocalConfiguration not present
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.noLocalProvidedFor(AndroidCompositionLocals.android.kt:168)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.access$noLocalProvidedFor(AndroidCompositionLocals.android.kt:1)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$LocalConfiguration$1.invoke(AndroidCompositionLocals.android.kt:47)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$LocalConfiguration$1.invoke(AndroidCompositionLocals.android.kt:44)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at androidx.compose.runtime.LazyValueHolder.getCurrent(ValueHolders.kt:29)
at androidx.compose.runtime.LazyValueHolder.getValue(ValueHolders.kt:31)
at androidx.compose.runtime.ComposerImpl.resolveCompositionLocal(Composer.kt:2039)
at androidx.compose.runtime.ComposerImpl.consume(Composer.kt:2007)
at androidx.compose.ui.res.Resources_androidKt.resources(Resources.android.kt:35)
at androidx.compose.ui.res.StringResources_androidKt.stringResource(StringResources.android.kt:35)