简体   繁体   English

Gradle Android无法找到符号上下文

[英]Gradle android cannot find symbol Context

I have a java + kotlin android project that builds and runs fine in Android Studio. 我有一个Java + Kotlin android项目,该项目可以在Android Studio中正常运行。 I am now setting up CI and need to run Gradle from the terminal. 我现在正在设置CI,需要从终端运行Gradle。 But when I run ./gradlew :app:lint I get a lot of errors like this: 但是当我运行./gradlew :app:lint时,我会收到很多这样的错误:

symbol:   class Context
location: class ConnectivityMonitor
e: /*******/LocalAppHistory.java:20: error: cannot find symbol
public boolean hasSeenOnboarding(Context context) {
                                 ^

I get the same type of error for Context, CognitoUserSession, Typeface, CognitoCachingCredentialsProvider... and many more. 对于Context, CognitoUserSession, Typeface, CognitoCachingCredentialsProvider... ,我收到相同类型的错误。 It only applies to the app project and none of the other modules. 它仅适用于app项目,不适用于其他任何模块。

The app gradle.build file: app gradle.build文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
   compileSdkVersion 27
   buildToolsVersion "27.0.3"

   defaultConfig {
       applicationId "****"
       minSdkVersion 21
       targetSdkVersion 27
       versionCode 48
       versionName "1.3.0-dev"
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
       renderscriptTargetApi 18
       renderscriptSupportModeEnabled true
       multiDexEnabled true
   }
   buildTypes {
       release {
           minifyEnabled false
       }
   }

   testOptions {
       unitTests.returnDefaultValues = true
   }
}

dependencies {
   implementation fileTree(include: ['*.jar'], dir: 'libs')
   implementation project(':corentiumio')
   implementation project(':uicomponents')
   implementation project(':core')
   implementation project(':localrepo')
   implementation project(':cloudio')
   implementation('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
       transitive = true
   }
   implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
   implementation 'com.android.support:appcompat-v7:27.1.1'
   implementation 'com.android.support:animated-vector-drawable:27.1.1'
   implementation 'com.android.support:design:27.1.1'
   implementation 'com.android.support:support-v4:27.1.1'
   implementation 'com.android.support.constraint:constraint-layout:1.1.0'
   implementation 'com.amazonaws:aws-android-sdk-core:2.4.2'
   implementation 'com.amazonaws:aws-android-sdk-ddb:2.2.22'
   implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.22'
   implementation 'com.amazonaws:aws-android-sdk-cognito:2.4.2'
   implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.4.2'
   implementation 'com.google.android.gms:play-services-places:15.0.0'
   implementation 'com.google.android.gms:play-services-maps:15.0.0'
   implementation 'com.google.android.gms:play-services-location:15.0.0'
   implementation 'uk.co.chrisjenx:calligraphy:2.3.0'

   testImplementation 'commons-logging:commons-logging:1.2'
   testImplementation 'junit:junit:4.12'
   testImplementation 'org.mockito:mockito-core:2.13.0'
   testImplementation 'org.robolectric:robolectric:3.5.1'
   androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2'
   androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
       exclude group: 'com.android.support', module: 'support-annotations'
   })
   androidTestImplementation('com.android.support.test:runner:0.5') {
       exclude group: 'com.android.support'
   }
   androidTestImplementation('com.android.support.test:rules:0.5') {
       exclude group: 'com.android.support'
   }
   androidTestImplementation('com.android.support.test.espresso:espresso-intents:2.2.2') {
       exclude group: 'com.android.support'
   }
}

I may be wrong, once I got this error while switching git branch from Kotlin Compiler that can't find symbols. 一旦从无法找到符号的Kotlin编译器切换git分支时遇到此错误,我可能是错的。

I did clear cache then it worked, 我确实清除了缓存,然后它起作用了,

rm -rf $HOME/.gradle/caches/

Seems while switching branch previous branch files cached created this issue. 似乎在切换分支时,先前缓存的分支文件会造成此问题。

Give a try if you want. 如果需要,请尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM