-1

I am using Android studio version 4.0

In Project level gradle :

def supportVersion = "27.1.0"
ext.deps = [
    supportAppCompat   : "com.android.support:appcompat-v7:$supportVersion",
    supportDesign      : "com.android.support:design:$supportVersion",
 
]

Module level gradle :

dependencies {    
implementation deps.supportAppCompat
implementation deps.supportDesign
}

When I import this it occurs an error

error pic

when I import this

import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

Error in xml

error pic

when add this tags in xml an error occurs

<android.support.design.widget.CoordinatorLayout/>
<android.support.design.widget.AppBarLayout/>
<android.support.v7.widget.Toolbar />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton />

give a solution for this!!!

3 Answers3

1

As Of Google Official Document (https://developer.android.com/topic/libraries/support-library/packages)

Note: With the release of Support Library 28.0.0, the android.support-packaged libraries are deprecated and replaced by individually-versioned Jetpack libraries packaged as androidx. The initial 1.0.0 release of the Jetpack libraries provides parity with Support Library 28.0.0 and provides a starting point for migrating to the new androidx packaging.

To fix the error:

"com.android.support:appcompat-v7:$supportVersion"
"com.android.support:design:$supportVersion"

to

def supportVersion = "1.0.0"
ext.deps = [
    supportAppCompat   : "androidx.appcompat:appcompat:$supportVersion",
    supportDesign      : "com.google.android.material:material:$supportVersion",
]

After that either restart Android Studio or Refresh is cache data as- enter image description here

More information on this this thread: Cannot resolve symbol AppCompatActivity - Support v7 libraries aren't recognized?

For forcing android studio to use old library

I check you are using 27.1.0, so we can force android studio not to use androidx

  • Go to gradle.properties

  • make these flags false

    android.useAndroidX=false

    android.enableJetifier=false

Nikhil Sharma
  • 897
  • 1
  • 4
  • 18
  • @Poorvaja if you are using androidx library, make sure you use the following - androidx.coordinatorlayout.widget.CoordinatorLayout , make sure to refresh the android studio cache – Nikhil Sharma Jul 09 '20 at 14:42
0

as you using android studio 4.0

use androidX library instead of Support Library...as latest version uses androidx

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha3', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
}
Wini
  • 1,906
  • 1
  • 12
  • 31
  • add dependencies in build.gradle which i gave in my answer and then sync now..then accordingly import in class and xml – Wini Jul 09 '20 at 07:56
  • use this xml tags `androidx.coordinatorlayout.widget.CoordinatorLayout` instead of `` use and import androidx tags – Wini Jul 09 '20 at 08:15
0

You can migrate your supportAppCompat to the AndroidX library.

In the menu go to Refactor -> Migrate to AndroidX. Then you should reimport androidx in your classes.