简体   繁体   中英

Android Studio - Error:Program type already present

When I try to compile the code, the following error appears on Android Studio 3.0.1

Error:Program type already present: com.squareup.picasso.Action$RequestWeakReference

My gradle code:

  ...
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.android.support:support-vector-drawable:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.1.0-beta4'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
    compile 'com.google.firebase:firebase-ads:11.8.0'
    compile 'com.google.gms:google-services:3.1.0'
    compile 'com.google.android.gms:play-services:11.8.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    testCompile 'junit:junit:4.12'

}

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

How do I fix my gradle script to fix the error?

将此添加到您的模块 build.gradle 文件中

  configurations.all {exclude group: 'com.android.support', module: 'support-v13'}

I just had the same problem so I will share the solution that worked for me. My error was:

Program type already present: org.json.CDL

and it started appearing after I added compile acra to my gradle file. So the solution was to add acra like this:

    compile('ch.acra:acra:4.5.0') {
    exclude group: 'org.json'
}   

So in OP's case the solution would be to find which one of his dependencies already compiles com.squareup.picasso and exclude like in the code above.

Check the compile version in your App settings. I changed it to the version compatible with the API level I've built my project with. This fixed the problem for me.

I faced nightmare of multiple troubles building APK after I upgraded Android Studio to 3.1.2 and targetSdkVersion to 27. This was one of them.

implementation 'me.leolin:ShortcutBadger:1.1.21@aar' 

This line causing build error Program type already present: me.leolin.shortcutbadger.Badger

For now I just commented it out and it compiled smoothly.

There is a Library Version Mismatch. if you are using newer version of Android Studio, it will trap error.just Resolve the Version mismatch or Change Compile version and you will be up and running.

See the dependencies defined below依赖

Ok, maybe it's not your case but this is the message coming out of compilation also in the following scenario

I built an app. Then I modified the app gradle file in such a way to produce an aar file instead of an apk [ie apply plugin: 'com.android.library' ] in order to move here some of the methods that had to be called by the original app

Then - in the original app - I commented the methods that I moved in the aar file and I added to the app project the aar file produced before

At this point I got the same error

The message Error:Program type already present helped me understanding that I had to rename the package name of the Android Studio project which was building the library because the two shared the same package name. So I renamed it, I built again the aar file and I added again this "new" file to the Android Studio project building the apk

Once done the issue disappeared

It's happened when you update a library build version and old build file not clear. Or other libraries are depended with the library. In my case I update com.google.gms:google-services

The solution is to open your project folder and delete build folder and reopen and clear cache, File > Invalidate Caches/Restart .

I came across this error in Android Studio 3.1.2 after I'd added Kotlin support to a Java project, and then removed all the Kotlin files (but left the gradle configuration in place). Removing the Kotlin configuration resolved this issue.

This can happen when there's a library version mismatch.

In my case when I updated Google Services dependencies from:

classpath 'com.google.gms:google-services:3.0.0'

to

classpath 'com.google.gms:google-services:3.2.1'

the error went away.

In My App I added this line & also add this library as import. Remove library import will work well Line that import all jar files from libs folder.

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

Still I am importing this line will cause error.

implementation(name: 'twitter4j-core-4.0.7', ext: 'jar')

Remove library as import will solve problem. If error still not go do build > Clean Project.

More information Found here: https://developer.android.com/studio/build/dependencies#duplicate_classes

For me, this error appeared when my build.gradle file contained an invalid line.

I added a .jar file as library, and the Build failed. I checked the build.gradle file, and somehow it contained two lines:

implementation files('libs/bcprov.jar')
implementation files('bcprov.jar')

Of course, I only added the .jar to the libs folder, so the second line is invalid. After I deleted the second line, the error disappeared.

Hope this will help someone.

this happens when you have duplicate dependencies, list all your dependencies with ./gradlew app:dependencies

for example both dagger and robolectric depend on guava, but dagger's latest version uses guava 23+ while robolectric uses 20+, excluding guava from robolectric will solve the issue in this case.

The answer is very simple:

Go to Build > Rebuild Project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM