Java.lang.nosuchmethoderror: нет статического метода для JetPack ComposableAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Java.lang.nosuchmethoderror: нет статического метода для JetPack Composable

Сообщение Anonymous »

Я создаю библиотеку Android для базовых диалогов. Прямо сейчас все, что у меня есть, это модуль Basic-Dialogs вместе с модулем App . Я вызываю композицию в модуле Basic-Dialogs из модуля Activity в приложении , и я продолжаю получать сообщение об ошибке исключения ниже о статическом методе , когда я пытаюсь запустить приложение. Что может быть не так с кодом? < /P>
java.lang.NoSuchMethodError: No static method BasicDialog(Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V in class Lcom//basic_dialogs/BasicDialogKt; or its super classes (declaration of 'com..basic_dialogs.BasicDialogKt' appears in /data/app/~~DOqVbMGsnzDWFS7_YdNgtw==/com..composedialogs-_5IuirMOFh5F8pL884Urnw==/base.apk!classes2.dex)

Activity
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeDialogsTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
BasicDialog(onDismiss = { }, onConfirmClick = { }, title = "Test Dialog", confirmButtonText = "Open") {
Text("This is a test dialog.")
}
}
}
}
}
}

basicdialog composable
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun BasicDialog(
title: String = "",
confirmButtonText: String,
onDismiss: () -> Unit,
onConfirmClick: () -> Unit,
content: @Composable () -> Unit
) {
Surface(
shape = MaterialTheme.shapes.medium,
color = MaterialTheme.colors.surface,
modifier = Modifier
.padding(4.dp)
) {
Dialog(
onDismissRequest = onDismiss,
properties = DialogProperties(
dismissOnBackPress = true,
dismissOnClickOutside = true,
usePlatformDefaultWidth = false
),
) {
if (title != "") {
Text(title)
Spacer(Modifier.padding(5.dp))
}

content()
Spacer(Modifier.padding(5.dp))
TextButton(onClick = onDismiss) {
Text(text = stringResource(id = R.string.dialog_cancel), fontSize = 16.sp)
}
TextButton(onClick = { onConfirmClick() }) {
Text(text = confirmButtonText, fontSize = 16.sp)
}
}
}
}

file Project Gradle
buildscript {
ext {
compose_version = '1.1.0-beta01'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}

task clean(type: Delete) {
delete rootProject.buildDir
}

Module Module File
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 32

defaultConfig {
applicationId "com..composedialogs"
minSdk 27
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
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.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation project(path: ':basic-dialogs')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

файл класса модуля базового модуля
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 32

defaultConfig {
minSdk 27
targetSdk 32

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
}


Подробнее здесь: https://stackoverflow.com/questions/733 ... composable
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»