我正在尝试将我的项目更新为使用Android Studio 3.0 Beta 2,而且我的Kotlin扩展功能出现错误。我有一个模块sdk
,其中包含一些提供扩展功能的Kotlin文件,例如:
fun Context.hasPermission(permission: String): Boolean =
ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
我在其他2个模块中使用此功能,我已将其从compile project(':sdk')
更改为implementation project(':sdk')
。当我现在编译时,我得到错误:
Unresolved error: hasPermission
在更新以跨模块获取这些扩展功能时,我还应该做些什么吗?
更新
我将函数签名更改为不再是扩展函数,而是看起来像:
fun hasPermission(context: Context, permission: String): Boolean
ContextCompat.checkSelftPermission(context, permission) == PackageManager.PERMISSION_GRANTED
我仍然得到相同的错误,如果我把它包装在一个类或它运行的对象中。
object ContextUtils {
fun hasPermission(context: Context, permission: String): Boolean
ContextCompat.checkSelftPermission(context, permission) == PackageManager.PERMISSION_GRANTED
}
更新
我使用--info --stacktrace
标记运行构建,这里有输出(还有更多,但这似乎是相关部分):
:sdk:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug (Thread[Daemon worker,5,main]) completed. Took 0.231 secs.
:experience:dataBindingExportBuildInfoDebug (Thread[Daemon worker,5,main]) started.
:experience:dataBindingExportBuildInfoDebug
Putting task artifact state for task ':experience:dataBindingExportBuildInfoDebug' into context took 0.002 secs.
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/java', not found
Executing task ':experience:dataBindingExportBuildInfoDebug' (up-to-date check took 0.024 secs) due to:
Output property 'output' file /home/yperess/workspace/Metaverse/experience/build/generated/source/dataBinding/debug has changed.
Output property 'output' file /home/yperess/workspace/Metaverse/experience/build/generated/source/dataBinding/debug/android has been removed.
Output property 'output' file /home/yperess/workspace/Metaverse/experience/build/generated/source/dataBinding/debug/android/databinding has been removed.
All input files are considered out-of-date for incremental task ':experience:dataBindingExportBuildInfoDebug'.
:experience:dataBindingExportBuildInfoDebug (Thread[Daemon worker,5,main]) completed. Took 0.033 secs.
:experience:kaptGenerateStubsDebugKotlin (Thread[Task worker for ':',5,main]) started.
:experience:kaptGenerateStubsDebugKotlin
Putting task artifact state for task ':experience:kaptGenerateStubsDebugKotlin' into context took 0.0 secs.
Executing task ':experience:kaptGenerateStubsDebugKotlin' (up-to-date check took 0.009 secs) due to:
Output property 'destinationDir' file /home/yperess/workspace/Metaverse/experience/build/tmp/kapt3/incrementalData/debug has changed.
Output property 'destinationDir' file /home/yperess/workspace/Metaverse/experience/build/tmp/kapt3/incrementalData/debug/com has been removed.
Output property 'destinationDir' file /home/yperess/workspace/Metaverse/experience/build/tmp/kapt3/incrementalData/debug/com/gometa has been removed.
All input files are considered out-of-date for incremental task ':experience:kaptGenerateStubsDebugKotlin'.
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
Using kotlin incremental compilation
:experience:kaptGenerateStubsDebugKotlin (Thread[Task worker for ':',5,main]) completed. Took 3.386 secs.
:experience:kaptDebugKotlin (Thread[Task worker for ':' Thread 3,5,main]) started.
:experience:kaptDebugKotlin
Putting task artifact state for task ':experience:kaptDebugKotlin' into context took 0.0 secs.
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
Executing task ':experience:kaptDebugKotlin' (up-to-date check took 0.012 secs) due to:
Output property 'destinationDir' file /home/yperess/workspace/Metaverse/experience/build/generated/source/kapt/debug/com has been removed.
Output property 'destinationDir' file /home/yperess/workspace/Metaverse/experience/build/generated/source/kapt/debug/com/gometa has been removed.
Output property 'destinationDir' file /home/yperess/workspace/Metaverse/experience/build/generated/source/kapt/debug/com/gometa/metaverse has been removed.
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
w: warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.lifecycle.LifecycleProcessor' less than -source '1.8'
w:
:experience:kaptDebugKotlin (Thread[Task worker for ':' Thread 3,5,main]) completed. Took 3.489 secs.
:experience:compileDebugKotlin (Thread[Task worker for ':' Thread 3,5,main]) started.
:experience:compileDebugKotlin
Putting task artifact state for task ':experience:compileDebugKotlin' into context took 0.001 secs.
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
Executing task ':experience:compileDebugKotlin' (up-to-date check took 0.035 secs) due to:
Task.upToDateWhen is false.
All input files are considered out-of-date for incremental task ':experience:compileDebugKotlin'.
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
file or directory '/home/yperess/workspace/Metaverse/experience/src/debug/kotlin', not found
Using kotlin incremental compilation
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class com.gometa.metaverse.sdk.utils.MediaUploader, unresolved supertypes: com.amazonaws.mobileconnectors.s3.transferutility.TransferListener
e: /home/yperess/workspace/Metaverse/experience/src/main/java/com/gometa/metaverse/experience/camera/CameraSceneViewModel.kt: (15, 39): Unresolved reference: toFile
e: /home/yperess/workspace/Metaverse/experience/src/main/java/com/gometa/metaverse/experience/camera/CameraSceneViewModel.kt: (47, 77): Unresolved reference: toFile
e: /home/yperess/workspace/Metaverse/experience/src/main/java/com/gometa/metaverse/experience/character/CharacterSceneViewModel.kt: (15, 39): Unresolved reference: toFile
e: /home/yperess/workspace/Metaverse/experience/src/main/java/com/gometa/metaverse/experience/character/CharacterSceneViewModel.kt: (41, 58): Unresolved reference: toFile
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/RotationMatrix.kt: (15, 39): Unresolved reference: toString
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/RotationMatrix.kt: (161, 107): Too many arguments for public open fun toString(): String defined in kotlin.Float
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/LightLoginActivity.kt: (24, 40): Unresolved reference: hasPermission
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/LightLoginActivity.kt: (437, 36): Unresolved reference: hasPermission
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/LightLoginActivity.kt: (438, 38): Unresolved reference: hasPermission
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/component/LoginChoice.kt: (10, 34): Unresolved reference: ankoComponent
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/component/LoginChoice.kt: (30, 9): Unresolved reference: ankoComponent
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/component/LoginChoice.kt: (30, 38): Unresolved reference: it
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (9, 32): Unresolved reference: textInputEditText
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (18, 5): Unresolved reference: textInputEditText
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (19, 9): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public var TextView.hintResource: Int defined in org.jetbrains.anko
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (20, 9): Unresolved reference: inputType
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (21, 9): Unresolved reference: maxLines
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (22, 9): Unresolved reference: filters
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (23, 9): Unresolved reference: addTextChangedListener
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (34, 13): Unresolved reference: textInputEditText
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (35, 17): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public var TextView.hintResource: Int defined in org.jetbrains.anko
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (36, 17): Unresolved reference: inputType
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (37, 17): Unresolved reference: maxLines
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/login/util/Layouts.kt: (38, 17): Unresolved reference: addTextChangedListener
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/view/CameraControlView.kt: (32, 39): Unresolved reference: clamp
e: /home/yperess/workspace/Metaverse/experience/src/main/kotlin/com/gometa/metaverse/experience/view/CameraControlView.kt: (305, 26): Unresolved reference: clamp
[KOTLIN] deleting /home/yperess/workspace/Metaverse/experience/build/tmp/kotlin-classes/debug on error
[KOTLIN] deleting /home/yperess/workspace/Metaverse/experience/build/tmp/kotlin-classes/debug on error
:experience:compileDebugKotlin FAILED
:experience:compileDebugKotlin (Thread[Task worker for ':' Thread 3,5,main]) completed. Took 8.489 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':experience:compileDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':experience:compileDebugKotlin'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:8)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:326)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:300)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:203)
at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:182)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 27 more
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 55s
88 actionable tasks: 88 executed
更新
删除testCoverageEnabled = true
修复了缺少的全局函数的问题。现在我刚刚离开亚马逊S3的错误,我认为这个错误属于另一个问题。
答案 0 :(得分:0)
正如@hotkey在评论中提到的那样,使用testCoverageEnabled
导致此问题存在一个错误,将其关闭修复了丢失的函数问题。