【问题标题】:Android Studio cannot resolve symbol 'TabLayout'Android Studio 无法解析符号“TabLayout”
【发布时间】:2015-12-17 15:04:20
【问题描述】:

无法解析符号 TabLayout ?如何清除此错误?请帮我。我已经导入 import android.support.design.widget.TabLayout;

【问题讨论】:

  • 重启你的机器

标签: android android-fragments android-studio importerror android-tablayout


【解决方案1】:

有一个类似的问题,为了在 Android Studio (AS) 中解决这个问题,我去了 Build->Clean Project 和 AS 整理了所有内容。确保在您拥有的依赖项下的 build.gradle 文件中:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:your_api_version_number.0.0'
    compile 'com.android.support:design:+'
}

【讨论】:

    【解决方案2】:

    我通过添加以下两行手动解决了这个问题:

    implementation 'com.android.support:support-v4:22.2.0'
    implementation 'com.android.support:design:22.2.0'
    

    \app\build.gradle 中的dependencies 下为我工作。

    注意:您的所有支持库必须是相同的版本,即 appcompat-v7 和 support-v4 到相同的版本,例如23.0.1;否则你会得到这个错误

    java.lang.NoClassDefFoundError: android.support.v7.internal.widget.TintManager` 代码构建后

    【讨论】:

      【解决方案3】:

      在 Gradle 脚本下, 打开build.gradle(模块:app)

      依赖项内添加

      compile 'com.android.support:design:25.3.1'
      

      可能有更新版本的库可用,android studio lint 检查可能会检测到。

      完整的依赖项区域可能如下所示以供参考。上面一行是我手动添加的唯一一行。

      dependencies {
          compile fileTree(dir: 'libs', include: ['*.jar'])
          androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
              exclude group: 'com.android.support', module: 'support-annotations'
          })
          compile 'com.android.support:appcompat-v7:25.3.1'
          compile 'com.android.support.constraint:constraint-layout:1.0.2'
          testCompile 'junit:junit:4.12'
          compile 'com.android.support:design:25.3.1'
      }
      

      上面的答案建议添加

      compile 'com.android.support:design:+'
      

      这有点危险,因为它总是使用最新的库,您可能无法通过在后台发生的自动库更新来隔离错误。

      【讨论】:

      • 谢谢!我也想知道com.android.support:design:+
      【解决方案4】:

      Android Studio 不再使用“编译”,而是使用“实现”。 当你去 Build Gradle>dependencies{ 时一定要包含下面的代码

      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.android.support:appcompat-v7:27.1.1'
      implementation 'com.android.support:support-v4:27.1.1'
      implementation 'com.android.support:design:27.1.1'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'com.android.support.test:runner:1.0.1'
      androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
      

      }

      【讨论】:

        【解决方案5】:

        我通过 Open build.gradle (Module: app) 解决它并添加

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

        【讨论】:

          【解决方案6】:

          对于 Android API Level 29+,在 build.gradle (Module:app) 中添加以下依赖项:

          dependencies {
              implementation 'com.google.android.material:material:1.0.0'
          }
          

          如果有更新版本可用,Android Studio 会提示您使用最新版本。

          【讨论】:

            猜你喜欢
            • 2018-05-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-11-15
            • 1970-01-01
            • 2015-08-22
            • 2017-04-20
            相关资源
            最近更新 更多