【问题标题】:error package android.support.design.widget does not exist错误包android.support.design.widget不存在
【发布时间】:2016-06-20 23:57:28
【问题描述】:

当我尝试构建我的 android 项目时,我得到了这个错误

Error:(8, 37) 错误:包 android.support.design.widget 没有 存在错误:(18, 9) 错误: 找不到符号类 TabLayout 错误:(18, 32) 错误: 找不到符号类 TabLayout 错误:(21, 33) 错误: 找不到符号变量 TabLayout 错误:(27, 56) 错误: 包 TabLayout 不存在 错误:(48, 36) 错误: 找不到 符号变量菜单错误:(28, 57) 错误: 包 TabLayout 没有 存在错误:任务执行失败 ':app:compileDebugJavaWithJavac'.

编译失败;有关详细信息,请参阅编译器错误输出。错误:(55, 23) 错误:找不到符号变量 action_settings

这是我的代码

package com.chaos.creativo;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.design.widget.TabLayout;

/**
 * Created by ahmed on 3/7/2016.
 */
public class Signin_up extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signing_up);
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        tabLayout.addTab(tabLayout.newTab().setText("SIGN IN"));
        tabLayout.addTab(tabLayout.newTab().setText("SIGN UP"));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
        final PageAdapter adapter = new PageAdapter(getSupportFragmentManager(), tabLayout.getTabCount());

        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

我的 build.gradle

> apply plugin: 'com.android.application'
> 
> android {
>     compileSdkVersion 23
>     buildToolsVersion "23.0.2"
> 
>     defaultConfig {
>         applicationId "com.chaos.creativo"
>         minSdkVersion 18
>         targetSdkVersion 23
>         versionCode 1
>         versionName "1.0"
>     }
>     buildTypes {
>         release {
>             minifyEnabled false
>             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
>         }
>     } }
> 
> dependencies {
>     compile fileTree(dir: 'libs', include: ['*.jar'])
>     testCompile 'junit:junit:4.12'
>     compile 'com.android.support:appcompat-v7:23.1.1'
>     compile 'com.google.android.gms:play-services-ads:8.4.0'
>     compile 'com.google.android.gms:play-services-identity:8.4.0'
>     compile 'com.firebase:firebase-client-android:2.3.1'
>     compile 'com.google.android.gms:play-services-gcm:8.4.0'
>     compile 'com.android.support:support-v4:23.2'
>     compile 'com.android.support:design:23.2' }

【问题讨论】:

    标签: java android


    【解决方案1】:

    如果您使用的是 android studio,则将以下内容放入 gradle 文件并重新构建。

     compile 'com.android.support:support-v4:23.2.1'
     compile 'com.android.support:design:23.2.1'
    

    如果版本 23.2.1 不支持,请使用 23.1.1

    【讨论】:

    • 您应该更新您的答案以使用 23.2 支持库
    【解决方案2】:

    替换

    implementation 'com.android.support:support-v4:28.0.0'
    

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    

    在你的 build.gradle 中

    【讨论】:

      【解决方案3】:

      我通过添加这个解决了同样的错误:

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

      【讨论】:

        【解决方案4】:

        对于 API 25,这对我有用:

        compile 'com.android.support:support-v4:25.2.0'
        compile 'com.android.support:design:25.2.0'
        

        【讨论】:

          【解决方案5】:

          在 API 26 上有效:

              compile 'com.android.support:support-v4:26.+'
              compile 'com.android.support:design:26.+' 
          

          【讨论】:

            【解决方案6】:

            如果您将 Support 库与 AndroidX 库混合使用,这是不允许的。移除 support 库并使用 AndroidX。要正确迁移 AndroidX,请执行以下步骤: 1.选择重构 -> 迁移到 AndroidX **2.Press Do Refatcor**

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2020-07-03
              • 2015-10-15
              • 2011-10-03
              • 1970-01-01
              • 2019-11-10
              • 2014-10-02
              相关资源
              最近更新 更多