Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
628 views
in Technique[技术] by (71.8m points)

android - error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath

I can't compile my Android Kotlin project.

I have no idea what is this...

Gradle log:

error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class android.support.v7.app.AppCompatActivity, unresolved supertypes: SupportParentable

build.gradle (app)

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"
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In my case I had a library module with an abstract application class implementing Dagger's HasActivityInjector and an application module with a dependency to the library and its own (non-abstract) application class extending the base app class.

My Gradle dependencies were implementations, and therefore not accessible to the application module's application class (even though there were no imports there, otherwise the issue would be immediately obvious as you'd get a 'could not resolve' error. The fix was to replace dagger implementation dependencies with api, that makes them available to dependant modules as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...