Java 导入android.support无法解析
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18299898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The import android.support cannot be resolved
提问by user13267
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. 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.
在多个文件中。但是,如果我检查了Android SDK管理器中,Android Support Library
以及在Android Support Repository
在都安装文件夹中的附加功能。我还可以看到支持文件夹及其目录中的内容SDK_INSTALL\sdk\extras\android\support
。它还具有 v4 文件夹,其中还包含android-support-v4.jar
和src
文件夹。那么为什么它仍然显示错误,我该如何解决它以及如何运行该示例代码?示例代码适用于 RSS 阅读器应用程序(如果相关)。
采纳答案by Salman Khakwani
Please follow these Steps:
请按照以下步骤操作:
For Eclipse:
对于日食:
- Go to your Project's
Properties
- Navigate to the
Java Build Path
- Then go to the
Libraries
tab. There click theAdd External JARs
Button on the Right pane. - Select the
android-support-v4.jar
file, usually the path for the Jar fileis :
YOUR_DRIVE\android-sdks\extras\android\support\v4\android-support-v4.jar - After adding
android-support-v4.jar
Library, navigate to theOrder and Export
tab and put check mark on theandroid-support-v4
Library file. - After doing the above, Cleanthe Project and Buildit.
- Problem Solved.
- 转到您的项目
Properties
- 导航到
Java Build Path
- 然后转到
Libraries
选项卡。单击Add External JARs
右侧窗格上的按钮。 - 选择
android-support-v4.jar
文件,通常jar文件的路径是:
YOUR_DRIVE\android-sdks\extras\android\support\v4\android-support-v4.jar - 添加
android-support-v4.jar
库后,导航到Order and Export
选项卡并在android-support-v4
库文件上打勾。 - 完成上述操作后,清理项目并构建它。
- 问题解决了。
For Android Studio:
对于安卓工作室:
Short Version:
精简版:
- Add the following line to your
build.gradle
file:implementation 'com.android.support:support-v4:YOUR_TARGET_VERSION'
- 将以下行添加到您的
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)"
Navigate to your "build.gradle" inside your App Directory and double check if your desired Android Support Library has been added to your dependencies.
Rebuild your project and now everything should work.
转到文件 -> 项目结构
转到“依赖项”选项卡 -> 单击加号 -> 转到“库依赖项”
选择支持库“support-v4 (com.android.support:support-v4:YOUR_TARGET_VERSION)”
导航到您的应用程序目录中的“build.gradle”,并仔细检查您想要的 Android 支持库是否已添加到您的依赖项中。
重建您的项目,现在一切正常。
Further reading regarding this Question:
关于这个问题的进一步阅读:
- Support Library - Android Dev
- Recent Support Library Revisions
- Support Library Packages
- What is an Android Support Library?
- How Android Support Library work?
I hope this helps.
我希望这有帮助。
回答by Dexter
Another way to solve the issue:
解决问题的另一种方法:
If you are using the support library, you need to add the appcompat
lib to the project. This linkshows how to add the support lib to your project.
如果您使用的是支持库,则需要将库添加appcompat
到项目中。此链接显示了如何将支持库添加到您的项目中。
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.
On the left side of the window, select Android. You will see something like this:
右键单击项目并导航到Build Path > Configure Build Path。
在窗口左侧,选择Android。你会看到这样的事情:
- You can notice that no library is referenced at the moment. Now click on the Addbutton shown at the bottom-right side. You will see a pop up window as shown below.
- 您可以注意到目前没有引用任何库。现在单击右下角显示的添加按钮。您将看到一个弹出窗口,如下所示。
- 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:
- 选择
appcompat
库并按OK。(注意:如果您如前所述添加了它们,则会显示该库)。现在您将看到以下窗口:
- Press OK. That's it. The lib is now added to your project (notice the red mark) and the errors relating inclusion of support lib must be gone.
- 按确定。就是这样。该库现在已添加到您的项目中(注意红色标记)并且与包含支持库相关的错误必须消失。
回答by Abdul Rizwan
This is very easy step to import any 3rd party lib or jar file into your project
这是将任何 3rd 方 lib 或 jar 文件导入项目的非常简单的步骤
- Copy android-support-v4.jarfile from
your_drive\android-sdks\extras\android\support\v4\android-support-v4.jar
orcopy from your existing project's bin folder.
or any third party .jar file paste copied jarfile into libfolder
right click on this jar file and then click on build Path->Add to Build Path
even still you are getting error in your project then Clean the Project and Build it.
- 复制Android的支持,v4.jar文件从
了Your_Drive \ Android的软件开发工具包\演员\机器人\ SUPPORT \ V4 \ Android的支持,v4.jar
或从现有项目的bin文件夹复制。
或任何第三方 .jar 文件 将复制的jar文件粘贴到lib文件夹中
右键单击这个jar文件,然后单击构建路径->添加到构建路径
即使您仍然在项目中出错,然后清理项目并构建它。
回答by Arun Badole
This issue may also occur if you have multiple versions of the same support library 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.
如果您有多个版本的同一个支持库,也可能会出现此问题android-support-v4.jar
。如果您的项目正在使用包含不同 2 版本支持库的其他库项目。要解决此问题,请在每个位置保持相同版本的支持库。
回答by Jawad Zeb
I have resolved it by deleting android-support-v4.jar
from my Project. Because appcompat_v7
already have a copy of it.
我已经通过android-support-v4.jar
从我的项目中删除来解决它。因为appcompat_v7
已经有副本了。
If you have already import appcompat_v7 but still the problem doesn't solve. then try it.
如果您已经导入了 appcompat_v7 但问题仍然没有解决。然后尝试一下。
回答by Gene
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. 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.
现在转到您的应用程序中的“build.gradle”文件,并确保已将 android 支持库添加到您的依赖项中。或者,您也可以 compile 'com.android.support:support-v4:23.0.1'
直接输入,dependencies{}
而不是通过 GUI 输入。
回答by Wayferer
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.
它开始工作了。
回答by JesseBoyd
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'
为我提供的示例库: compile '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 支持。
回答by Ajji
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.
单击“使缓存无效并重新启动”,您就完成了。