Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error implementing Material Design in Android

I've been reading over the new material design website but I'm having an issue implementing it.

The application I'm currently working in is a simple test applications with nothing more than a button and some textviews.

The problem comes after placing implementation 'com.google.android.material:material:1.0.0-alpha1' in the gradle file.

heres my build.gradle(app) file

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.user.firebasemessagingtest"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    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.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-messaging:15.0.2'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
    implementation 'com.google.firebase:firebase-ml-vision:15.0.0'
    implementation 'com.google.android.material:material:1.0.0-alpha1'
}

apply plugin: 'com.google.gms.google-services'

I've got 4 errors,

error: resource android:attr/dialogCornerRadius not found.
error: resource android:attr/fontVariationSettings not found.
error: resource android:attr/ttcIndex not found.
error: failed linking references.

I have included the maven in the project gradle file like stated in the documentation.

like image 418
Demonic218 Avatar asked Oct 17 '22 18:10

Demonic218


2 Answers

Try this

change compileSdkVersion and Support Libraries version

compileSdkVersion  'android-P'
Support Libraries to '28.0.0-alpha1'

and use

 api 'com.android.support:design:28.0.0-alpha1'

EDIT

Update your SDK Platform update - Android P Preview (latest)

and also make targetSdkVersion 'P'

Than Clean-Re_Build-Run your project

EDIT 2

apply plugin: 'com.android.application'

android {

    compileSdkVersion  'android-P'

    defaultConfig {
        applicationId "com.example.nilesh.testapp"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
    compile 'com.android.support:design:28.0.0-alpha1'
    compile 'com.android.support:cardview-v7:28.0.0-alpha1'

    implementation 'com.android.support.constraint:constraint-layout:1.1.0'

    testImplementation 'junit:junit:4.12'

    implementation 'com.google.android.material:material:1.0.0-alpha1'


    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-messaging:15.0.2'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
    implementation 'com.google.firebase:firebase-ml-vision:15.0.0'

    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
repositories {
    mavenCentral()
}

Hope this helps

like image 179
AskNilesh Avatar answered Nov 15 '22 06:11

AskNilesh


Set compileSdkVersion as 'android-P'.

Match the support library with the compileSdkVersion. For instance, implementation 'com.android.support:support-v4:28.0.0-alpha1' instead of implementation 'com.android.support:appcompat-v7:27.1.1'.

Replace implementation 'com.google.android.material:material:1.0.0-alpha1' with api 'com.android.support:design:28.0.0-alpha1'.

The app build.gradle should look something like this.

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 'android-P'

    defaultConfig {
        applicationId "com.wolfrevokcats.myapp"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 16
        versionName "2.3"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable false
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    api 'com.android.support:design:28.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
    implementation ('com.someone.addons:library:1.6.1@aar'){
        exclude group: 'com.android.support'
        exclude module: 'appcompat-v7'
        exclude module: 'support-v4'
    }
    implementation 'com.google.android.gms:play-services-location:15.0.1'

    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'
}

As 'com.android.support:design:28.0.0-alpha1' is being used, our code will have to change to android.support.design instead of com.google.android.material libraries. Here's an example using the new Bottom App Bar widget.

<android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/toolbar"
        style="@style/Widget.MaterialComponents.BottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:fabAttached="true"
        app:fabAlignmentMode="center"/>
like image 29
Nur Ilyas Avatar answered Nov 15 '22 05:11

Nur Ilyas