How do I import material design library to Android Studio?
Asked Answered
N

9

38

I want to import this library to my project in Android Studio v1.0.0 rc2:

https://github.com/navasmdc/MaterialDesignLibrary

But there is a problem. When I add this library as a module, this error appears:

Error:Dependency MyApplication.libraries:MaterialDesign:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: C:\ADTBundle\StudioWorkspace\MyApplication\libraries\MaterialDesign\build\outputs\apk\MaterialDesign-release-unsigned.apk

What would be a step-by-step guide to solve this problem? Or what would be a gradle dependency for this library?

Nowicki answered 8/12, 2014 at 18:34 Comment(1)
In general it looks like you're trying to import an APK, which isn't a valid library type. An APK is a full installable Android application file, not a library. You should include it as source or look for a JAR or AAR archive.Undersecretary
G
27

If you are using Android Studio:

  • You can import the project as a module and change the following in the build.gradle file of the imported module.

  • Change apply plugin: com.android.application to apply plugin: com.android.library remove applicationId and set minSdkVersion to match your project minSdkVersion.

  • And in your project build.gradle file compile project(':MaterialDesignLibrary'), where MaterialDesignLibrary is the name of your library project or you can import the module by File -> Project Structure -> Select your project under Modules -> Dependencies -> Click on + to add a module.

Gallium answered 12/12, 2014 at 12:18 Comment(4)
I had the same problem. I did exactly as you suggested. It built successfully. But when I tried to run it, this error came up; Error:(25, 32) error: cannot find symbol class myLibUsed
I found the solution. Have to set minifyEnabled false for it to work, else the class myLib could not be found.Used
am using android studio v1.0.2. please help me to how can i add already existing project into android studio and set that project as support libreary project like in eclipse.Bernardinebernardo
I don't get an "apply plugin" line. I get "configurations.create("default")" and an artifacts.add statement.Bateman
W
44

There is a new official design library, just add this to your build.gradle: for details visit android developers page

implementation 'com.android.support:design:27.0.0'
Whelp answered 15/6, 2015 at 15:35 Comment(7)
how to compile gradle? how to use this?Opera
@NitinKarale android-developers.blogspot.com/2015/05/…Interne
How do I know which version number to use?Padus
@ScottBiggs try the latest stable oneWhelp
@WhereDatApp.com Thanks for your help! How do I know what the latest stable version number is? Guessing is a very tedious process.Padus
Just google "material design support library", e.g. developer.android.com/training/material/design-library.html @ScottBiggsWhelp
Upgrade the dependency to implementationJackofalltrades
J
28

If u are using Android X: https://material.io/develop/android/docs/getting-started/ follow the instruction here

when last edited the latest library version was

implementation 'com.google.android.material:material:1.11.0'

Update : Get latest material design library from here https://maven.google.com/web/index.html?q=com.google.android.material#com.google.android.material:material

For older SDK

Add the design support library version as same as of your appcompat-v7 library

You can get the latest library from android developer documentation https://developer.android.com/topic/libraries/support-library/packages#design

implementation 'com.android.support:design:28.0.0'
Jackofalltrades answered 31/10, 2018 at 9:29 Comment(1)
implementation 'com.google.android.material:material:1.2.0'Goneness
G
27

If you are using Android Studio:

  • You can import the project as a module and change the following in the build.gradle file of the imported module.

  • Change apply plugin: com.android.application to apply plugin: com.android.library remove applicationId and set minSdkVersion to match your project minSdkVersion.

  • And in your project build.gradle file compile project(':MaterialDesignLibrary'), where MaterialDesignLibrary is the name of your library project or you can import the module by File -> Project Structure -> Select your project under Modules -> Dependencies -> Click on + to add a module.

Gallium answered 12/12, 2014 at 12:18 Comment(4)
I had the same problem. I did exactly as you suggested. It built successfully. But when I tried to run it, this error came up; Error:(25, 32) error: cannot find symbol class myLibUsed
I found the solution. Have to set minifyEnabled false for it to work, else the class myLib could not be found.Used
am using android studio v1.0.2. please help me to how can i add already existing project into android studio and set that project as support libreary project like in eclipse.Bernardinebernardo
I don't get an "apply plugin" line. I get "configurations.create("default")" and an artifacts.add statement.Bateman
A
8

Goto

  1. File (Top Left Corner)
  2. Project Structure
  3. Under Module. Find the Dependence tab
  4. press plus button (+) at top right.
  5. You will find all the dependencies
Addressee answered 17/12, 2015 at 10:46 Comment(0)
A
4

If you migrated to AndroidX you should add the dependency in graddle like this:

com.google.android.material:material:1.0.0-rc01

Arber answered 28/11, 2018 at 4:28 Comment(0)
I
3

The latest as of release of API 23 is

compile 'com.android.support:design:23.2.1'
Impermanent answered 3/4, 2016 at 18:14 Comment(0)
G
1

First, add the Material Design dependency.

implementation 'com.google.android.material:material:<version>'

To get the latest material design library version. check the official website github repository.

Current version is 1.2.0.

So, you have to add,

implementation 'com.google.android.material:material:1.2.0'

Then, you need to change the app theme to material theme by adding,

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

in your style.xml. Dont forget to set the same theme in your application theme in your manifest file.

Guntar answered 5/8, 2020 at 6:49 Comment(0)
S
0

build.gradle

implementation 'com.google.android.material:material:1.2.0-alpha02'

styles.xml

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
Soares answered 6/6, 2020 at 9:42 Comment(0)
B
0

you can add latest libraries support to old project by putting all these inside app:level gradle.build like this

    apply plugin: 'com.android.application'

android {
    
    
   // rest code

    dependencies {
        implementation("com.squareup.okhttp3:okhttp:4.10.0")
        implementation 'androidx.appcompat:appcompat:1.4.2'
        implementation 'com.google.android.material:material:1.6.1'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        testImplementation 'junit:junit:4.13.2'
        androidTestImplementation 'androidx.test.ext:junit:1.1.3'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    }
}
Bergschrund answered 13/7, 2022 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.