Build Failed: Program Type Already Present - android

I have searched online about this error and the issue always seems to end up being some sort of dependency conflict. I think I am supposed to add exclude after certain dependencies, but I am unsure which one(s). It's also unclear based on the error which dependency I should actually exclude; all I know is that the group is probably com.android.support...
Here's what I've tried:
Adding multiDexEnabled true to my defaultConfig block in build.gradle.
Cleaning the project in Android Studio.
Manually deleting (from the file system) the entire .gradle directory.
I've made sure compileSdkVersion and targetSdkVersion are the same.
I've made sure all my Android dependencies use the same version (namely 26.1.0).
Despite all this, I still get this error when I build:
Program type already present: android.support.compat.R$bool
and from the Java compiler:
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
F:\ExampleProject\app\build\intermediates\transforms\dexBuilder\debug\115,
F:\ExampleProject\app\build\intermediates\transforms\externalLibsDexMerger\debug\0
Here is my module's build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.myapp.exampleproject"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.1.0'
}
and lastly, my project's build.gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any help in rectifying this would be greatly appreciated.

This is a problem with Glide 4.1.0. Use the version 4.1.1 instead which fix the bug by remove the R*.class file from their dependencies. (source)

This is probably because of Glide library. Try to exclude the support library from it with:
// add support-fragment removed from Glide.
implementation "com.android.support:support-fragment:26.1.0"
implementation ('com.github.bumptech.glide:glide:4.1.0') {
exclude group: 'com.android.support'
exclude module: 'support-fragment'
exclude module: 'appcompat-v7'
}
You can see the support library inside Glide at Glide build.gradle

Solution:
implementation ('com.github.bumptech.glide:glide:4.1.0') {
exclude group: 'com.android.support'
exclude module: 'support-fragment'
exclude module: 'appcompat-v7'
}

Related

after upgrading, my project could not find resource file R but still running app showing no error. how to solve

I am facing a peculiar problem. i have upgraded my project from 23 api to 28. after upgrading, from my activity there showing cannot resolve R but while i run its building apk successfully and app running well without any showing any error. 2 more UI name also not recognizing in "setContentView" i have check that UIs no problem there. how to check for more specifically for UI error if exist.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
all*.exclude group: 'xpp3', module: 'xpp3'
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
repositories {
jcenter()
maven { url "https://dl.bintray.com/hani-momanii/maven" }
}
aaptOptions {
cruncherEnabled = false
}
lintOptions {
checkReleaseBuilds false
//If you want to continue even if errors found use following line
abortOnError false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation 'com.github.delight-im:Android-AdvancedWebView:v3.0.0'
implementation 'com.google.gdata:core:1.47.1'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-v13:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-nearby:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.markomilos:paginate:0.5.1'
implementation 'com.github.lovetuzitong:MultiImageSelector:1.2'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.iarcuschin:simpleratingbar:0.1.5'
implementation 'com.droidninja:filepicker:2.1.1'
implementation 'com.google.android:flexbox:1.0.0'
implementation 'com.felipecsl.asymmetricgridview:library:2.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'
}
apply plugin: 'com.google.gms.google-services'
build.gradle:
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
can anyone please help me.
There are a few reasons for this problem and also a few solutions:
First thing to try is to Invalidate caches and restart, usually it's just an Android Studio caching problem
If that doesn't work you might have a Gradle/Android Studio version problem. Usually when you upgrade your compile SDK, also the gradle version needs to be updated, but Android Studio complains with the error you are getting (already happened to me). Also update your Android Studio to the latest stable version (my guess goes to this solution to your problem)
After Rebuild Project click Tools -> Android -> Sync Project with Gradle Files
I had a similar problem that occurred when pulling updates from my master Github branch. The resource files were there and named correctly, the app still worked fine but all of the resource identifiers in one of my classes were highlighted red. I solved this by restarting Android Studio and the errors went away.

Firebase Firestore prevents Gradle from completing build

It shows this error whenever I try to sync the Gradle. Program type already present: com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream
I'm using AndroidStudio 3.1.3. I also followed the documentation on Firebase on how to get started but it dosen't work. I have tried to search and I couldn't get much information. I read about excluding the protobuf but it dosen't really work too.Thanks in advance for the help.
Also apparently commenting out the line with Firestore works so the issue is something with the Firestore dependency.
Below is my build.gradle for app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
//on laptop
//buildToolsVersion "26.0.2"
defaultConfig {
applicationId "application_id_name(sanitized)"
minSdkVersion 19
targetSdkVersion 26
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'project.properties'
exclude 'META-INF/INDEX.LIST'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.0.1'
implementation 'com.google.firebase:firebase-auth:16.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'
api 'com.google.android.gms:play-services-vision:15.0.0'
api 'com.android.support:multidex:1.0.3'
api 'com.google.cloud:google-cloud-storage:1.27.0'
implementation 'com.google.firebase:firebase-firestore:17.0.2'
implementation 'com.jjoe64:graphview:4.2.2'
}
apply plugin: 'com.google.gms.google-services'
And here is my build.gradle for the project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
//classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Got this error when trying to exclude protobuf.Could not find method com.google.firebase:firebase-firestore:17.0.2() for arguments [build_60vj88gllutj4zz7i0ca1ojkd$_run_closure2$_closure7#3b52fa7d] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
implementation 'com.google.firebase:firebase-firestore:17.0.2'{
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
Upgrade this:
classpath 'com.google.gms:google-services:3.2.1'
to this:
classpath 'com.google.gms:google-services:4.0.1'
to be able to use the latest version of firebase libraries.
After executing the ./gradlew :app:dependencies , you can see that both 'com.google.firebase:firebase-firestore:17.0.2' and 'com.google.cloud:google-cloud-storage:1.27.0' are depending on protobuf, thus leading to this problem.
Since Op is not using google-cloud-storage then removing 'com.google.cloud:google-cloud-storage:1.27.0' fixed this issue.

Unable to merge dex when a module is imported

I know there are many questions on this, but I tried the solutions of most of them and neither of them worked.
I have an app in which I have imported a module. When I try to run the app, I am getting Unable to merge dex exception.
build.gradle (app module)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.meditab.imspatient"
minSdkVersion 21
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'])
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2' // Constraint layout
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" // Kotlin
// Support libraries
implementation "com.android.support:appcompat-v7:$appcompat_version"
implementation "com.android.support:support-v4:$appcompat_version"
compile project(path: ':commonutils')
}
build.gradel (imported module)
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion '27.0.2'
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.jetbrains:annotations-java5:15.0'
compile 'com.jakewharton:butterknife:8.8.1'
// Support libraries
compile "com.android.support:appcompat-v7:$appcompat_version"
compile "com.android.support:design:$appcompat_version"
// Rx related libraries
compile 'io.reactivex:rxjava:1.1.1'
compile 'io.reactivex:rxandroid:1.1.0'
//compile 'com.netflix.rxjava:rxjava-core:0.+'
// Networking related libraries
compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-jackson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.android.gms:play-services-base:11.8.0'
compile 'com.google.android.gms:play-services-location:11.8.0'
compile 'com.estimote:sdk:0.10.+#aar'
}
build.gradle (project level)
buildscript {
ext.kotlin_version = '1.2.21'
ext.appcompat_version = '27.0.2'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Needed for the common utils module
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried deleting the .gradle folder, cleaning the project and rebuilding it. Nothing works. I also tried using implementation instead of compile in the build.gradle of the imported module.
Any help will be appreciated.
Thanks in advance.
It seems that 2 libraries you're declaring a dependency on are causing duplicate entries.
The problem is that you can't have the exact same class or annotation declared by 2 different libraries. If they were different versions of the same library probably the one with the highest version would be picked, but if they are completely different libraries, there is no way to tell which implementation should be included in the dex file.
The first one is:
'com.netflix.rxjava:rxjava-core:0.+'
Why would you use this? You have already defined a dependency on RxJava ('io.reactivex:rxjava:1.1.1') and they probably have many classes in common, the first that comes to my mind and that I checked is rx.Observable. The last update for that repo is Novermber 2014, more than 3 years ago. Besides conflicts, this fact alone should be a very good reason not to use it.
The second problem is:
'org.jetbrains:annotations-java5:15.0'
I imagine that you're importing this in order to get org.jetbrains.annotations.Nullable, this is already available in your project because Kotlin stdlib has a dependncy on org.jetbrains:annotations that also declares it. Hence the conflict.
Remove these 2 dependencies, you most likely don't actually need them anyway, and the project compiles.
I'm not 100 percent sure but I think you need to enable multidex in your app. Check this link : Enable Multidex
Just trying to help.
In my previous project which has multiple modules If I enable Proguard I was getting the same error.
That error frustrating and In my case I solved problem after inspecting
the project dependency graph(Using gradle to find dependency tree may help you while finding dependencies)
Play service's different version was causing in my case

duplicate entry error after adding google services

I wanted to add firebase to one of my app. I integrated firebase according to firebase offical documents. but when I tried to "run" app. it gives me this warning
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzc.class
I removed all the firebase coding & removed it from gradle file. but error still exist untill I remove this line
apply plugin: 'com.google.gms.google-services'
but unfortunately I need google services to work with firebase. here is my app gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId ""
minSdkVersion 19
targetSdkVersion 22
versionCode 15
versionName "2.01"
multiDexEnabled true
}
dexOptions {
preDexLibraries = false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/main.jar')
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.squareup.picasso:picasso:2.5.0'
compile 'com.commit451:NativeStackBlur:1.0.1'
compile 'com.google.firebase:firebase-analytics:9.0.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.facebook.android:audience-network-sdk:4.11.0'
}
apply plugin: 'com.google.gms.google-services'
here is my project gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
The problem was with Facebook Audience network. once I excluded google services it worked fine. If anyone having same problem change your audience network dependency like this
compile ('com.facebook.android:audience-network-sdk:4.11.0'){
exclude group: 'com.google.android.gms'
}
Add these dependencies:
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-gcm:11.0.4'
compile 'com.google.android.gms:play-services-places:11.0.4'
Add
android{
....
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
to your app's gradle file.
Add Firebase related dependencies
And Firebase related dependencies under dependencies in the same build.gradle file.
dependencies {
compile 'com.google.firebase:firebase-core:9.2.0' // this line must be included to integrate with Firebase
compile 'com.google.firebase:firebase-messaging:9.2.0' // this line must be included to use FCM
}
Update services using com.google.android.gms:play-services
If you add Firebase into an existing project which uses any function of gms:play-services, such as gps location,
you have to update their versions, too. Upon writing this tutorial, 9.2.0 works well. If you get compilation problems, you need to check find out the correct version number.
compile 'com.google.android.gms:play-services-location:9.2.0'
compile 'com.google.android.gms:play-services-places:9.2.0'
Source:
https://www.codementor.io/flame3/send-push-notifications-to-android-with-firebase-du10860kb

Unable to import mockito in android studio

I've started writing the unit tests for my application. I'm using Mockito to mock the objects.
This is the link I followed to include the mockito dependency in my app level gradle file.
The problem is I'm unable to import mockito into my test class.
Here's my app build.gradle file for the reference.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
lintOptions {
disable 'HardcodedText','TextFields','OnClick'
}
}
repositories {
jcenter()
mavenCentral()
maven() {
name 'SonaType snapshot repository'
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
ext {
robobindingVersion = 'latest.integration'
//robobindingVersion = '0.8.6-SNAPSHOT'
}
dependencies {
testCompile "org.mockito:mockito-core:1.+"
compile("org.robobinding:robobinding:$robobindingVersion:with-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile('org.robolectric:robolectric:3.0-rc2') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
apt "org.robobinding:codegen:$robobindingVersion"
compile 'junit:junit:4.12'
}
Try changing
compile "org.mockito:mockito-core:1.+" or implementation "org.mockito:mockito-core:1.+"
to
androidTestImplementation "org.mockito:mockito-core:1.+"
I had the same problem and solve it just by using:
compile "org.mockito:mockito-core:1.+"
Hope it helps =]
Check this link .... this may useful
https://stackoverflow.com/a/34148132/5185201
// add dexOptions
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
// Enabling multidex support.
multiDexEnabled true
Manually importing the mockito jar file did the thing for me.
To do that, first create a directory called "libs" in your app directory. Take note that this directory should be in the same level as that of the src/main and build directories.
Next, download the mockito jar file and paste it into the libs directory.
Include that into your dependencies in the app level build.gradle file:
dependencies {
compile files('libs/add-your-jar-file-name-here')
}
Sync the gradle and that should do the job.
Refer to this answer for more detailed answer with snapshots.

Categories

Resources