0

I am working on a face recognition app using google API. But android studio says symbol not found.

Here is my activity. All four of them don't work.

import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;

My build.gradle(module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "ece.course.myapplication"
        minSdkVersion 19
        targetSdkVersion 26
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion "28.0.3"
    productFlavors{
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:mediarouter-v7:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.android.support:design:28.0.0'
    //implementation 'com.android.support:support-annotations:28.0.0'
    //compile 'com.android.support:support-v4:24.2.0'
    //compile 'com.android.support:design:24.2.0'
    //compile 'com.google.android.gms:play-services-vision:9.4.0+'
}

My build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        //classpath 'com.android.tools.build:gradle:2.1.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I am new to android and confused. I cleaned the project and rebuild it several times. Invalidate cache and restart several times.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
WenxuNiu
  • 1
  • 3

3 Answers3

0

Yes Because you have to migrate your project into the androidx.

You are using compileSdkVersion 28

Steps to migrate

  1. Add the following properties to gradle.properties

    android.useAndroidX=true

    android.enableJetifier=true

    1. From the menu bar: Refactor > Migrate to AndroidX…

Here is the reference for whole process.

Sunny
  • 3,134
  • 1
  • 17
  • 31
0

You need to Migrate your project to androidx

Refactor > Migrate to Androidx

Another thing to remember is to check all your packages are correct in gradle. The Snackbar package for androidx is:

com.google.android.material.snackbar.Snackbar

Answered here: Snackbar package in AndroidX

For Androidx artifact mapping. Take a look at the Android Developer API here: https://developer.android.com/jetpack/androidx/migrate/artifact-mappings

Sample: Artifact Mapping Sample

0

Thanks everyone for the answers.

As it turns out, during project setup time I used the "basic activity" as a template for fast setup. But I later realized in the "basic activity" in newer version of Android Studio uses AndroidX instead of Android Suppor library. And all my code is based on the legacy android library.

In the file gradle.properties file(located in the base directory of your project same as gradlew), change

android.useAndroidX=true
android.enableJetifier=true

to

android.useAndroidX=false
android.enableJetifier=false

If you have all the dependency right and rebuild and cleared cache several times, still the android support library doesn't work. And if you have a newer version of android studio. It's possible that gradle.properties are wrong.

WenxuNiu
  • 1
  • 3