gpt4 book ai didi

将 Android Studio 升级到 3.1.0 后的 Android Support 插件错误

转载 作者:行者123 更新时间:2023-12-03 15:49:48 26 4
gpt4 key购买 nike

我在我的项目中使用 Kotlin 和数据绑定(bind),最近升级到 Android Studio 3.1.0 后,我经常在 Android 支持插件中看到很多异常:

Could not initialize class android.databinding.tool.ext.ExtKt java.lang.NoClassDefFoundError: Could not initialize class android.databinding.tool.ext.ExtKt at android.databinding.tool.reflection.ModelClass.getTypeName(ModelClass.java:688) at android.databinding.tool.reflection.ModelClass.equals(ModelClass.java:694) at android.databinding.tool.reflection.ModelClass.findSetter(ModelClass.java:614) at android.databinding.tool.reflection.ModelClass.findGetterOrField(ModelClass.java:523) at com.android.tools.idea.lang.databinding.DataBindingXmlReferenceContributor$2.getReferencesByElement(DataBindingXmlReferenceContributor.java:196) at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl.getReferences(ReferenceProvidersRegistryImpl.java:135) at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl.mapNotEmptyReferencesFromProviders(ReferenceProvidersRegistryImpl.java:123) at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl.doGetReferencesFromProviders(ReferenceProvidersRegistryImpl.java:102) at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(ReferenceProvidersRegistry.java:59) at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(ReferenceProvidersRegistry.java:53) at com.android.tools.idea.lang.databinding.DataBindingPsiElement.getReferences(DataBindingPsiElement.java:32) at org.intellij.plugins.intelliLang.references.InjectedReferencesContributor.getInjectedReferences(InjectedReferencesContributor.java:56) at org.intellij.plugins.intelliLang.references.InjectedReferencesInspection$1.visitElement(InjectedReferencesInspection.java:40) at com.intellij.psi.impl.PsiElementBase.accept(PsiElementBase.java:274) at com.android.tools.idea.lang.databinding.psi.impl.PsiDbExprImpl.accept(PsiDbExprImpl.java:43) at com.android.tools.idea.lang.databinding.psi.impl.PsiDbRefExprImpl.accept(PsiDbRefExprImpl.java:42) at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:82) at com.intellij.codeInspection.InspectionEngine.createVisitorAndAcceptElements(InspectionEngine.java:70) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.doInspectInjectedPsi(LocalInspectionsPass.java:750) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$inspectInjectedPsi$6(LocalInspectionsPass.java:338) at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:133) at com.intellij.concurrency.ApplierCompleter.tryToExecAllList(ApplierCompleter.java:223) at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:151) at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1125) at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:105) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:543) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:488) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:94) at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:116) at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:96) at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:143) at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:229) at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96) at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.pollAndExecCC(ForkJoinPool.java:1190) at java.util.concurrent.ForkJoinPool.helpComplete(ForkJoinPool.java:1879) at java.util.concurrent.ForkJoinPool.awaitJoin(ForkJoinPool.java:2045) at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:390) at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719) at java.util.concurrent.ForkJoinPool.invoke(ForkJoinPool.java:2616) at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:65) at com.intellij.concurrency.JobLauncher.invokeConcurrentlyUnderProgress(JobLauncher.java:57) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspectInjectedPsi(LocalInspectionsPass.java:341) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:231) at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:136) at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:83) at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:70) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:437) at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1130) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:430) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:543) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:488) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:94) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:429) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:405) at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:143) at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:229) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:403) at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:170) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)



我的主 build.gradle
buildscript {
ext.kotlin_version = '1.2.31'
ext.protobuf_version = '3.0.0'
ext.anko_version='0.10.4'

repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.5'
}
}

allprojects {
repositories {
google()
jcenter()
}
}

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

申请 build.gradle
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'project-report'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "com.myapp"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dataBinding {
enabled = true
}
}

kapt {
useBuildCache = true
mapDiagnosticLocations = true
}

dependencies {
implementation project(':proto')

implementation "android.arch.persistence.room:runtime:1.0.0"
implementation 'com.android.support:recyclerview-v7:27.1.0'
kapt "android.arch.persistence.room:compiler:1.0.0"
kapt "com.android.databinding:compiler:3.1.0"

implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:common-java8:1.1.1"

implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.squareup.okhttp3:okhttp:3.9.1'

// Anko
implementation "org.jetbrains.anko:anko-sdk15:$anko_version"
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:support-vector-drawable:27.1.0'

testImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//noinspection GradleDependency
androidTestImplementation 'org.exparity:hamcrest-date:1.1.0'
}

gradle.properties
org.gradle.jvmargs=-Xmx2048m
kotlin.incremental.usePreciseJavaTracking=true
android.enableD8=true
android.databinding.enableV2=true

gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

到目前为止,我已经尝试过:
  • 使缓存无效并重新启动
  • 重新导入项目
  • 清理重建
  • 没有以前的配置的全新安装 + 重新导入项目 + 没有安装额外的插件
  • 在 gradle.properties 中用其中一个或全部注释掉每一行 + 无效并重新启动
  • 试过implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"在 gradle 中“以防万一”

  • 没有任何帮助,几乎每个文件中仍然会弹出错误。正如我所看到的,这在某种程度上与绑定(bind)和 kotlin 有关。

    有人遇到过这个问题吗?

    附言

    在布局 xml 文件中,甚至没有突出显示不存在的字符串资源,例如 @string/non_existing_title - 仅显示为有效的字符串资源(即使在全新安装之后)。
    虽然我不确定这个问题是否与报告的异常有关。

    更新 1

    我注意到在 Invalidate & restart 之后抛出另一个异常:
    com/squareup/javapoet/TypeName
    java.lang.NoClassDefFoundError: com/squareup/javapoet/TypeName
    at android.databinding.tool.ext.ExtKt.<clinit>(ext.kt:180)
    at android.databinding.tool.reflection.ModelClass.getTypeName(ModelClass.java:688)
    at android.databinding.tool.reflection.ModelClass.equals(ModelClass.java:694)
    at android.databinding.tool.reflection.ModelClass.findSetter(ModelClass.java:614)
    at android.databinding.tool.reflection.ModelClass.findGetterOrField(ModelClass.java:523)
    ....
    Caused by: java.lang.ClassNotFoundException: com.squareup.javapoet.TypeName PluginClassLoader[org.jetbrains.android, 10.3.1] com.intellij.ide.plugins.cl.PluginClassLoader@19c41e97
    at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:63)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 63 more

    我尝试添加 javapoet 依赖项,但在失效后仍然会抛出此异常一次。然后只有 Could not initialize class android.databinding.tool.ext.ExtKt如最初报告的那样抛出异常。

    最佳答案

    经过一番犹豫,我决定转移到金丝雀 channel 并安装 Android Studio Canary 10(导入以前的设置),现在规范是:

    Android Studio 3.2 Canary 10 Build #AI-181.2784.17.32.4705630,于 2018 年 4 月 7 日构建
    JRE:1.8.0_152-release-1136-b01 amd64
    JVM:JetBrains s.r.o Linux 4.13.0-38-generic 的 OpenJDK 64 位服务器 VM

    在安装时,我遇到了 kotlin 找不到很多类的多个问题;无效并重新启动,清理/重建没有帮助。

    然后我刚刚从 卸载了 Kotlin 插件插件 部分,看起来重启后它恢复为原始版本,此后我没有任何问题。

    当前 Kotlin 插件版本:版本:1.2.31-Studio3.2-1

    最后一切都按预期工作。 @Yazazzello,感谢您对 Android Studio Canary #10 的反馈。

    关于将 Android Studio 升级到 3.1.0 后的 Android Support 插件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49630048/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com