简体   繁体   中英

Android Studio cannot find classes after upgrading version of dependency

I have two projects: library and app. I have previously uploaded library to jCentre, and library is listed as an external dependency of app in its build.gradle file. Recently I published a newer version of library and updated the dependency version code in app's build.gradle file, but when I did this Android Studio could no longer find any of the classes from library.

To test the library, I created an entirely new project and added library as a dependency. In this scenario Android Studio finds the classes just fine. I've compared every line of the build.gradle files: They have the same min and target SDK version, they have the same proguard config, they're literally identical. They projects are also using the exact same version of the android plugin and the exact same gradle version.

I also tried entirely deleting app from my machine and re-checked it out from git. This did not solve the problem. I've tried all the usual steps of cleaning the project and rebuilding the project, deleting all build files, invalidating caches, etc.

So can anyone tell me why Android Studio cannot find any of the library classes after upgrading the dependency version?

Here is the gradle.build file in the new test project:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 24
        versionCode 11
        versionName "3.1.0"
    }

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

dependencies {
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.matthew-tamlin:android-utilities:2.1.0' // this is library
}

Here's the build.gradle file in the app project:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 24
    }

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

dependencies {
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.matthew-tamlin:android-utilities:2.1.0' // this is library
}

You can see that they're virtually identical, so why can one project find the classes from the library but the other cannot?

So I never discovered why this is an issue, but I found a workaround. I created a new project in Android Studio and copied all the src directories and build.gradle files from the existing project. I also copied the hidden git folder and all git ignore files. I didn't copy the gradle wrapper, the gradle file or the generated builds. I don't know why this fixed the problem, it must be a bug in gradle or Android Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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