尝试将.xml布局绑定到.kt文件时出现此错误。 这是我尝试使用Instant App支持功能创建应用程序
Error:10:35:11.151 [ERROR] [org.gradle.api.Task] e: ./../feature/src/main/java/my/${projectname}/${projectname}/feature/view/splash/fragment/LandingFragment.kt: (14, 37): Unresolved reference: databinding
10:35:11.154 [ERROR] [org.gradle.api.Task] e: ./../feature/src/main/java/my/${projectname}/${projectname}/feature/view/splash/fragment/LandingFragment.kt: (22, 42): Unresolved reference: FragmentLandingBinding
10:35:11.379 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':feature:compileDebugKotlin'.
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Compilation error. See log for more details
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
10:35:11.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --scan to get full insights.
10:35:11.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:35:11.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is:
10:35:11.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':feature:compileDebugKotlin'.
10:35:11.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
10:35:11.382 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
10:35:11.382 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
10:35:11.382 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
10:35:11.383 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
10:35:11.383 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
10:35:11.383 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
10:35:11.383 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
10:35:11.383 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
10:35:11.383 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
10:35:11.383 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
10:35:11.384 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
10:35:11.385 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:8)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:415)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:389)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:251)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:215)
10:35:11.386 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
10:35:11.387 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
10:35:11.387 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
10:35:11.387 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
10:35:11.387 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
10:35:11.387 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
10:35:11.387 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
10:35:11.387 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] ... 29 more
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org
10:35:11.388 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger]
10:35:11.389 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 13s
这是我的build.gradle(Project:projectname)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.versions = [
'kotlin_version' : '1.2.21',
'anko_version' : '0.10.4',
'glide_version' : '4.5.0',
'android_plugin_version' : '3.1.0-alpha06'
]
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
dependencies {
classpath "com.android.tools.build:gradle:$versions.android_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的build.gradle(模块:app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
applicationId "application_id"
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
mavenCentral()
google()
}
dataBinding {
enabled = true
}
}
dependencies {
implementation project(':feature')
implementation project(':base')
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:support-v13:27.0.2'
implementation 'com.github.bumptech.glide:glide:4.5.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
}
我的build.gradle(模块:基础)
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
api 'com.android.support:appcompat-v7:27.0.2'
api 'com.android.support.constraint:constraint-layout:1.0.2'
application project(':app')
feature project(':feature')
}
Build.gradle(模块:功能)
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$versions.kotlin_version"
implementation "org.jetbrains.anko:anko:$versions.anko_version"
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation "com.github.bumptech.glide:glide:$versions.glide_version"
kapt "com.github.bumptech.glide:compiler:$versions.glide_version"
implementation project(':base')
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'
kapt "com.android.databinding:compiler:$versions.android_plugin_version"
}
和Build.Gradle(模块:即时应用)
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':feature')
implementation project(':base')
}
似乎问题是因为在数据绑定自动绑定布局上。
我指的是Android Databinding : package does not exist
和Kapt not generating classes in Instant app feature module
我是否遗漏了build.gradles上的内容?
答案 0 :(得分:3)
我找到了解决方法...... 来自https://issuetracker.google.com/issues/63814741
添加
android.enableExperimentalFeatureDatabinding = true
android.databinding.enableV2=true
gradle.properties
文件中的有点解决了这个问题...但我怀疑这是一个解决方案......但是现在......这就是问题的解决方法
答案 1 :(得分:0)
我最近也遇到了这个问题。将kapt插件添加到应用程序级别的build.gradle文件解决了我的问题。问题是您的gradle文件中已经具有该插件。也许一段时间后问题就解决了,但是我想离开这个答案,因为这个问题首先出现在Google搜索中。
apply plugin: 'kotlin-kapt'