简体   繁体   English

错误“包 android.support.v7.app 不存在”

[英]Error "package android.support.v7.app does not exist"

I am new to android development, and I have been using the command line tools to create an android project.我是android开发新手,一直在使用命令行工具创建android项目。 I followed all the instructions given in the tutorial at android developers .我遵循了android 开发人员教程中给出的所有说明。 However, they are focused more on IDE users.但是,他们更关注 IDE 用户。

When I tried extending my MainActivity class from ActionBarActivity instead of just Activity, it threw the following error.当我尝试从 ActionBarActivity 而不是 Activity 扩展我的 MainActivity 类时,它抛出了以下错误。

error: package android.support.v7.app does not exist错误:包 android.support.v7.app 不存在

It was complaining about this import statement.它抱怨这个导入声明。

import android.support.v7.app.ActionBarActivity;

I made sure to visit the SDK manager, and it says Android Support Library is installed.我确保访问了 SDK 管理器,它说已安装 Android 支持库。 I am truly stumped on this one, and I would really appreciate any help you guys could give me.我真的被这个难住了,我真的很感激你们能给我的任何帮助。

This might help: http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html这可能有帮助: http : //developer.android.com/reference/android/support/v7/app/ActionBarActivity.html

First of all check if your project is using androidx or android support library.首先检查您的项目是否使用 androidx 或 android 支持库。 Check gradle.properties file:检查 gradle.properties 文件:

android.useAndroidX=true android.useAndroidX=true

android.enableJetifier=true android.enableJetifier=真

If it contains the above lines, it is using androidx with an old code from some old tutorial.如果它包含以上几行,则它使用的是带有旧教程中的旧代码的 androidx。

In build.gradle (module:app)在 build.gradle (module:app)

Use

implementation 'androidx.appcompat:appcompat:1.0.0'

Instead of代替

compile 'com.android.support:appcompat-v7:28.0.0'

Also in MainActivity.java : Use同样在 MainActivity.java 中:使用

import androidx.appcompat.app.AppCompatActivity;

instead of :代替 :

import android.support.v7.app.AppCompatActivity;

If the issue reported from MainActivity.java then replace如果从 MainActivity.java 报告问题,则替换

import android.support.v7.app.AppCompatActivity;

with

import androidx.appcompat.app.AppCompatActivity;

Your project is missing the support library from the SDK.您的项目缺少 SDK 中的支持库。

If you have no installed them, just right click on the project > Android Tools > Install support library .如果您还没有安装它们,只需右键单击project > Android Tools > Install support library

Then, just import into workspace, as an Android project, android-support-v7-appcompat , located into ${android-sdk-path}/extras/android/support/v7然后,只需导入到工作区,作为一个 Android 项目, android-support-v7-appcompat ,位于${android-sdk-path}/extras/android/support/v7

And finally, right click in the Android project > Properties > Android Tab .最后,右键单击 Android project > Properties > Android Tab Push the Add button and add the support project "android-support-v7-appcompat" as dependency.Add按钮并添加支持项目"android-support-v7-appcompat"作为依赖项。

Clean your project and the must compile and work properly.清理您的项目,必须编译并正常工作。

Using Android Studio you have to add the dependency of the support library that was not indicated in the tutorial使用Android Studio你必须添加教程中没有指出的支持库的依赖

dependencies {

    implementation 'com.android.support:appcompat-v7:22.0.0'
}

If you are using latest Android Studio, then v7 libraries contradict with AndroidX, only you have to do is:如果您使用的是最新的 Android Studio,那么 v7 库与 AndroidX 相矛盾,您只需要做的是:

In Project files go in gradle.properties在项目文件中进入 gradle.properties
Find out android.useAndroidX=true then set it to android.useAndroidX=false找出android.useAndroidX=true然后将其设置为android.useAndroidX=false
Find out android.enableJetifier=true then set it to android.enableJetifier=false找出android.enableJetifier=true然后将其设置为android.enableJetifier=false
Rebuild your project, all will working fine.重建你的项目,一切都会正常的。

切换到 AndroidX 对我有帮助: import androidx.appcompat.app.AppCompatActivity;

For what it's worth:物有所值:

I ran in to this issue when using Xamarin, even though I did have the Support packages installed, both the v4 and the v7 ones.我在使用 Xamarin 时遇到了这个问题,即使我确实安装了 v4 和 v7 的支持包。

It was resolved for me by doing Build -> Clean All.通过执行 Build -> Clean All 为我解决了这个问题。

For those who migrated to androidx, here is a list of mappings to new packages: https://developer.android.com/jetpack/androidx/migrate#class_mappings对于迁移到 androidx 的用户,这里是新包的映射列表: https : //developer.android.com/jetpack/androidx/migrate#class_mappings

Use implementation 'androidx.appcompat:appcompat:1.0.0'使用implementation 'androidx.appcompat:appcompat:1.0.0'

Instead support library implementation 'com.android.support:appcompat-v7:28.0.0'而是支持库implementation 'com.android.support:appcompat-v7:28.0.0'

First of all check if your project is using androidx or android support library. 首先检查您的项目是否使用androidx或android支持库。 Check gradle.properties file: 检查gradle.properties文件:

android.useAndroidX=true
android.enableJetifier=true

If it contains the above lines, it is using androidx with an old code from some old tutorial. 如果包含以上几行,则说明它是将androidx与旧教程中的旧代码一起使用。

In build.gradle (module:app) 在build.gradle(module:app)中

Use 采用

implementation 'androidx.appcompat:appcompat:1.0.0'

Instead of 代替

compile 'com.android.support:appcompat-v7:28.0.0'

Also in MainActivity.java : Use 同样在MainActivity.java中:使用

import androidx.appcompat.app.AppCompatActivity;

instead of : 代替 :

import android.support.v7.app.AppCompatActivity;

(It works for me)Thanks for sharing. (对我有用)感谢分享。

If your app is AndroidX, This response may apply to your problem:如果您的应用是 AndroidX,此回复可能适用于您的问题:

npm install --save-dev jetifier
npx jetify (may take a while)
npx react-native run-android

尝试从其他工作 PC 复制 C:\\Program Files\\Java\\jdk1.8.0_121 && C:\\Program Files\\Java\\jre1.8.0_121 然后全部(清理 && 重建)

If you are using SDK 28 or higher, you need to migrate to AndroidX library.如果您使用的是 SDK 28 或更高版本,则需要迁移到 AndroidX 库。

With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.对于 Android Studio 3.2 及更高版本,您可以通过从菜单栏中选择 Refactor > Migrate to AndroidX 将现有项目迁移到 AndroidX。

For AndroidX implement following lib in gridle对于 AndroidX 在 gridle 中实现以下库

implementation 'androidx.palette:palette:1.0.0'

and import following class in activity -并在活动中导入以下课程 -

import androidx.palette.graphics.Palette;

for more info see class and mapping for AndroidX https://developer.android.com/jetpack/androidx/migrate/artifact-mappings https://developer.android.com/jetpack/androidx/migrate/class-mappings有关更多信息,请参阅 AndroidX 的类和映射https://developer.android.com/jetpack/androidx/migrate/artifact-mappings https://developer.android.com/jetpack/androidx/migrate/class-mappings

I'm a beginner but what I did for my code to work was to import androidx hence replacing the android.v7 then I erased the support.v7 line and my code worked.我是初学者,但我为我的代码所做的工作是导入 androidx 因此替换了 android.v7 然后我删除了 support.v7 行并且我的代码工作。 I'm sorry I couldn't explain in more technical terms but that's what worked for me.很抱歉,我无法用更多技术术语来解释,但这对我有用。 Actually the Java codes were codes I copied from an old tutorial hence the error encountered.实际上,Java 代码是我从旧教程中复制的代码,因此遇到了错误。 Hope this helps.希望这可以帮助。

I just got this error today and this is how I fixed.我今天刚收到这个错误,这就是我修复的方法。

  • On my build output, I double click on the class with the error.在我的构建输出中,我双击出现错误的类。
  • After the class opened, I expanded the imports section and deleted existing imports with errors.课程打开后,我扩展了导入部分并删除了存在错误的现有导入。
  • I then hovered my mouse near the errors which were:RecyclerView,LinearLayoutManager, and FragmentTransaction and chose Alt+Enter to import appropriate classes.然后我将鼠标悬停在以下错误附近:RecyclerView、LinearLayoutManager 和 FragmentTransaction 并选择 Alt+Enter 以导入适当的类。

Note : in my case, the error occured after I migrated one of my old projects to androidx and so imports hard to be androidx related.注意:就我而言,错误发生在我将一个旧项目迁移到 androidx 后,因此导入很难与 androidx 相关。 I am using android studio.我正在使用安卓工作室。

Note: You may run into other issues, so everytime I run into an error, I check other called classes and makes sure their imports are correct.注意:您可能会遇到其他问题,因此每次遇到错误时,我都会检查其他被调用的类并确保它们的导入是正确的。 What I do mostly is press ctrl+shift+R, and put the old import in the first field and the correct import on the second field and then replace all.我所做的主要是按 ctrl+shift+R,然后将旧的导入放在第一个字段中,将正确的导入放在第二个字段中,然后全部替换。 This way, I replace all imports that in the project at once.这样,我一次替换了项目中的所有导入。

You can use ctrl+shift+f to find where imports are used.您可以使用 ctrl+shift+f 来查找使用导入的位置。

It is 2020 December.现在是 2020 年 12 月。 The same problem came to me in a different way.同样的问题以不同的方式出现在我身上。 When I was going to Deploy in google play store, it said I have to create the bundle higher than android v28 and I updated my projects Compile using Android Version 30 (in Xamarin Android project properties).当我打算在 google play 商店中进行部署时,它说我必须创建高于 android v28 的包,并且我使用 Android 版本 30(在 Xamarin Android 项目属性中)更新了我的项目编译。 It was not possible to do it with the same error (Android support library has no support for V7).不可能用同样的错误来做(Android 支持库不支持 V7)。 I tried everything mentioned above and was not working and here is what worked for me.我尝试了上面提到的所有内容,但没有奏效,这对我有用。 I was using this in splashactivity.cs我在 splashactivity.cs 中使用它

using Android.Support.V7.App;

And it is the one giving the trouble and i changed it into V4它是一个给我带来麻烦的人,我把它改成了 V4

using Android.Support.V4.App;

then AppCompatActivity was underlined red and I had to get androidx appcompat app as follows然后 AppCompatActivity 下划线为红色,我必须按如下方式获取 androidx appcompat 应用程序

using AndroidX.AppCompat.App;

Now it is working and it may help someone else too.现在它正在工作,它也可以帮助其他人。

If you have a problem with dependencies when download a new version, try...如果您在下载新版本时遇到依赖项问题,请尝试...

FILE....MANAGE IDE SETTINGS...RESTORE DEFAULT SETTINGS文件....管理IDE设置...恢复默认设置

重建项目问题解决后..

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

相关问题 错误:包 android.support.v7.app 不存在 - error: package android.support.v7.app does not exist 错误:包 android.support.v7.app 不存在 问题 - error: package android.support.v7.app does not exist Problem androidStudio 中的“包 android.support.v7.app 不存在”错误 - "package android.support.v7.app does not exist" error in androidStudio 错误:迁移到 android x 后包 android.support.v7.app 不存在 - error: package android.support.v7.app does not exist after migrating to android x 错误:包android.support.v7.app不存在[ANDROID STUDIO] - Error: package android.support.v7.app does not exist [ANDROID STUDIO] 反应原生错误包android.support.v7.app不存在 - react native error package android.support.v7.app does not exist 无法导入包 android.support.v7.app(错误:不存在) - Can't import package android.support.v7.app (error: does not exist) 获取错误:包 android.support.v7.app 不存在 import android.support.v7.app.ActionBar - Getting error: package android.support.v7.app does not exist import android.support.v7.app.ActionBar 生成Project时,:app:compileDebugJava错误。 它显示错误:包android.support.v7.app不存在 - While building Project, error in :app:compileDebugJava. It says error: package android.support.v7.app does not exist 在gradle中声明android.support.v7.app - declaring android.support.v7.app in gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM