简体   繁体   English

包 android.support.v4.app 不存在; 在安卓工作室 0.8

[英]package android.support.v4.app does not exist ; in Android studio 0.8

I've recently updated the android studio IDE to 0.8 to work with the new android L SDK.我最近将 android studio IDE 更新到 0.8 以使用新的 android L SDK。 To start I imported a finished android project that receives no errors in the older version of android studio.首先,我导入了一个完成的 android 项目,该项目在旧版本的 android studio 中没有收到任何错误。 In version 0.8 i lines such as在 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 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重新安装IDE
  • deleting contents of idea folder删除idea文件夹的内容
  • re installing all the SDK's - including the support libraries重新安装所有 SDK - 包括支持库
  • syncing the gradle同步 gradle
  • copying the support library into the libs folder manually手动将支持库复制到 libs 文件夹中
  • rebuilding the project重建项目
  • as well as creating a new project to test the library以及创建一个新项目来测试库

not entirely sure what's left to do.不完全确定还需要做什么。

Ok, so I had the same problem and found a solution in a udacity forum:好的,所以我遇到了同样的问题,并在 udacity 论坛中找到了解决方案:

In Android Studio:在 Android Studio 中:

  1. Right click on your projects "app" folder and click on -> module settings右键单击您的项目“app”文件夹,然后单击 -> 模块设置
  2. Click on the "dependencies" tab单击“依赖项”选项卡
  3. Click on the + sign to add a new dependency and select "Library Dependency"点击+号添加一个新的依赖并选择“Library Dependency”
  4. Look for the library you need and add it查找您需要的库并添加它

@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 generic compile 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

None of the above solutions worked for me.以上解决方案都不适合我。 What finally worked was:最终奏效的是:

Instead of代替

import android.support.v4.content.FileProvider;

Use this用这个

import androidx.core.content.FileProvider;

This path is updated as of AndroidX (the repackaged Android Support Library).此路径从 AndroidX(重新打包的 Android 支持库)开始更新。

[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 link from 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.确保您已使用 SDK 管理器下载了 Android 支持库。
  • Create a library project and ensure the required JAR files are included in the project's build path:创建一个库项目并确保所需的 JAR 文件包含在项目的构建路径中:

    • Select File > Import .选择文件 > 导入
    • Select E xisting Android Code Into Workspace and click Next.选择Existing Android Code Into Workspace并单击 Next。
    • Browse to the SDK installation directory and then to the Support Library folder.浏览至 SDK 安装目录,然后浏览至 Support Library 文件夹。 For example, if you are adding the appcompat project, browse to /extras/android/support/v7/appcompat/.例如,如果您要添加appcompat项目,请浏览到 /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 .对于 v7 appcompat 项目,您现在应该会看到一个名为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 .在新的库项目中,展开libs/文件夹,右键单击每个 .jar 文件并选择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.例如,在创建 v7 appcompat 项目时,将 android-support-v4.jar 和 android-support-v7-appcompat.jar 文件都添加到构建路径中。
    • Right-click the library project folder and select Build Path > Configure Build Path .右键单击库项目文件夹并选择Build Path > Configure Build Path
    • In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project.Order and Export选项卡中,检查您刚刚添加到构建路径的 .jar 文件,以便它们可用于依赖此库项目的项目。 For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.例如,appcompat 项目要求您同时导出 android-support-v4.jar 和 android-support-v7-appcompat.jar 文件。
    • Uncheck Android Dependencies .取消选中Android 依赖项
    • 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 .Project Explorer中,右键单击您的项目并选择Properties
    • In the category panel on the left side of the dialog, select Android .在对话框左侧的类别面板中,选择Android
    • In the Library pane, click the Add button.窗格中,单击添加按钮。
    • Select the library project and click OK.选择库项目并单击确定。 For example, the appcompat project should be listed as android-support-v7-appcompat.例如,appcompat 项目应列为 android-support-v7-appcompat。
    • In the properties window, click OK.在属性窗口中,单击确定。

Delete删除

/.idea/libraries

Then sync gradle to build project.然后同步 gradle 来构建项目。

// run this commend - its fixed everything // 运行这个命令 - 它修复了一切

ionic cordova plugin add cordova-plugin-androidx-adapter离子cordova插件添加cordova-plugin-androidx-adapter

tl;dr Remove 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.在我们的例子中,我们在一个由每个模块导入的common.gradle文件中将支持库声明为我们所有模块(一个应用程序模块和多个库模块)的依赖项。 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).在每几次同步中,Android Studio 都会选择那个确切的模块作为寻找支持库的地方(这就是为什么它对我们来说似乎是随机发生的)。 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.由于该模块从未使用过,因此它从未构建,这反过来又导致 jar 文件不在模块的中间文件夹中。

Removing this library module from settings.gradle and syncing again fixed the problem for us.settings.gradle删除这个库模块并再次同步为我们解决了这个问题。

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 中的这种依赖关系

在 ECLIPSE LUNA 中,我通过在我的项目中使用 contet 菜单解决了这个问题:ANdroid Tools > Add support Library ...

在我的情况下,通过将字符串cordova.system.library.2=com.android.support:support-v4:+附加到platforms/android/project.properties文件来解决问题

For me the problem was caused by a gradle.properties file in the list of Gradle scripts.对我来说,问题是由 Gradle 脚本列表中的 gradle.properties 文件引起的。 It showed as gradle.properties (global) and refered to a file in C:\users\.gradle\gradle.properties.它显示为 gradle.properties(全局)并引用 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我猜全局文件正在覆盖用于定位包 android.support 的东西

My solution was creating a project with Use legacy support library option checked .我的解决方案是创建一个checked Use legacy support library选项的项目。 after the project creation is successfully completed, just delete the src folder in the app directory and copy the src folder from your main project.项目创建成功后,只需要delete app目录下的src文件夹,从你的主项目中copy src文件夹即可。 Finally, Sync project with Gradle files.最后,将项目与 Gradle 文件Sync

Add this to build.gradle:将此添加到 build.gradle:

allprojects {
    repositories {
        google()
    }
}
dependencies {
    implementation "com.android.support:support-core-utils:28.0.0"
}

*Must have minSdkVersion 14 (or higher) *必须具有 minSdkVersion 14(或更高版本)

If none of these solution worked, you need to jetify your project to fully support AndroidX.如果这些解决方案都不起作用,您需要将您的项目jetify 以完全支持AndroidX。 Try尝试

npm i -D jetifier

then run然后运行

npx jetify

you could find more details here : https://github.com/michalchudziak/react-native-geolocation/issues/39#issuecomment-514566895 ,this should fix the issues.您可以在此处找到更多详细信息: https ://github.com/michalchudziak/react-native-geolocation/issues/39#issuecomment-514566895,这应该可以解决问题。 Let me know if this worked.让我知道这是否有效。

and also make sure to add below in gradle.properties并确保在 gradle.properties 中添加以下内容

android.useAndroidX=true

android.enableJetifier=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM