Java 包 android.support.v4.app 不存在;在 Android Studio 0.8 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24545576/
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
package android.support.v4.app does not exist ; in Android studio 0.8
提问by user3381665
I've recently updated the android studio IDE to 0.8 to work with the new android L SDK. To start I imported a finished android project that receives no errors in the older version of android studio. In version 0.8 i lines such as
我最近将 android studio IDE 更新到 0.8 以使用新的 android L SDK。首先,我导入了一个完成的 android 项目,该项目在旧版本的 android studio 中没有收到任何错误。在版本 0.8 i 中,例如
import android.support.v4.app.Fragment;
get: Support cannot be resolved causing the rest of the code to have errors. The logcat returns 101 instances of
import android.support.v4.app.Fragment;
get:无法解决支持导致其余代码出错。logcat 返回 101 个实例
Error:(8, 30) error: package android.support.v4.app does not exist
1 for each time I call the support library in an import statement.
1 每次我在导入语句中调用支持库。
I've tried
我试过了
- reinstalling the IDE
- deleting contents of idea folder
- re installing all the SDK's - including the support libraries
- syncing the gradle
- copying the support library into the libs folder manually
- rebuilding the project
- as well as creating a new project to test the library
- 重新安装IDE
- 删除idea文件夹的内容
- 重新安装所有 SDK - 包括支持库
- 同步gradle
- 手动将支持库复制到 libs 文件夹中
- 重建项目
- 以及创建一个新项目来测试库
not entirely sure what's left to do.
不完全确定还有什么要做。
采纳答案by user3799575
[for some reasons this answer is related to Eclipse, NOT Android Studio!]
[出于某些原因,这个答案与 Eclipse 相关,而不是 Android Studio!]
Have you tried setting the support libraries to your class path? This linkfrom the Android Developer's website has some info on how to do that.
您是否尝试将支持库设置为您的类路径?Android 开发人员网站上的此链接提供了有关如何执行此操作的一些信息。
Try following these steps from the website:
尝试从网站执行以下步骤:
Create a library project based on the support library code:
根据支持库代码创建一个库项目:
- Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a library project and ensure the required JAR files are included in the project's build path:
- Select File > Import.
- Select Existing Android Code Into Workspaceand click Next.
- Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompatproject, browse to /extras/android/support/v7/appcompat/.
- Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
- In the new library project, expand the libs/folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
- Right-click the library project folder and select Build Path > Configure Build Path.
- In the Order and Exporttab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
- Uncheck Android Dependencies.
- Click OK to complete the changes.
You now have a library project for your selected Support Library that you can use with one or more application projects.
- Add the library to your application project:
- In the Project Explorer, right-click your project and select Properties.
- In the category panel on the left side of the dialog, select Android.
- In the Librarypane, click the Addbutton.
- Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
- In the properties window, click OK.
- 确保您已使用 SDK 管理器下载了 Android 支持库。
创建一个库项目并确保所需的 JAR 文件包含在项目的构建路径中:
- 选择文件 > 导入。
- 选择Existing Android Code Into Workspace并单击 Next。
- 浏览到 SDK 安装目录,然后浏览到 Support Library 文件夹。例如,如果您要添加appcompat项目,请浏览至 /extras/android/support/v7/appcompat/。
- 单击完成以导入项目。对于 v7 appcompat 项目,您现在应该会看到一个名为android-support-v7-appcompat的新项目。
- 在新的库项目中,展开libs/文件夹,右键单击每个 .jar 文件并选择Build Path > Add to Build Path。例如,在创建 v7 appcompat 项目时,将 android-support-v4.jar 和 android-support-v7-appcompat.jar 文件添加到构建路径。
- 右键单击库项目文件夹并选择Build Path > Configure Build Path。
- 在Order and Export选项卡中,检查您刚刚添加到构建路径的 .jar 文件,以便它们可用于依赖于该库项目的项目。例如,appcompat 项目要求您导出 android-support-v4.jar 和 android-support-v7-appcompat.jar 文件。
- 取消选中Android 依赖项。
- 单击确定以完成更改。
您现在拥有了一个用于所选支持库的库项目,您可以将其与一个或多个应用程序项目一起使用。
- 将库添加到您的应用程序项目:
- 在Project Explorer 中,右键单击您的项目并选择Properties。
- 在对话框左侧的类别面板中,选择Android。
- 在库窗格中,单击添加按钮。
- 选择库项目并单击确定。例如,appcompat 项目应列为 android-support-v7-appcompat。
- 在属性窗口中,单击确定。
回答by Bernhardt Scherer
Ok, so I had the same problem and found a solution in a udacity forum:
好的,所以我遇到了同样的问题,并在 udacity 论坛中找到了解决方案:
In Android Studio:
在 Android Studio 中:
- Right click on your projects "app" folder and click on -> module settings
- Click on the "dependencies" tab
- Click on the + sign to add a new dependency and select "Library Dependency"
- Look for the library you need and add it
- 右键单击您的项目“app”文件夹,然后单击 -> 模块设置
- 单击“依赖项”选项卡
- 单击 + 号添加新的依赖项并选择“库依赖项”
- 查找您需要的库并添加它
回答by colm.anseo
@boernard 's answer solves this from the Android Studio IDE, but if you want to understand what's happening under the covers, it's a simple gradle build file update:
@boernard 的答案从 Android Studio IDE 解决了这个问题,但如果您想了解幕后发生的事情,这是一个简单的 gradle 构建文件更新:
You can edit the build.gradle file from within the IDE (left pane: Gradle Scripts -> build.gradle (Module: app)
) or use the raw path (<proj_dir>/app/build.gradle
)
and add/update the following dependency section:
您可以在 IDE(左窗格:)中编辑 build.gradle 文件Gradle Scripts -> build.gradle (Module: app)
或使用原始路径 ( <proj_dir>/app/build.gradle
) 并添加/更新以下依赖项部分:
dependencies {
//
// IDE setting pulls in the specific version of v4 support you have installed:
//
//compile 'com.android.support:support-v4:21.0.3'
//
// generic directive pulls in any available version of v4 support:
//
compile 'com.android.support:support-v4:+'
}
Using the above genericcompile directive, allows you to ship your code to anyone, provided they have some level of the Android Support Libraries v4
installed.
使用上述通用编译指令,允许您将代码发送给任何人,前提是他们安装了某种级别的代码Android Support Libraries v4
。
回答by AnNik
IN ECLIPSE LUNA I ve resolved this issue by using contet menu on my Project : ANdroid Tools > Add support Library ...
在 ECLIPSE LUNA 我已经通过在我的项目中使用 contet 菜单解决了这个问题:ANdroid Tools > Add support Library ...
回答by ubuntudroid
tl;drRemove all unused modules which have a dependency on the support library from your settings.gradle
.
tl;dr从您的settings.gradle
.
Long version:
长版:
In our case we had declared the support library as a dependency for all of our modules (one app module and multiple library modules) in a common.gradle
file which is imported by every module. However there was one library module which wasn't declared as a dependency for any other module and therefore wasn't build. In every few syncs Android Studio would pick that exact module as the one where to look for the support library (that's why it appeared to happen randomly for us). As this module was never used it never got build which in turn caused the jar file not being in the intermediates folder of the module.
在我们的例子中,我们已经将支持库声明为我们所有模块(一个应用程序模块和多个库模块)在common.gradle
每个模块导入的文件中的依赖项。但是,有一个库模块未声明为任何其他模块的依赖项,因此未构建。在每几次同步中,Android Studio 都会选择那个确切的模块作为寻找支持库的地方(这就是为什么它对我们来说似乎是随机发生的)。由于从未使用过此模块,因此从未构建过,从而导致 jar 文件不在模块的中间文件夹中。
Removing this library module from settings.gradle
and syncing again fixed the problem for us.
删除这个库模块settings.gradle
并再次同步为我们解决了这个问题。
回答by Hyman
In my case the error was on a module of my project.I have resolved this with adding
在我的情况下,错误出在我项目的一个模块上。我通过添加解决了这个问题
dependencies {
implementation 'com.android.support:support-v4:20.0.+'
}
this dependency in gradle of corresponding module
相应模块的 gradle 中的此依赖项
回答by Praveen
Delete
删除
/.idea/libraries
Then sync gradle to build project.
然后同步gradle来构建项目。
回答by dolcom
In my case the problem was solved by appending the string cordova.system.library.2=com.android.support:support-v4:+
to platforms/android/project.properties
file
在我的情况下,问题是通过将字符串附加cordova.system.library.2=com.android.support:support-v4:+
到platforms/android/project.properties
文件来解决的
回答by Paul McCarthy
For me the problem was caused by a gradle.properties file in the list of Gradle scripts. It showed as gradle.properties (global) and refered to a file in C:\users\.gradle\gradle.properties. I right-clicked on it and selected delete from the menu to delete it. It deleted the file from the hard disk and my project now builds and runs. I guess that the global file was overwriting something that was used to locate the package android.support
对我来说,问题是由 Gradle 脚本列表中的 gradle.properties 文件引起的。它显示为 gradle.properties(全局)并引用 C:\users\.gradle\gradle.properties 中的文件。我右键单击它并从菜单中选择删除以将其删除。它从硬盘中删除了文件,我的项目现在可以构建并运行。我猜全局文件正在覆盖用于定位包 android.support 的东西