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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23330816/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:01:01  来源:igfitidea点击:

Error "package android.support.v7.app does not exist"

androidandroid-support-library

提问by Alexander Otavka

I am new to android development, and I have been using the command line tools to create an android project. I followed all the instructions given in the tutorial at android developers. However, they are focused more on IDE users.

我是android开发新手,一直在使用命令行工具创建android项目。我遵循了android 开发人员教程中给出的所有说明。但是,他们更关注 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. I am truly stumped on this one, and I would really appreciate any help you guys could give me.

我确保访问了 SDK 管理器,它说已安装 Android 支持库。我真的被这个难住了,我真的很感激你们能给我的任何帮助。

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

采纳答案by vgonisanz

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. Push the Addbutton and add the support project "android-support-v7-appcompat"as dependency.

最后,右键单击 Android project > Properties > Android Tab. 按下Add按钮并将支持项目添加"android-support-v7-appcompat"为依赖项。

Clean your project and the must compile and work properly.

清理您的项目,必须编译并正常工作。

回答by Sunil Kumar

First of all check if your project is using androidx or android support library. Check gradle.properties file:

首先检查您的项目是否使用 androidx 或 android 支持库。检查 gradle.properties 文件:

android.useAndroidX=true

android.enableJetifier=true

android.useAndroidX=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;

回答by Jorgesys

Using Android Studioyou have to add the dependency of the support librarythat was not indicated in the tutorial

使用Android Studio你必须添加教程中没有指明的支持库的依赖

dependencies {

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

回答by siva balan

If the issue reported from MainActivity.java then replace

如果从 MainActivity.java 报告问题,则替换

import android.support.v7.app.AppCompatActivity;

with

import androidx.appcompat.app.AppCompatActivity;

回答by Sami

Switching to AndroidX helped me: import androidx.appcompat.app.AppCompatActivity;

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

回答by Muzammil Imran

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
Find out android.useAndroidX=truethen set it to android.useAndroidX=false
Find out android.enableJetifier=truethen set it to android.enableJetifier=false
Rebuild your project, all will working fine.

在项目文件中 gradle.properties
Find outandroid.useAndroidX=true然后将其设置为android.useAndroidX=false
Find outandroid.enableJetifier=true然后将其设置为android.enableJetifier=false
Rebuild your project,一切都会正常工作。

回答by thnee

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 为我解决了这个问题。

回答by gandalf

If your app is AndroidX, This responsemay apply to your problem:

如果您的应用是 AndroidX,此回复可能适用于您的问题:

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

回答by Sreehari Radhakrishnan

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。

回答by Mike Darwish

try to copy C:\Program Files\Java\jdk1.8.0_121 && C:\Program Files\Java\jre1.8.0_121 from other working PC then all (clean && rebuild)

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