1

I am receiving a "can not find symbol" error for dependencies which are already added to the project

The app is running on android studio 3.1, and it compiles and runs normally, as if there are no dependency issues. I tried clearing gradle cache with the cleanBuildCache command, and I also invalidate the cache from File > Invalidate Cache/Restart but to no avail.

Import error in red

The error in question

Support libraries under dependency on the right, but not showing in external libs on the left

external library and dependency

  • What version of Gradle are you using ? You can check that in gradle-wrapper.properties file under distributionUrl. Doesn't it gives you an error that `complie` keyword has been deprecated ? – Syed Ahmed Jamil Jul 01 '19 at 22:16
  • It seems that this is just an IDE not syncing with gradle issue and already been asked here https://stackoverflow.com/questions/20386331/android-studio-and-android-support-v4-app-fragment-cannot-resolve-symbol/33631619 – Syed Ahmed Jamil Jul 01 '19 at 22:24
  • You can also try https://stackoverflow.com/questions/21100688/android-studio-suddenly-cannot-resolve-symbols/21100896#21100896 – Syed Ahmed Jamil Jul 01 '19 at 22:24

2 Answers2

1

Try doing the following:

  • Save your project and close Android Studio
  • DELETE Project Name.iml file from you project directory
  • DELETE app.iml file from your Project Name/app directory
  • DELETE .idea folder from your project directory

Project Name is the name of the project that you set when you first created your project in Android Studio.

Relaunch Android Studio, load your project ,sync gradle and build again.

NOTE: You might have to be connected to internet as it will download the libraries again that were delete when deleting the .idea folder

Also update your gradle verions and use implementation instead of compile as it was deprecated long ago.

Syed Ahmed Jamil
  • 1,881
  • 3
  • 18
  • 34
  • This doesn't work; All the classes the OP is trying to import doesn't have the correct dependency – SnakeException Jul 01 '19 at 23:30
  • See my answer. He's not using AppCompat in the imports in his picture. – SnakeException Jul 02 '19 at 00:14
  • he is using appcompat-v7 which also depends on support-v4 (but he included it anyway) which contains all the classes he is importing. See here the list of classes support-v4 contains https://developer.android.com/reference/android/support/v4/app/package-summary.html. – Syed Ahmed Jamil Jul 02 '19 at 01:10
  • I can tell you don't understand my comment and/or you haven't looked at my answer. Let me clarify. He is missing the `com.android.support:support-compat:26.1.0` dependency and that is what is causing the red import statements in Android Studio. – SnakeException Jul 02 '19 at 01:12
  • The library you mentioned `support-compat:26.1.0` is one part of `support-v4`. In other words including `support-v4` implies that `support-compat:26.1.0` along with all the parts v4 Support Libraries are included. See here https://developer.android.com/topic/libraries/support-library/packages#v4 – Syed Ahmed Jamil Jul 02 '19 at 01:13
  • You are right... But then both our answers still don't work. Using the same support libraries and import statements as the OP I get identical results. – SnakeException Jul 02 '19 at 01:37
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195830/discussion-between-syed-ahmed-jamil-and-divergence). – Syed Ahmed Jamil Jul 02 '19 at 01:44
  • @Divergence check my last message in the chat. I ran your project did some tweaks and it runs now there were some trivial typos. – Syed Ahmed Jamil Jul 02 '19 at 04:31
0

Have you tried Build > Clean Project? Or a good old fashioned restart of Android Studio?

Cameron
  • 1,281
  • 1
  • 19
  • 40