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

时间:2019-07-15 05:10:18

标签: java android android-studio gradle

我想向我的应用添加操作栏。并且出现了一个问题

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

无论我尝试什么,我都无法解决该问题。互联网上的任何解决方案都不适用于我。我不知道为什么会这样,我真的很累了。我是初学者,这个问题使我发疯。我尝试更改

android.useAndroidX=true->设置为

android.enableJetifier=true->在gradle.properties上为false

是的,它的工作!但是这里出现了另一个问题:

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

这是我的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'

}

我不知道实施方法是否有问题。可能是我在SDK版本上有问题。我曾尝试迁移到AndroidX,但无法正常工作。

5 个答案:

答案 0 :(得分:1)

请尝试以下操作:

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'

答案 1 :(得分:0)

您的项目缺少SDK中的支持库。

如果尚未安装它们,只需右键单击project > Android Tools > Install support library

然后,作为一个android-support-v7-appcompat的Android项目${android-sdk-path}/extras/android/support/v7导入工作区,

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

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

答案 2 :(得分:0)

添加依赖项

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

答案 3 :(得分:0)

欢迎您使用stackoverflow!

您在一个项目中同时具有支持库 androidx 库...这是您的问题...

将支持库更改为首选的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'

}

或者您可以迁移到AndroidX ,并且可以直接在Android Studio中完成

只需转到重构> 迁移到AndroidX > 迁移

添加操作栏

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

我希望这会有所帮助。...

答案 4 :(得分:0)

尝试更换

android.support.v7.widget

androidx.appcompat.widget
相关问题