Anonymous
Невозможно найти метод java.lang.String com.squareup.javapoet.ClassName.canonicalName().
Сообщение
Anonymous » 18 дек 2025, 04:50
Скрипт Gradle синхронизируется правильно, но когда я пытаюсь запустить приложение, я получаю следующую ошибку:
Код: Выделить всё
Unable to find method ''java.lang.String com.squareup.javapoet.ClassName.canonicalName()''
'java.lang.String com.squareup.javapoet.ClassName.canonicalName()'
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Я уже испробовал все предложения, которые дает мне Android Studio, и не решил проблему. Я также проверил аналогичный случай здесь, на Stack Overflow, и не могу найти решение.
В проекте я использую Hilt для внедрения зависимостей, и у меня такое ощущение, что проблема может быть именно здесь, но сколько бы я ни проверял, все аннотации верны.
Это скрипт Gradle на уровне модуля
Код: Выделить всё
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt.plugin)
}
android {
namespace = "com.bdavidgm.consumoelectrico"
compileSdk = 36
defaultConfig {
applicationId = "com.bdavidgm.consumoelectrico"
minSdk = 26
targetSdk = 36
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
compose = true
}
}
configurations.all {
resolutionStrategy {
eachDependency {
if (requested.group == "com.squareup" && requested.name == "javapoet") {
useVersion("1.13.0")
}
}
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.room.common.jvm)
implementation(libs.androidx.room.ktx)
implementation(libs.androidx.runtime)
implementation(libs.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
// For datastore
// Preferences DataStore (SharedPreferences like APIs)
implementation("androidx.datastore:datastore-preferences:1.2.0")
// Alternatively - without an Android dependency.
implementation("androidx.datastore:datastore-preferences-core:1.2.0")
// For encryption
implementation("androidx.security:security-crypto:1.1.0")
// Hilt
implementation("com.google.dagger:hilt-android:2.57.1")
ksp("com.google.dagger:hilt-android-compiler:2.57.1")
//material icons
implementation("androidx.compose.material:material-icons-core:1.7.8")
implementation("androidx.compose.material:material-icons-extended:1.7.8")
}
Скрипт Gradle на уровне проекта
Код: Выделить всё
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
}
Это файл libs.versions.toml:
Код: Выделить всё
[versions]
agp = "8.12.3"
kotlin = "2.0.21"
coreKtx = "1.10.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.9.4"
activityCompose = "1.11.0"
composeBom = "2024.09.00"
roomCommonJvm = "2.8.4"
roomKtx = "2.8.4"
runtime = "1.9.5"
material3 = "1.4.0"
comGoogleDevtoolsKspGradlePlugin = "1.5.30-1.0.0"
kspver = "2.0.21-1.0.27" # Use an updated and compatible KSP version for Kotlin 2.0.21
hiltver = "2.57.2"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-room-common-jvm = { group = "androidx.room", name = "room-common-jvm", version.ref = "roomCommonJvm" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomKtx" }
androidx-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "runtime" }
material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "kspver" }
hilt-plugin = { id = "com.google.dagger.hilt.android", version.ref = "hiltver" }
А полный проект находится по адресу:
https://github.com/bdavidgm/Consumo-electrico.git
Подробнее здесь:
https://stackoverflow.com/questions/798 ... me-canonic
1766022636
Anonymous
Скрипт Gradle синхронизируется правильно, но когда я пытаюсь запустить приложение, я получаю следующую ошибку: [code]Unable to find method ''java.lang.String com.squareup.javapoet.ClassName.canonicalName()'' 'java.lang.String com.squareup.javapoet.ClassName.canonicalName()' Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project. In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes. [/code] Я уже испробовал все предложения, которые дает мне Android Studio, и не решил проблему. Я также проверил аналогичный случай здесь, на Stack Overflow, и не могу найти решение. В проекте я использую Hilt для внедрения зависимостей, и у меня такое ощущение, что проблема может быть именно здесь, но сколько бы я ни проверял, все аннотации верны. [b]Это скрипт Gradle на уровне модуля[/b] [code]plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.compose) alias(libs.plugins.ksp) alias(libs.plugins.hilt.plugin) } android { namespace = "com.bdavidgm.consumoelectrico" compileSdk = 36 defaultConfig { applicationId = "com.bdavidgm.consumoelectrico" minSdk = 26 targetSdk = 36 versionCode = 1 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = "17" } buildFeatures { compose = true } } configurations.all { resolutionStrategy { eachDependency { if (requested.group == "com.squareup" && requested.name == "javapoet") { useVersion("1.13.0") } } } } dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.activity.compose) implementation(platform(libs.androidx.compose.bom)) implementation(libs.androidx.ui) implementation(libs.androidx.ui.graphics) implementation(libs.androidx.ui.tooling.preview) implementation(libs.androidx.material3) implementation(libs.androidx.room.common.jvm) implementation(libs.androidx.room.ktx) implementation(libs.androidx.runtime) implementation(libs.material3) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(platform(libs.androidx.compose.bom)) androidTestImplementation(libs.androidx.ui.test.junit4) debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.test.manifest) // For datastore // Preferences DataStore (SharedPreferences like APIs) implementation("androidx.datastore:datastore-preferences:1.2.0") // Alternatively - without an Android dependency. implementation("androidx.datastore:datastore-preferences-core:1.2.0") // For encryption implementation("androidx.security:security-crypto:1.1.0") // Hilt implementation("com.google.dagger:hilt-android:2.57.1") ksp("com.google.dagger:hilt-android-compiler:2.57.1") //material icons implementation("androidx.compose.material:material-icons-core:1.7.8") implementation("androidx.compose.material:material-icons-extended:1.7.8") } [/code] [b]Скрипт Gradle на уровне проекта[/b] [code]plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.compose) apply false } [/code] [b]Это файл libs.versions.toml:[/b] [code][versions] agp = "8.12.3" kotlin = "2.0.21" coreKtx = "1.10.1" junit = "4.13.2" junitVersion = "1.1.5" espressoCore = "3.5.1" lifecycleRuntimeKtx = "2.9.4" activityCompose = "1.11.0" composeBom = "2024.09.00" roomCommonJvm = "2.8.4" roomKtx = "2.8.4" runtime = "1.9.5" material3 = "1.4.0" comGoogleDevtoolsKspGradlePlugin = "1.5.30-1.0.0" kspver = "2.0.21-1.0.27" # Use an updated and compatible KSP version for Kotlin 2.0.21 hiltver = "2.57.2" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } junit = { group = "junit", name = "junit", version.ref = "junit" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } androidx-ui = { group = "androidx.compose.ui", name = "ui" } androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-room-common-jvm = { group = "androidx.room", name = "room-common-jvm", version.ref = "roomCommonJvm" } androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "roomKtx" } androidx-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "runtime" } material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "kspver" } hilt-plugin = { id = "com.google.dagger.hilt.android", version.ref = "hiltver" } [/code] [b]А полный проект находится по адресу:[/b] https://github.com/bdavidgm/Consumo-electrico.git Подробнее здесь: [url]https://stackoverflow.com/questions/79849630/unable-to-find-method-java-lang-string-com-squareup-javapoet-classname-canonic[/url]