IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
Asked Answered
I

7

7

I'm using Android Studio + gradle on MyProject + Facebook api as a library. See below settings.

I've tried removing all references of support-v4 (either r7 or 18.0.0) and replace them with support-v13, but the message with v4 was still present. I've also noticed that support-v4-r7 appears in External libraries, even though it's not referenced at all, anywhere. Would that be the problem ?

MyProject build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
    maven {
        url "https://raw.github.com/ark/ark/master/releases/"
    }
}

dependencies {
    compile 'com.andreabaccega:android-form-edittext:1.0.3'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
    compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
    compile 'com.google.android.gms:play-services:3.1.36'
    compile files('libs/imageloader-core-1.5.8.jar')
    compile project(':libs:Facebook')

}

android {
    compileSdkVersion 17
    buildToolsVersion "18.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 17
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['res']
            res.srcDirs = ['res']
        }

        debug {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src', 'libs/Facebook/src', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
            resources.srcDirs = ['build', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
            res.srcDirs = ['res']
        }
    }
}

MyProject settings.gradle:

include ':MyProject'
include ':libs:Facebook'

Facebook build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

android {
  compileSdkVersion 17
  buildToolsVersion '18.1'

    defaultConfig {
        minSdkVersion 8
    }

  sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['res']
        res.srcDirs = ['res']
    }
      debug {
          manifest.srcFile 'AndroidManifest.xml'
          java.srcDirs = ['src', 'build/source/r/debug', 'build/source/buildConfig/debug']
          resources.srcDirs = ['build/source/r/debug', 'build/source/buildConfig/debug']
          res.srcDirs = ['res']
      }
  }
}

Edit: I've tried adding the libs that I use in this project, in another project, one by one, to see what fails. Apparently these 2 are the culprits. If I include any or both of them, I get the above error.

compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
compile 'com.google.android.gms:play-services:3.1.36'

Any ideas on how to manage this ?

Edit2: Apparently another project presents the same issue. See build.gradle dependencies below. StickyListHeaders project doesn't contain anymore dependencies. So I presume it's because of ActionBarSherlock ?

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:18.0.+'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
    compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
    compile project(':Project Base:libs:StickyListHeaders')
}
Intersection answered 26/9, 2013 at 14:0 Comment(1)
Hi @Andrew could you please check my question ? #19957064Cathern
I
7

Apparently there were 2 reasons for this issue.

1) PagerSlidingTabStrip library depends on a local support lib v4 jar. Remove the dependency and add the project as a library project in your app and inside it add the maven dependency for support v4. So it should look exactly like the Facebook library project from above.

2) RoboSpice library depends on LRUCache from support lib v4 (https://github.com/octo-online/robospice/issues/195). Just exclude it from your main build.gradle file and you should be good to go.

compile ('com.octo.android.robospice:robospice-spring-android:1.4.7')
        {
            exclude module: 'support-v4'
        }

Hopefully this will help somebody and not spend an entire week with this problem like I did. Oh, and trillion of thanks to @Snicolas. Couldn't have solved it without his help.

Edit: As of RoboSpice v1.4.8, there is no more local support lib dependency, so this issue is fixed.

Intersection answered 5/10, 2013 at 14:51 Comment(1)
Great answer. PagerSlidingTabStrip updated to 1.0.1 solved my issue.Fagoting
C
7

For anyone who happens to hit this error while using Visual Studio with Xamarin, like I did;

I solved it by simply removing the reference to "Xamarin.Android.Support.v4" from the References folder within the project, then cleaned and built project as normal.

Creeper answered 22/11, 2016 at 14:20 Comment(4)
I did that now I get this error: Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Xamarin.Android.Support.v4'Norseman
This didn't fix my issue right away. For others having this problem I'd recommend fiddling with the package and references for a little while.Yuriyuria
The fix for this, using Xamarin, was to update my Xamarin.Support libraries. In my case it was from 23.3.0 to 25.3.1Postrider
I found simply deleting the obj folder from within the project's folder on disk was enough to fix the issue (or maybe it was that in combination with removing the nuget packages folder earlier) - I would recommend trying this before anything elseMarmoset
M
2

When this is for Xamarin.Android, this error occurs for version mismatching between depended packages. You've got to remove this Xamarin.Android.Support.v4 package from the project along with other mismatching packages. (What does mismatching means here is, if your target Android version is Android 6, all packages listed in the packages.config file should have targetFramework="monoandroid60" packages. If any package won't abide this, it's a mismatching version). If you have messed with versions, then removing the reference and cleaning stuff alone won't work. You've got to remove all the mismatching packages from the Nuget Package Manager (Tools > NuGet Package Manager > Manage NuGet Packages for Solution...). Note that when you're to remove these packages, you'll also need to remove the depended packages. No harm go ahead and remove them all and you can re-install them with the correct version.

Once you've removed the package along with the dependent packages, try building the project. After a successful build, re-install the packages from the Nuget Package Manager with the correct version. (Package versions are listed according to the API levels, Ex: Android 6 which is API 23, would support packages of version 23.x.x)

Cleanup the project and build it, hopefully it'll succeed building!

Hope this'll help cleanup the mess!

Maltzman answered 7/8, 2017 at 7:10 Comment(2)
I'm experiencing the same error but can't remove the offending package, because Xamarin.Forms depends on it. I can't remove Xamarin.Forms because other packages depend on it.Enterprising
What I did was, I noted down all the packages linked with each other that I were to remove. Then removed them along with their dependents. Then re-installed all of them back with the correct versions of them.Maltzman
P
1

Run "gradle androidDependencies" and check your dependencie tree. Add an exclude for the modules that are overlapped.

For example i had to do the following:

dependencies {
  compile 'com.google.android:support-v4:r7'
  compile project(':libraries:actionbarsherlock')
  compile ('com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+') {
    // Need to specifically exclude this as it is specified in our own project
    exclude module: 'actionbarsherlock'
    exclude module: 'support-v4'
  }
}
Pyralid answered 4/12, 2013 at 13:52 Comment(0)
P
0

The page slider library also have support library dependency. Thus you are getting this error. In case of maven all you need to do is change your main project pom file dependency entry of the support library to scope as provided.

<dependency>
    <groupId>android.support</groupId>
    <artifactId>compatibility-v4</artifactId>
    <version>13</version>
    <scope>provided</scope>
</dependency>

In case of gradle i think you need to change the dependency configuration to match maven provided scope

Please refer the following link for more details Convert Maven to Gradle

Purposeless answered 1/10, 2013 at 7:29 Comment(6)
Ok, I can confirm that's the problem with the PagerSlidingTabStrip library, and I've contacted its author to solve this issue. But what about PlayServices ? I don't see a /libs folder after compiling it, like I saw with PagerSlidingTabStrip.Intersection
Did not get your question if you are using Android Studio, the only thing you need is to edit the build.gradle file and make sure that there are no android or google jar libraries, which means that you will need to remove jar libraries from your project.Purposeless
I was referring to this line: compile 'com.google.android.gms:play-services:3.1.36' This produces the same error.Intersection
I think I fixed the problem with PagerSlidingTabStrip by including 'com.android.support:support-v4:18.0.+' in the local project for the lib, then including this into Facebook lib, then including Facebook into MyProject. The issue is still present, probably now due to PlayServices... Any ideas for that ?Intersection
I had faced similar issue when i used action bar , facebook sdk and view pager library. The scope=provided did the trick for me. As i mentioned earlier , you need to do similar thing in gradle.Purposeless
Well I can't do that for PlayServices. It's either a jar (in which I can't find any reference to the support lib), either a maven dependency, which I can't modify.Intersection
T
0

I just got this same issue. I simply updated all Xamarin.Android.Support… nuget packages to the same version.

Note: this app was older so I did not go to the Latest stable version as there were other dependencies that would have needed to be updated. I simply moved them all to the highest common version.

Good luck! Tom

Toughminded answered 7/7, 2018 at 16:6 Comment(0)
W
-2

Remove all old reference .dlls and relevant to that and add again from NuGet.

Wether answered 28/2, 2017 at 14:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.