Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imported jar in gradle, compiles, but not recognized by Android Studio (0.2.10)

This is an annoying one. I have a simple project structure which is based on Gradle, very similar to other projects I have. The project has these imports:

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile files('libs/jackson-annotations-2.1.0.jar')
    compile files('libs/jackson-core-2.1.0.jar')
    compile files('libs/jackson-databind-2.1.0.jar')
    compile files('libs/zip4j_1.3.1.jar')
    compile files('libs/httpclient-4.1.3.jar')
    compile files('libs/httpclient-cache-4.1.3.jar')
    compile files('libs/httpcore-4.1.4.jar')
    compile files('libs/httpmime-4.1.3.jar')
    compile project(":grid_lib")
}

Which works well.

The only problem is that the Android Studio does not recognize those classes, so they are all in red and have no intel. Very annoying!

I've been banging my head against the wall for too long, so I'm trying here now. What do you say guys? Any ideas?

Thanks :-)

Edit

I've answered my own questions, for those who find the same problem.

like image 435
daniel.gindi Avatar asked Feb 01 '26 10:02

daniel.gindi


2 Answers

well, to answer my own question...

Sometimes Android Studio's Gradle goes haywire, and I found a simple fix:

  1. Restart Android Studio
  2. Create a new project (doesn't matter where or name)
  3. Wait for it finish downloading its gradle stuff
  4. Restart android studio

For other gradle problems, an additional step may be required, which is copying the gradle wrapper (gradlew files, and gradle folder, not the .gradle folder) from the newly created project to your own project, and re-import your project.

You can now delete the new project... of course.

Edit:

Gradle's version keep changing. If you are still having trouble, try this-

  1. Edit your gradle/wrapper/gradle-wrapper.properties file, and update the distribution url's version. Currently it should be 1.8, but it may change in the future. So you can use a "new project" to find out what the version should be. Example: distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip

  2. Edit your build.gradle file, and change the minimum version to 0.6.+ - and again it may change in the future. Example for current versions: classpath 'com.android.tools.build:gradle:0.6.+'

  3. Restart your Android Studio and recompile.

like image 198
daniel.gindi Avatar answered Feb 03 '26 10:02

daniel.gindi


I encountered the same problem once I tried to upgrade Crashlytics to Fabric which cost me few hours to solve it. I tried cleaning the project and rebuilding it from IDE and Terminal, closed Android Studio and opened it again, synced the gradle, checked out to other git branches and so on. Non of them solved the problem! As a final attempt I closed the project and imported it to Android Studio again and the error was gone!!! I couldn't find any explanation for why it happened but it could be some sort of caching issue on the gradle which was not being cleared in normal ways.

like image 27
Fbarzin Avatar answered Feb 03 '26 11:02

Fbarzin