IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl; - android

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')
}

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.

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.

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!

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'
}
}

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

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

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

Related

Gradle build fails looking for Google Play Services in Android Studio

I'm trying to run my project in Android Studio 0.3.6, but I always get this error :
Gradle: A problem occurred configuring root project 'myapp_android'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not resolve com.google.android.gms:play-services:3.1.36.
Required by:
:myapp_android:unspecified
> Could not GET 'http://maven.hq.couchbase.com/nexus/content/repositories/releases/com/google/android/gms/play-services/3.1.36/play-services-3.1.36.pom'. Received status code 503 from server: Service Temporarily Unavailable
Here is my complete build.gradle file :
home = System.getenv("ANDROID_HOME")
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url "http://maven.hq.couchbase.com/nexus/content/repositories/releases/"
}
maven {
url "http://files.couchbase.com/maven2/"
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.couchbase.cblite:CBLite:1.0.0-beta'
compile 'com.couchbase.cblite:CBLiteEktorp:1.0.0-beta'
compile 'com.couchbase.cblite:CBLiteJavascript:1.0.0-beta'
compile fileTree(dir: 'libs', include: '*.jar')
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3'
}
android {
compileSdkVersion 18
buildToolsVersion "18.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
tasks.withType(Compile) {
options.encoding = 'UTF-8'
}
And finally, my SDK Manager :
I tried with many versions of Android Studio (0.2.8, 0.2.9, 0.2.13, 0.3.2, 0.3.6) and it's always the same. I tried changing the Play Services version, I tried changing the order of the dependencies, nothing did the trick.
Is there something not correct with my setup? I looked for answers and pretty much everything I found (build.gradle structure, SDK missing items) was already fine...
I finally found what was the problem. #gnuf pointed me in the right direction. But the problem was that Android Studio, in Project Structure | Platform Settings | Android SDK, showed the wrong SDK. It showed the SDK it used was C:/Program Files (x86)/Android/android-studio/sdk, but in fact, I discovered it tried to build with another SDK located in C:\Users\my_username\AppData\Local\Android\android-studio\sdk.
Needless to say, it didn't work. There was nothing installed in this SDK. So I copied the contents of C:/Program Files (x86)/Android/android-studio/sdk to C:\Users\my_username\AppData\Local\Android\android-studio\sdk and it worked! My first build in three weeks.
So I think it's a bug of Android Studio. If anyone runs into this problem, make sure you only have one SDK on your computer. If you have more than one, make sure they all have the required dependencies. If you can, just copy the content of the most up to date to the others.
It may be the case that the location where you've installed the SDK components is different than the one that Android Studio is using.
Can you verify that the local Maven repositories (installed by the Google Repository and Android Support Repository) are under the Android SDK that you're using in your Android Studio project?
In Android Studio, go to Project Structure | Platform Settings | Android SDK. (On my machine, the path for Android SDK Location is /opt/boxen/homebrew/Cellar/android-sdk/22.2.1 ) In that directory, ensure that the subdirectory extras/google/m2repository/com/google/android/gms/play-services/ exists.
It looks for Google dependencies like Google Play Services in your SDK extras, not in Maven repositories over the network. Install the "Google Repository" in your SDK manager and you should be good to go.

How to add libraries to Android Studio?

I'm currently downloaded newest android studio 0.3.2. I've been trying to add libraries for almost 5 hours, and nothing.
I've pressed F4 in the 'Module' where the libraries should go, added the libraries, also in the project structure added the dependencies, and also in build.gradle of the 'Module'. The errors in the IDE stop appearing, but when It 'compiles' it. It keeps telling me, that com.google.gson and other libraries don't exist.
How can I fix It? Or should I use Android studio?. Thank you very much.
EDIT
This is the build.gradle file, of the main project.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
And this is the Gradle file o f the 'Module' that gives problems:
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src']
main.resources.srcDirs = ['src']
test.java.srcDirs = ['tests/java']
test.resources.srcDirs = ['tests/resources']
}
Here is an example for the Google Analytics library and the Gson library:
dependencies {
...
compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/libGoogleAnalyticsServices.jar')
}

Can't build project, problems with gradle?

I'm trying to switch from eclipse to android studio for my android development.
However, I still haven't found the right way to import my existing project.
I don't know if it is important: but I'm using a mac
I did the export step in eclipse, imported this gradle build in Android Studio, but when I try to build my project, it gives me this error:
Gradle:
FAILURE: Could not determine which tasks to execute.
* What went wrong:
Task 'assembleDebug' not found in project ':ProjectName'.
* Try:
Run gradle tasks to get a list of available tasks.
Could not execute build using Gradle installation '/Users/<username>/Development/Build/gradle-1.6'.
This is the build.gradle file that eclipse gave me:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.+'
}
}
apply plugin: 'android'
dependencies {
compile project(':ProjectName:library:ActionBarSherlock')
compile project(':ProjectName:library:facebook')
compile files('../../../../../../../ProjectName/libs/gcm.jar')
compile files('../../../../../../../ProjectName/libs/libGoogleAnalyticsV2.jar')
compile files('../../../../../../../ProjectName/libs/commons-lang3-3.1.jar')
compile files('../../../../../../../ProjectName/libs/actionbarsherlock-plugin-maps-4.2.0.jar')
compile files('../../../../../../../NiteOwl/libs/volley.jar')
compile project(':ProjectName:library:PullToRefresh')
compile project(':ProjectName:library:google-play-services_lib')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I've seen a lot of possible solutions, but none of them worked for me, any idea what I'm doing wrong?
The path to the project has no spaces in it
jar libraries => ProjectName/libs
android libraries => ProjectName/library
all of this was working in eclipse
We recently moved our project to gradle as well. We ran into issues due to the library projects.
To solve it we added a settings.gradle file in the root of your project with
include ':libs:actionbarsherlock'
include ':yourprojectname'
Add all your library projects from eclipse into the settings.gradle
We also made a build.gradle file for each of the library Projects.
AFAIK the export from eclipse doesn't deal well with library projects.
In the build.gradle at the root of your project (the one that's probably mostly empty), add the following line:
task assemble{}
Found at https://code.google.com/p/android/issues/detail?id=57531
I've had this error appear when I had a stray empty flavors stanza in my build.gradle:
productFlavors {
}

Gradle error with Android project added as a library (SlidingMenu) [package does not exist]

I've never used Gradle before so I'm completely lost!
I've added SlidingMenu as a library and I have access from my project to all the SlindingMenu stuff, but trying to compile will give me this error:
Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist
I'm using Android Studio (so IntelliJ) and this is my gradle.build
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
Thanks in advance
Assuming you have added SlidingMenu.jar into libs folder, right click on it -> Add as library. Then change in gradle.build:
Before:
dependencies {
compile files('libs/android-support-v4.jar')
}
After:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will include all your jar files.
I had the same problem. Adding sliding-menu-lib from with gradle-build as android library did help me.
My project structure is as:
-MyDemoProject
-build.gradle
-settings.gradle
--MyDemo
--build.gradle
--libs
---sliding-menu-lib
----res
----src
----AndroidManifest.xml
----build.gradle
--src
To make all the stuff working your settings.bundle should have this contents:
include ':MyDemo' ':MyDemo:libs:sliding-menu-lib'
There is a trick here, which allows you avoid errors while building project with gradle using Android Studio, as according to Android Tools Manual you should use ':libs:sliding-menu-lib' but that does not work due to issue with relative projectDir paths.
Your MyDemo/build.gradle should contain dependencies like:
dependencies {
compile 'com.android.support:support-v4:18.0.0'
...
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':MyDemo:libs:sliding-menu-lib')
}
And your sliding-menu-lib/build.gradle should be like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 14
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
Most important part deals with sourceSets section as you may not want change sliding-menu-lib file structure (non-default for current gradle)
I added all of my previous libraries using the default import from source tool. For SlidingMenu I used the import with Maven then deleted all of the Maven dependancies from the Project Settings for SlidingMenu and reimported the Support libraries. This seemed to clear most issues up for me.
If the module is just a library and not a stand-alone app, it's gradle should contain
apply plugin: 'android-library'
instead of
apply plugin: 'android'
You can Sync Project with Gradle Files:
Tools -> Android -> Sync Project with Gradle Files
Recently found better solution for SlidingMenu separately:
You can add SlidingMenu as generated #aar file if you do not need to make any changes to it. Just use https://github.com/jzaccone/SlidingMenu-aar and make changes as in Readme file there.
Be careful with order of repos. This one should be above mavenCentral()

Gradle can't find dependency (Android support library)

I have a problem that Gradle can't find my dependency (Android support library).
My build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/FlurryAgent.jar')
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
compile files('libs/YouTubeAndroidPlayerApi.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
When I build (on commandline, no IDE) I get the following message:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'AndroidCalculator'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':compile'.
> Could not find com.google.android:support-v4:r7.
Required by:
:AndroidCalculator:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Why am I not allowed to add the Android Support library like this?
You have declared a repository dependency, but haven't declared a repository. Hence the dependency cannot be resolved. (Repositories/dependencies in the buildscript block are strictly separated from repositories/dependencies in the main build script.)
http://pastebin.com/FmcCZwA5
This paste is elaborate project with AndroidAnnotations, Dagger, Jackson and Robolectric.
all you need is add
repositories {
mavenCentral()
}
replace
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
with (line 44 of the code linked above)
compile 'com.android.support:support-v4:18.0.+'
Gotchas: Last bit will works on Android Studio 0.2+ only if you had a fresh install. Since 0.2 Studio is shipped with its internal m2 repo to provide support and google api libraries so if you upgraded from previous versions your SDK doesn't have it.
also make sure local.properties file is present in root folder and sdk.dir points to SDK
You need to add additional dependency in dependencies tag. If you have android-support-v4.jar library in your libs folder, try to add code listed below:
dependencies {
compile files('libs/android-support-v4.jar')
}

Categories

Resources