错误“包 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
Error "package android.support.v7.app does not exist"
提问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 Add
button 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 Studio
you 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 outandroid.useAndroidX=true
then set it toandroid.useAndroidX=false
Find outandroid.enableJetifier=true
then set it toandroid.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
回答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 然后全部(清理 && 重建)