简体   繁体   English

如何解决“错误:包 android.support.v7.widget 不存在”的问题?

[英]How to fix "error: package android.support.v7.widget does not exist" problem?

I want to add an Action Bar to my app.我想向我的应用程序添加一个操作栏 And there is a problem appearing并且出现了问题

error: package android.support.v7.widget does not exist . error: package android.support.v7.widget does not exist

I cannot fix that problem whatever i tried.无论我怎么尝试,我都无法解决这个问题。 Any solution on internet does not work on me.I do not know why this is happening and i am really tired of it.互联网上的任何解决方案对我都不起作用。我不知道为什么会这样,我真的厌倦了。 I am the beginner and this problem drives me crazy.I've tried to change我是初学者,这个问题让我发疯。我试图改变

android.useAndroidX=true --> to false android.useAndroidX=true --> 为假

and

android.enableJetifier=true --> false on gradle.properties android.enableJetifier=true --> gradle.properties 上的 false

Yeah, its work!But here is another problem appearing:是的,它的工作!但这里出现了另一个问题:

java.lang.RuntimeException: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91

Here is my build.gradle:这是我的 build.gradle:

    compileSdkVersion 29
    buildToolsVersion '29.0.1'
    minSdkVersion 21
    targetSdkVersion 29


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
    implementation 'com.google.android.material:material:1.1.0-alpha07'
    testİmplementation 'junit:junit:4.13-beta-3'
    androidTestİmplementation 'androidx.test:runner:1.3.0-alpha01'
    androidTestİmplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:support-v13:28.0.0'

}

Could be problem on implementation methods, i do not know.可能是实现方法的问题,我不知道。 May be i have a problem on SDK versions.可能是我在 SDK 版本上有问题。 I have tried migrate to AndroidX and not worked.我试过迁移到 AndroidX 并没有奏效。

Please try this:请试试这个:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

Try replacing尝试更换

android.support.v7.widget

with

androidx.appcompat.widget

Welcome to stackoverflow!欢迎使用 stackoverflow!

You have both support library and androidx library in one project...that's your issue...您在一个项目中同时拥有支持库androidx库……那是您的问题……

Change the support libraries to the preferred AndroidX library...将支持库更改为首选的 AndroidX 库...

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
    implementation 'com.google.android.material:material:1.1.0-alpha07'
    testİmplementation 'junit:junit:4.13-beta-3'
    androidTestİmplementation 'androidx.test:runner:1.3.0-alpha01'
    androidTestİmplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'

}

Or you can probably Migrate to AndroidX and it can be done right in Android Studio或者你可以迁移到 AndroidX ,它可以在 Android Studio 中完成

Simply go to Refactor > Migrate to AndroidX > Migrate只需转到重构>迁移到 AndroidX >迁移

Adding an Action Bar添加操作栏

<androidx.appcompat.widget.Toolbar
   android:id="@+id/toolbar"
   android:layout_width="match_parent"
   android:layout_height="?attr/actionBarSize"
   android:background="@color/yourColor"/>

I hope this helps....我希望这有帮助....

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

If you have not 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. 清理您的项目,必须编译并正常工作。

添加依赖项

implementation 'com.android.support:design:28.0.0'

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

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