Android Studio inline compiler showing red errors,

2019-01-21 07:23发布

I've set up my project in Android Studio to use the Square Wire library, as per this question.

Build -> Compile Project works fine.

2:03:10 PM Compilation completed successfully in 31 sec

However, if I open one of my generated Protocol Buffer files, then the Square package is not being recognized.

Android Studio inline compile errors

Another symptom is that methods inherited from the Square Message class are showing as "Cannot resolve method" compile errors in the editor, even though they build and run fine.

Android Studio single line compile error

Do I need to do something more than just adding the dependency in build.gradle for my module in my project?

17条回答
成全新的幸福
2楼-- · 2019-01-21 07:39

In my case, for some reason, Android Plugin Version wasn't set. I did try clearing cache and removing .gradle and .idea as well, but it didn't work out and after finally wandering for hours, I found this.

File > Project Structure

查看更多
淡お忘
3楼-- · 2019-01-21 07:40

For me deleting .gradle and .idea folder of project solved the problem.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-21 07:40

If all above answers don't work for you. Just try update your dependencies to latest version. It worked for me.

查看更多
forever°为你锁心
5楼-- · 2019-01-21 07:45

My hacky fix for this -

  1. Open your build.gradle file
  2. Cut out everything inside dependencies{}
  3. Paste in notepad for super safe temporary keeping
  4. Choose 'Sync Now' in the build.gradle file
  5. Wait for Sync to fail
  6. Paste your dependencies back in
  7. 'Sync Now' again

Tried a lot of solutions and this was the only fix for me.

查看更多
够拽才男人
6楼-- · 2019-01-21 07:52

1) Click on the gradle icon (right side on the android studio)

enter image description here

2) Click on the refresh button and wait for the issue to be resolved :D

enter image description here

查看更多
别忘想泡老子
7楼-- · 2019-01-21 07:55

The following steps helps

  1. Close your project, and in your project folder delete project/.idea
  2. Delete ~/.gradle folder.

Open the project again. Everything should be solved.

查看更多
登录 后发表回答