Reputation: 258
I am trying to implement a search bar and a box just below to search & display an address list using Jetpack Compose (my first UI using Kotlin). This is how I did it :
@Composable
private fun LocalizationScreen(
addressList: List<String>,
onSearchValueChanged: (query: String) -> Unit
) {
var isSearching by remember { mutableStateOf(false) }
displayText = remember { mutableStateOf("") }.value
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
OutlinedTextField(
value = displayText,
onValueChange = {
isSearching = it.isNotEmpty()
onSearchValueChanged.invoke(it)
},
label = { Text(text = "Adresse") }
)
AddressListBox(addressList = addressList, isSearching)
}
When I launch the app, it displays a basic OutlineTextField
. But when I click on it, the app crashes with the following stacktrace :
java.lang.NoSuchMethodError: No static method setInitialSurroundingText(Landroid/view/inputmethod/EditorInfo;Ljava/lang/CharSequence;)V in class Landroidx/core/view/inputmethod/EditorInfoCompat; or its super classes (declaration of 'androidx.core.view.inputmethod.EditorInfoCompat' appears in /data/app/~~****************==/bla.blac.bla.debug-TLWFWI3WdhzpXiEL2uW_8g==/base.apk)
at androidx.compose.ui.text.input.TextInputServiceAndroid_androidKt.update(TextInputServiceAndroid.android.kt:335)
at androidx.compose.ui.text.input.TextInputServiceAndroid.createInputConnection(TextInputServiceAndroid.android.kt:104)
at androidx.compose.ui.platform.AndroidComposeView.onCreateInputConnection(AndroidComposeView.android.kt:945)
at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:2250)
at android.view.inputmethod.InputMethodManager$DelegateImpl.startInput(InputMethodManager.java:699)
at android.view.ImeFocusController.checkFocus(ImeFocusController.java:192)
at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:2431)
at android.view.inputmethod.InputMethodManager.showSoftInput(InputMethodManager.java:1892)
at android.view.inputmethod.InputMethodManager.showSoftInput(InputMethodManager.java:1815)
at androidx.compose.ui.text.input.InputMethodManagerImpl.showSoftInput(InputMethodManager.kt:62)
at androidx.compose.ui.text.input.TextInputServiceAndroid.keyboardVisibilityEventLoop(TextInputServiceAndroid.android.kt:189)
at androidx.compose.ui.text.input.TextInputServiceAndroid$keyboardVisibilityEventLoop$1.invokeSuspend(Unknown Source:14)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8595)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
I am using compose version 1.0.1
with kotlin 1.5.21
. Also the compose compiler version 1.0.1
:
composeOptions {
kotlinCompilerExtensionVersion = "1.0.1"
}
I already tried the usual "Invalide caches and restart" and downgraded compose version from 1.0.2
and kotlin version from 1.5.30
(which requires an alpha version of the compose compiler)
Does anyone has an idea of what is happening here ? (Thank you for reading this far)
Upvotes: 1
Views: 4450
Reputation: 258
Turns out I needed to declare all compose dependencies in my app module too (yeah I am in a multi module project. Sorry I missed this information).
So in my sub-module build.gradle
I had :
dependencies {
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.compiler:compiler:1.1.0-alpha04"
}
android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.1.0-alpha04"
}
kotlinOptions {
jvmTarget = "1.8"
}
}
And in my main module build.gradle
I now have the same (which I didn't have before) :
dependencies {
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.compiler:compiler:1.1.0-alpha04"
}
android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.1.0-alpha04"
}
kotlinOptions {
jvmTarget = "1.8"
}
}
Upvotes: 10