Android Studio- java class里使用external tool显示cannot resolve symbol XXX

Android Studio里如果使用其他的dependency,需要在build.gradle -> dependencies -> implementation啥啥啥,表示如果lib里没有 就会在build的时候会自动从网上下载。在build之前class里不论import还是使用都会显示"cannot resolve symbol"。有时候build之后仍然会显示红字错误,找不到包,但是build和run都没问题。这时候试试下面的操作:

Open the Preferences window by clicking File > Settings (on Mac, Android Studio > Preferences).
In the left pane, click Build, Execution, Deployment > Gradle.
Check the Offline work checkbox. (如果新版本android studio没有的话,点Download external annotations for dependencies和其他的checkbox,来回点两下都选上)
Click Apply or OK.

再次build project就会发现External Libraries里面有了dependencies -> implementation里的lib,红字错误就消失了。之前红字是因为build之后没有下载到External Libraries里虽然build正常,具体成因不知道为什么。

你可能感兴趣的:(Android Studio- java class里使用external tool显示cannot resolve symbol XXX)