提问者:小点点

错误:无法解析以下类的超类型。请确保您在类路径中具有所需的依赖项


我无法编译我的Android静态编程语言项目。

我不知道这是什么…

Gradle日志:

错误:无法解析以下类的超类型。请确保您在类路径中具有所需的依赖项:类android.support.v7.app。AppCompatActivity,未解析的超类型:Support家长

build. gradle(应用程序)

buildscript {
    ext.android_plugin_version = "2.3.3"
    ext.kotlin_version = '1.1.2-5'

    repositories {
        maven { url 'https://maven.google.com' }
        maven { url "https://jitpack.io" }

        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:$android_plugin_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        maven { url "https://jitpack.io" }

        mavenCentral()
    }
}

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

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

def compat_version = '26.+'
def play_services_version = '11.0.1'
def firebase_version = '9.6.1'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"

    defaultConfig {
        applicationId "com.site.app"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["library" : "true"]
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    dataBinding {
        enabled true
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

kapt {
    generateStubs = true
    correctErrorTypes = true
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    // android
    compile 'com.android.support:multidex:1.0.1'
    compile "com.android.support:appcompat-v7:${compat_version}"
    compile "com.android.support:design:${compat_version}"
    compile "com.android.support:cardview-v7:${compat_version}"
    compile "com.android.support:recyclerview-v7:${compat_version}"
    compile "com.android.support:gridlayout-v7:${compat_version}"
    compile "com.google.android.gms:play-services:${play_services_version}"
    compile "com.google.android.gms:play-services-ads:${play_services_version}"
    compile "com.google.android.gms:play-services-maps:${play_services_version}"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.maps.android:android-maps-utils:0.4+'
    kapt "com.android.databinding:compiler:$android_plugin_version"

    // kotlin
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}

共3个答案

匿名用户

在我的例子中,我有一个库模块,其中包含一个实现Dagger的HasActivityInjector的抽象应用程序类,以及一个依赖于库的应用程序模块和它自己的(非抽象)应用程序类来扩展基本应用程序类。

我的Gradle依赖项是实现,因此应用程序模块的应用程序类无法访问(即使那里没有导入,否则问题会立即明显,因为你会得到一个“无法解决”的错误。修复方法是用api替换dagger实现依赖项,这使得它们也可用于依赖模块。

匿名用户

我通过更改插件调用的顺序来修复它!

build. gradle

buildscript {
    ext.android_plugin_version = '2.3.3'
    ext.kotlin_version = '1.1.3-2'

    repositories {
        jcenter()
        mavenCentral()

        maven { url "https://maven.google.com" }
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
    }

    dependencies {
        classpath "com.android.tools.build:gradle:$android_plugin_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()

        maven { url "https://maven.google.com" }
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
    }
}

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

app/build. gradle

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

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"

    defaultConfig {
        applicationId "com.sample.app"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        debug {
            ext.alwaysUpdateBuildId = false
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    dataBinding {
        enabled true
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        abortOnError false
        disable 'InvalidPackage'
    }
}

kapt {
    generateStubs = true
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    // kotlin
    kapt "com.android.databinding:compiler:$android_plugin_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    // android
    compile 'com.android.support:multidex:1.0.1'
    compile "com.android.support:appcompat-v7:${compat_version}"
    compile "com.android.support:design:${compat_version}"
    compile "com.android.support:cardview-v7:${compat_version}"
    compile "com.android.support:recyclerview-v7:${compat_version}"
    compile "com.android.support:gridlayout-v7:${compat_version}"
    compile "com.android.support:support-vector-drawable:${compat_version}"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile "com.google.android.gms:play-services-ads:${play_services_version}"
    compile "com.google.android.gms:play-services-maps:${play_services_version}"
    compile "com.google.android.gms:play-services-gcm:${play_services_version}"
    compile 'com.google.maps.android:android-maps-utils:0.4+'

    // fabric
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }

    // logger
    compile 'com.orhanobut:logger:2.1.1'

    // dexter
    compile 'com.karumi:dexter:4.1.0'

    // firebase
    compile "com.google.firebase:firebase-messaging:${firebase_version}"

    // persistence
    compile "android.arch.persistence.room:runtime:1.0.0-alpha3"
    annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha3"

    // facebook
    compile 'com.facebook.android:facebook-android-sdk:4.+'

    // retrofit
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'

    // gson
    compile 'com.google.code.gson:gson:2.8.1'

    // jobs
    compile 'com.evernote:android-job:1.1.11'

    // chart
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'

    // fresco
    compile 'com.facebook.fresco:fresco:1.3.0'

    // indicator
    compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
}

匿名用户

在尝试其他任何东西之前,请尝试:Android Studio-

这对我有用。