[英]The import android.support cannot be resolved
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 我从他们的Github下载了代码并导入到Android SDK中,但它在行中显示错误
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. 但是,如果我检查了Android SDK管理器,在Android Support Library
,以及对Android Support Repository
在Extras文件夹都安装。 I can also see the support folder and it's contents in the SDK_INSTALL\\sdk\\extras\\android\\support
directory. 我还可以在SDK_INSTALL\\sdk\\extras\\android\\support
目录中看到support文件夹及其内容。 It also has the v4 folder which also contains the android-support-v4.jar
and the src
folder. 它还有v4文件夹,其中还包含android-support-v4.jar
和src
文件夹。 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. 如果相关,则示例代码适用于RSS阅读器应用程序。
Please follow these Steps: 请按照以下步骤操作:
For Eclipse: 对于Eclipse:
Properties
转到项目的Properties
Java Build Path
导航到Java Build Path
Libraries
tab. 然后转到Libraries
选项卡。 There click the Add External JARs
Button on the Right pane. 单击右窗格上的Add External JARs
按钮。 android-support-v4.jar
file, usually the path for the Jar file is : 选择android-support-v4.jar
文件,通常Jar文件的路径是: android-support-v4.jar
Library, navigate to the Order and Export
tab and put check mark on the android-support-v4
Library file. 添加android-support-v4.jar
库后,导航到Order and Export
选项卡并在android-support-v4
库文件上添加复选标记。 For Android Studio: 对于Android Studio:
Short Version: 精简版:
build.gradle
file: build.gradle
添加到build.gradle
文件中: implementation 'com.android.support:support-v4:YOUR_TARGET_VERSION'
Long Version: 长版:
Go to File -> Project Structure 转到文件 - >项目结构
Go to "Dependencies" Tab -> Click on the Plus sign -> Go to "Library dependency" 转到“依赖关系”选项卡 - >单击加号 - >转到“库依赖关系”
Select the support library "support-v4 (com.android.support:support-v4:YOUR_TARGET_VERSION)" 选择支持库“support-v4(com.android.support:support-v4:YOUR_TARGET_VERSION)”
Navigate to your "build.gradle" inside your App Directory and double check if your desired Android Support Library has been added to your dependencies. 导航到App Directory中的“build.gradle”,然后仔细检查是否已将所需的Android支持库添加到依赖项中。
Rebuild your project and now everything should work. 重建你的项目,现在一切都应该工作。
Further reading regarding this Question: 关于这个问题的进一步阅读
I hope this helps. 我希望这有帮助。
andorid-support-v4.jar is an external jar file that you have to import into your project. andorid-support-v4.jar是一个外部jar文件,您必须将其导入到项目中。
This is how you do it in Android Studio: 这是您在Android Studio中执行此操作的方式:
Go to File -> Project Structure 转到文件 - >项目结构
Go to "Dependencies" Tab -> Click on the Plus sign -> Go to "Library dependency" 转到“依赖关系”选项卡 - >单击加号 - >转到“库依赖关系”
Select the support library "support-v4 (com.android.support:support-v4:23.0.1)" 选择支持库“support-v4(com.android.support:support-v4:23.0.1)”
Now to go your "build.gradle" file in your app and make sure the android support library has been added to your dependencies. 现在去你的应用程序中的“build.gradle”文件,并确保已将android支持库添加到您的依赖项中。 Alternatively, you could've also just typed compile 'com.android.support:support-v4:23.0.1'
directly into your dependencies{}
instead of doing it through the GUI. 或者,您也可以直接将compile 'com.android.support:support-v4:23.0.1'
键入您的dependencies{}
而不是通过GUI执行。
Rebuild your project and now everything should work. 重建你的项目,现在一切都应该工作。
Another way to solve the issue: 解决问题的另一种方法:
If you are using the support library, you need to add the appcompat
lib to the project. 如果您使用的是支持库,则需要将appcompat
lib添加到项目中。 This link shows how to add the support lib to your project. 此链接显示如何将支持lib添加到项目中。
Assuming you have added the support lib earlier but you are getting the mentioned issue, you can follow the steps below to fix that. 假设您之前添加了支持库,但是您收到了上述问题,可以按照以下步骤进行修复。
Right click on the project and navigate to Build Path > Configure Build Path . 右键单击项目并导航到Build Path> Configure Build Path 。
On the left side of the window, select Android . 在窗口左侧,选择Android 。 You will see something like this: 你会看到这样的事情:
appcompat
lib and press OK . 选择appcompat
lib并按OK 。 (Note: The lib will be shown if you have added them as mentioned earlier). (注意:如果您已按前面所述添加了lib,则会显示它)。 Now you will see the following window: 现在您将看到以下窗口: For me they were appearing when i transferred code manually to another laptop. 对我来说,当我手动将代码转移到另一台笔记本电脑时,它们就出现 Just do 做就是了
File>Invalidate Cache/Restart 文件>无效缓存/重新启动
click on 'Invalidate Cache and Restart' and your are done. 单击“使缓存无效并重新启动”,您就完成了。
I followed the instructions above by Gene in Android Studio 1.5.1 but it added this to my build.gradle file: 我在Android Studio 1.5.1中遵循了Gene的上述说明,但是它将它添加到我的build.gradle文件中:
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. 它开始工作了。
This issue may also occur if you have multiple versions of the same support library android-support-v4.jar
. 如果您具有相同支持库android-support-v4.jar
多个版本,也可能会发生此问题。 If your project is using other library projects that contain different-2 versions of the support library. 如果您的项目正在使用包含支持库的不同版本的其他库项目。 To resolve the issue keep the same version of support library at each place. 要解决此问题,请在每个位置保留相同版本的支持库。
This is very easy step to import any 3rd party lib or jar file into your project 这是将任何第三方库或jar文件导入项目的非常简单的步骤
paste copied jar file into lib folder 将复制的jar文件粘贴到lib文件夹中
right click on this jar file and then click on build Path->Add to Build Path 右键单击此jar文件,然后单击构建路径 - >添加到构建路径
even still you are getting error in your project then Clean the Project and Build it. 即使您的项目仍然出现错误,然后清理项目并构建它。
I have resolved it by deleting android-support-v4.jar
from my Project. 我通过从我的项目中删除android-support-v4.jar
来解决它。 Because appcompat_v7
already have a copy of it. 因为appcompat_v7
已经有了它的副本。
If you have already import appcompat_v7 but still the problem doesn't solve. 如果您已导入appcompat_v7但问题仍无法解决。 then try it. 然后尝试一下。
Android Studio 2.2.3 Linux Mint 18.1 Android Studio 2.2.3 Linux Mint 18.1
Inside your 'project view' open Gradle Scripts -> build.gradle(Module:app) and put your mouse pointer inside the word dependencies. 在“项目视图”中打开Gradle Scripts - > build.gradle(Module:app)并将鼠标指针放在单词依赖项中。
Click on the light bulb and click "add library dependency" and for me all the libraries I wanted were listed there. 点击灯泡,然后点击“添加库依赖”,对我来说,我想要的所有库都列在那里。
example libraries that came up for me: compile 'com.android.support:gridlayout-v7:25.1.0' compile 'com.android.support:support-v13:25.1.0' 为我提供的示例库:编译'com.android.support:gridlayout-v7:25.1.0'compile'com.android.support:support-v13:25.1.0'
I am now looking to add android support by default in Gradles default configuration. 我现在希望在Gradles默认配置中默认添加android支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.