【问题标题】:package android.support.design.widget does not exist包 android.support.design.widget 不存在
【发布时间】:2020-04-22 18:12:53
【问题描述】:

build.gradle(module:app)

apply plugin: 'com.android.application'

  android {
        compileSdkVersion 29
        buildToolsVersion '29.0.2'

        defaultConfig {
            applicationId "com.example.android.miwok"
            minSdkVersion 15
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        } }


    dependencies {
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.1.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.2.0'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
        'com.android.support:design:28.0.0'
        'com.google.android.material:material:1.0.0-'
        'com.android.support:support-v13:28.0.0'
        'com.android.support:support-annotations:28.0.0'
        'com.android.support:appcompat-v7:28.0.0' }

我的 mainActivity.java

package com.example.android.miwok;


import android.os.Bundle; import
android.support.design.widget.TabLayout;

import androidx.appcompat.app.AppCompatActivity; import
androidx.viewpager.widget.ViewPager;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the content of the activity to use the activity_main.xml layout file
        setContentView(R.layout.activity_main);

        // Find the view pager that will allow the user to swipe between fragments
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);


        // Create an adapter that knows which fragment should be shown on each page
        CategoryAdapter adapter = new CategoryAdapter(this, getSupportFragmentManager());


        // Set the adapter onto the view pager
        viewPager.setAdapter(adapter);

        // Find the tab layout that shows the tabs
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

        // Connect the tab layout with the view pager. This will
        //   1. Update the tab layout when the view pager is swiped
        //   2. Update the view pager when a tab is selected
        //   3. Set the tab layout's tab names with the view pager's adapter's titles
        //      by calling onPageTitle()
        tabLayout.setupWithViewPager(viewPager);
    }
}

【问题讨论】:

  • 尝试描述你的问题和代码
  • 您正在项目中混合Support 库和AndroidX 库。删除support 库并使用AndroidX

标签: android compiler-errors package


【解决方案1】:

在您的代码中,您将Support 库与AndroidX 库混合使用,这是不允许的。删除support 库并使用AndroidX。要正确迁移 AndroidX,请按照以下步骤操作:

来自 Android Studio 菜单

  1. 选择重构->迁移到AndroidX
  2. 进行重构

【讨论】:

  • 您是否从您的build.gradle 中删除了所有support 依赖项?
  • 依赖项 { 实现 'androidx.constraintlayout:constraintlayout:1.1.3' fileTree(dir: 'libs', include: ['*.jar']) 实现 'androidx.appcompat:appcompat:1.1. 0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 'com.google.android.material:material:1.0 .0' 'com.android.support:support-v13:28.0.0' 'com.android.support:support-annotations:28.0.0' 'com.android.support:appcompat-v7:28.0.0' }
  • 删除最后三个也'com.android.support:support-v13:28.0.0' 'com.android.support:support-annotations:28.0.0' 'com.android.support:appcompat-v7:28.0.0'
  • 然后在您的 Java/Kotlin 文件中重新导入所需的依赖项。如果需要布局,您必须手动更改它。
  • 是的,我已经从 build.gradle 中删除了所有支持依赖项
猜你喜欢
  • 2016-06-20
  • 1970-01-01
  • 2020-07-03
  • 2019-11-10
  • 1970-01-01
  • 2015-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多