Flo*_*ang 1 android kotlin android-jetpack-compose
我正在尝试实现一个搜索栏和下面的一个框,以使用 Jetpack Compose(我的第一个使用 Kotlin 的 UI)搜索和显示地址列表。我就是这样做的:
@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)
}
Run Code Online (Sandbox Code Playgroud)
当我启动该应用程序时,它会显示一个基本的OutlineTextField. 但是当我单击它时,应用程序崩溃并显示以下堆栈跟踪:
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)
Run Code Online (Sandbox Code Playgroud)
我正在使用1.0.1kotlin 的compose 版本1.5.21。还有撰写编译器版本1.0.1:
composeOptions {
kotlinCompilerExtensionVersion = "1.0.1"
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了通常的“无效缓存并重新启动”,并降级了 compose 版本1.0.2和 kotlin 版本1.5.30(这需要 alpha 版本的 compose 编译器)
有人知道这里发生了什么吗?(感谢您读到这里)
Flo*_*ang 10
事实证明,我也需要在我的应用程序模块中声明所有 compose 依赖项(是的,我在一个多模块项目中。抱歉,我错过了此信息)。
所以在我的子模块中build.gradle我有:
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"
}
}
Run Code Online (Sandbox Code Playgroud)
在我的主模块中,build.gradle我现在有相同的(我以前没有):
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"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3970 次 |
| 最近记录: |