error: cannot find symbol Build.VERSION_CODES.KITKAT

error: cannot find symbol Build.VERSION_CODES.KITKAT

  
.../platforms/android/app/src/main/java/com/tenforwardconsulting/cordova/BackgroundGeolocationPlugin.java:563: error: cannot find symbol
    @TargetApi(Build.VERSION_CODES.KITKAT)
                                  ^
  symbol:   variable KITKAT
  location: class VERSION_CODES

.../platforms/android/app/src/main/java/com/redskyit/mobile/common/RMCActivity.java:79: error: cannot find symbol
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                                                      ^
  symbol:   variable FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
  location: class LayoutParams

我得到这些 + 100 多个其他类似错误(都找不到符号错误)。

我正在将一个项目迁移到 cordova 8。Cordova 8 对 android 项目进行了相当大的更改,我正在解决由此带来的各种问题。我正处于开始编译的阶段,但因这些错误而失败。

顶层build.gradle看起来像这样

allprojects {
  repositories {
    jcenter()
    maven {
      url "https://maven.google.com"
    }
  }
  //This replaces project.properties w.r.t. build settings
  project.ext {
    defaultBuildToolsVersion="25.0.2" //String
    defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
    defaultTargetSdkVersion=26 //Integer - We ALWAYS target the latest by default
    defaultCompileSdkVersion=26 //Integer - We ALWAYS compile with the latest by default
  }
}

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

app\build.gradle 里面有这些(还有更多)

buildscript {
  repositories {
    mavenCentral()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
  }
}

...

dependencies {
  implementation fileTree(dir: 'libs', include: '*.jar')
  // SUB-PROJECT DEPENDENCIES START
  implementation(project(path: ":CordovaLib"))
  compile "com.google.android.gms:play-services-location:+"
  compile "com.android.support:support-v4:26+"
  compile "com.android.support:support-v4:24.1.1+"
  compile "com.google.gms:google-services:+"
  compile "com.google.android.gms:play-services-tagmanager:+"
  compile "com.google.firebase:firebase-core:+"
  compile "com.google.firebase:firebase-messaging:+"
  compile "com.google.firebase:firebase-crash:+"
  compile "com.google.firebase:firebase-config:+"
  // SUB-PROJECT DEPENDENCIES END
}

我不熟悉 android 工作室项目和 gradle 所以真的不知道从哪里开始寻找。我认为这是一种缺失的依赖性或类似的东西。

尝试 Build > Clean Project,如果不起作用 Build> Rebuild Project,如果也不起作用,请尝试 File > Invalidate Caches & Restart。可能会解决你的问题。

我最终将其追踪到由一个插件定义的一些依赖项,一个我分叉的插件。依赖项是:-

dependencies {
  compile 'com.github.tony19:logback-android-core:1.1.1-6'       
  compile 'com.github.tony19:logback-android-classic:1.1.1-6'        
  compile 'org.slf4j:slf4j-api:1.7.21'
}

解决方法是排除 logback-android-classic 的某些依赖项,如下所示:

dependencies {
  compile 'com.github.tony19:logback-android-core:1.1.1-6'       
  compile('com.github.tony19:logback-android-classic:1.1.1-6') {
    exclude group: 'com.google.android', module: 'android'
  }
  compile 'org.slf4j:slf4j-api:1.7.21'
}