Android Studio androidx.coordinatorlayout error and how to set up 3Dot Menu?

24,704

Solution 1

This will solve your first issue with coordinateLayout

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

Add this dependency to your app.gradle file

And this will also solve your issue with AppBarLayout

As the errors are clearly saying that you do not have the design package,

C:\Users\User\AndroidStudioProjects\BluetoothCar\app\src\main\java\com\car\bluetooth\bluetoothcar\MainActivity.java:11: error: **package android.support.design.widget does not exist**
import android.support.design.widget.AppBarLayout;
C:\Users\User\AndroidStudioProjects\BluetoothCar\app\src\main\java\com\car\bluetooth\bluetoothcar\MainActivity.java:12: error: **package android.support.v7.widget does not exist**
import android.support.v7.widget.Toolbar;

Edit:

Edit this portion

enter image description here

with

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha05'
implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha05'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

There is a duplicate of appcompat and the other dependecies are not looking good with versions.

Solution 2

For androidx use following dependency

dependencies {
    implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
}

Ref - https://developer.android.com/jetpack/androidx/releases/coordinatorlayout

Share:
24,704
BlazeCodeDev
Author by

BlazeCodeDev

Writing Android apps for fun

Updated on May 26, 2020

Comments

  • BlazeCodeDev
    BlazeCodeDev over 2 years

    I have the following problem. My android studio is showing the error, which is alredy written in the title Screenshot. I was trying to implement the nice 3 dot menu in the top right corner. Would be very nice if someone could tell me what the issue is...

    The error im getting when trying to gradle is:

    C:\Users\User\AndroidStudioProjects\BluetoothCar\app\src\main\java\com\car\bluetooth\bluetoothcar\MainActivity.java:11: error: package android.support.design.widget does not exist import android.support.design.widget.AppBarLayout;

    C:\Users\User\AndroidStudioProjects\BluetoothCar\app\src\main\java\com\car\bluetooth\bluetoothcar\MainActivity.java:12: error: package android.support.v7.widget does not exist import android.support.v7.widget.Toolbar;

    I already tried to import the v7.widget.toolbar, but it marks the v7 red and says cant resolve symbol.

    MainActivity.java :

    package com.car.bluetooth.bluetoothcar;
    import android.os.Bundle;
    import com.google.android.material.floatingactionbutton.FloatingActionButton;
    import com.google.android.material.snackbar.Snackbar;
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.appcompat.widget.Toolbar;
    import android.support.design.widget.AppBarLayout;
    import android.support.v7.widget.Toolbar;
    import android.util.Log;
    import android.view.View;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.SeekBar;
    import android.widget.TextView;
    public class MainActivity extends AppCompatActivity {
    //SeekBars
    private SeekBar seekBarGas;
    private TextView textViewGas;
    private SeekBar seekBarSteering;
    private TextView textViewSteering;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        seekBarGas = (SeekBar) findViewById(R.id.seekBarGas);
        textViewGas = (TextView) findViewById(R.id.textViewGas);
        seekBarGas.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                textViewGas.setText(progress + "  /  " + seekBarGas.getMax());
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                seekBarGas.setProgress(0);
            }
        });
        seekBarSteering = (SeekBar) findViewById(R.id.seekBarSteering);
        textViewSteering = (TextView) findViewById(R.id.textViewSteering);
        seekBarSteering.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                textViewSteering.setText(progress + "  /  " + seekBarSteering.getMax());
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                seekBarSteering.setProgress(3);
            }
        });
    }
    }
    

    content_main.xml :

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">
    <SeekBar
        android:id="@+id/seekBarGas"
        android:layout_width="237dp"
        android:layout_height="117dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:max="5"
        android:progress="0"
        android:rotation="-90"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:id="@+id/gas_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="28dp"
        android:layout_marginLeft="28dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:text="Gas"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="@+id/seekBarGas"
        app:layout_constraintTop_toTopOf="parent"
        tools:textColor="@android:color/background_dark" />
    <TextView
        android:id="@+id/textViewGas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/gas_text"
        app:layout_constraintVertical_bias="0.0"
        tools:textColor="@android:color/background_dark" />
    <SeekBar
        android:id="@+id/seekBarSteering"
        android:layout_width="199dp"
        android:layout_height="106dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="4dp"
        android:max="6"
        android:progress="3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent" />
    <TextView
        android:id="@+id/steeringText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="160dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="Lenkung"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.86"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:textColor="@android:color/background_dark" />
    <TextView
        android:id="@+id/textViewSteering"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="88dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.842"
        app:layout_constraintStart_toStartOf="parent"
        tools:textColor="@android:color/background_dark" />
    

    activity_main.xml :

    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>
    <include layout="@layout/content_main" />
    

    AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.car.bluetooth.bluetoothcar">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    

    Build.grade (App)

    apply plugin: 'com.android.application'
    android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.car.bluetooth.bluetoothcar"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    }
    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha05'
    implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha05'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    }
    

    Error:

    * What went wrong:
    Execution failed for task ':app:processDebugResources'.
    > Android resource linking failed
      C:\Users\User\.gradle\caches\transforms-1\files-1.1\appcompat-1.0.0- 
    rc01.aar\f57a72ca523e97bfd49e26fe0ca995bd\res\values-v28\values-v28.xml:9:5- 
       12:13: AAPT: error: resource android:attr/dialogCornerRadius not found.
    

    C:\Users\User\AndroidStudioProjects\BluetoothCar\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: AAPT: error: resource android:attr/dialogCornerRadius not found.

     C:\Users\User\.gradle\caches\transforms-1\files-1.1\material-1.0.0-rc01.aar\5165e838ec45d5f110381d4afe9056c6\res\values\values.xml:161:5-202: AAPT: error: resource android:attr/fontVariationSettings not found.
      C:\Users\User\.gradle\caches\transforms-1\files-1.1\material-1.0.0-rc01.aar\5165e838ec45d5f110381d4afe9056c6\res\values\values.xml:161:5-202: AAPT: error: resource android:attr/ttcIndex not found.
      error: failed linking references.
    
  • BlazeCodeDev
    BlazeCodeDev over 4 years
    Thank you ,my coordinateLayout issue is solved, but I cant import v7.widget, because its marked red as seen here: imgur.com/a/tJ0kR4e It also says cannot resolve symbol.
  • Sana over 4 years
    Welcome :) ! I have edited my answer.Please check it.
  • BlazeCodeDev
    BlazeCodeDev over 4 years
    Sadly still wont work :/ Is it normal, that the toolbar is so small? imgur.com/a/GxhTdaA And I will put my dependencies in the post as well, If this helps
  • Sana over 4 years
    Yes please post if I can help you anyhow.
  • Sana over 4 years
    I also have updated my answer as per your updated question.Please check it.
  • BlazeCodeDev
    BlazeCodeDev over 4 years
    My compile sdk version is now set to 27 and I replaced my dependencies with yours. Now it says Cannot resolve symbol for "AppBarLayout" and "Toolbar" as you can see here imgur.com/a/tlQHU0K . If you wonder why I changed the compile sdk verion... the dependencies said it would not work if its set to 28 as it was. So I changed that one.
  • Sana over 4 years
    Can you please send your full app.gradle file?
  • Sana over 4 years
    Please give 27 to both the targetSdkVersion and compileSdkVersion.Then tell me.I think this time it will run properly.Because targetSdkVersion and compileSdkVersion should have the same version.
  • BlazeCodeDev
    BlazeCodeDev over 4 years
    Still wont work I pasted the error code in the question.
  • Sana over 4 years
    Hey this is working now.Now you don't have issues with depedencies and version.Now it is giving error in other section of your project. i.e, error: resource android:attr/dialogCornerRadius not found.
  • Sana over 4 years
    You have to focus on resource android:attr/dialogCornerRadius.Where have used this attr/dialogCornerRadius,android:attr/ttcIndex & android:attr/fontVariationSettings in your project?
  • BlazeCodeDev
    BlazeCodeDev over 4 years
    I have littelary no idea,but I have to say my toolbar is still not showing. Looks like this imgur.com/a/GxhTdaA
  • BlazeCodeDev
    BlazeCodeDev over 4 years
    Do you have any idea?