The import android.support cannot be resolved

2019-01-03 23:05发布

I am trying to run the code provided HERE
I downloaded the code from their Github and imported into Android SDK, but it shows error at the lines

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;  

in multiple files. However if I check the Android SDK Manager, the Android Support Library as well as the Android Support Repository in the Extras folder are both installed. I can also see the support folder and it's contents in the SDK_INSTALL\sdk\extras\android\support directory. It also has the v4 folder which also contains the android-support-v4.jar and the src folder. THen why is it still showing the error, how do I resolve it and how do I get that sample code running? THe sample code is for an RSS reader app, if that's relevant.

9条回答
聊天终结者
2楼-- · 2019-01-03 23:28

I have resolved it by deleting android-support-v4.jar from my Project. Because appcompat_v7 already have a copy of it.

If you have already import appcompat_v7 but still the problem doesn't solve. then try it.

查看更多
Animai°情兽
3楼-- · 2019-01-03 23:30

I followed the instructions above by Gene in Android Studio 1.5.1 but it added this to my build.gradle file:

compile 'platforms:android:android-support-v4:23.1.1'

so I changed it to:

compile 'com.android.support:support-v4:23.1.1'

And it started working.

查看更多
Viruses.
4楼-- · 2019-01-03 23:37

Another way to solve the issue.

If you are using support library you need to add the compat lib to the project. This link shows how to add the support lib to your project

Assuming you have added the support lib earlier but you are getting the mentioned issue, you can follow below steps to fix that.

1- Right click on the project and navigate to Build Path->Configure Build Path

2- On left side of the pop up windowd select Android. You will see an image as like this:

enter image description here

3- You can notice that no libaray is referenced at the momonet. Now click on the add button shown at the bottom-right side. You will see a pop up windows as shown below.

enter image description here

4- Select the appcompat lib and press ok. (note: the lib will be shown if you have added them as mentioned earlier). Now you will see the following window.

enter image description here

5- Press ok. Thats it. The lib is added to your project (notice the red mark) and the errors relating inclusion of support lib must go now.

查看更多
登录 后发表回答