Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.0 - "Failed to transform file 'gson-2.2.4.jar' to match attributes {artifactType=android-classes}"

I'm a newcomer to Android Studio development, and I'm currently following an online tutorial to make a messenger app.

I've followed the steps of this tutorial, and it now needs me to download the Library files for Smack API & GSON, and add the .jar files to the libs folder in my project.

With this done, I right-clicked the files in the directory and clicked Add as library (the tutorial says to do Build Path -> Add to Build Path, but this doesn't seem to be an option in this version of Android Studio).

At this point, the project directory menu sidebar looks like this: enter image description here

From here, I tried to rebuild the project but was met with the following error:

enter image description here

I've not been able to find a way around this error at all, and don't know enough about Android Studio to know if this is an issue with the IDE or the package itself. I've had a look around S/O but none of the posts seem to describe the same issue, or offer any solutions to similar issues that appear to work for this too.

If anyone has run into this before, or if it is a common Android Studio problem, would you be able to advise me on how to resolve it please? Very frustrating when I just want to get on with learning how to code for Android!

Any help massively appreciated, thanks in advance!

Mark

like image 883
marcuthh Avatar asked Dec 04 '17 21:12

marcuthh


2 Answers

Here is best solution for importing any jar, arr libs

enter image description here

allprojects {
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    ....
}

You do not need to add repeatable lines with libs file name.

if you are a new to android studio, you can check the project structure from android by tapping drop-down menu.

enter image description here

like image 177
AppHero2 Avatar answered Sep 29 '22 06:09

AppHero2


did you try

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
}

in your build.graddle file of app module

like image 38
Ergin Ersoy Avatar answered Sep 29 '22 04:09

Ergin Ersoy