I can integrate (add & work) with many libraries.
But as for ActionBarSherlock library, I have so many problems with it.
First Issue is the popular issue Multiple dex files define,
I know The duplicated android-support-v4.jar causes it, but I can not solve this issue now :
Error:Execution failed for task ':fitness:dexDebug'.
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
I followed the answer in same error. It used :
dependencies {
compile('...') {
exclude module: 'support-v4'
}
compile 'com.android.support:support-v4:18.0.+'
}
But I received Second Issue : unsupported Gradle DSL method found: 'exclude()'! error.
Therefore I changed build.gradle of main module like this:
//configurations {
// all*.exclude group: 'com.android.support', module: 'support-v4'
//}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':google-play-services')
compile files('/google-play-services/libs/google-play-services.jar')
compile (project(':actionbarsherlock')) {
exclude(module: 'support-v4')
}
compile 'com.android.support:support-v4:18.0.+'
}
Solved Second Issue, But still get First Issue Multiple dex files define error.
I read many topics, but can not solve First Issue now,
Please help me,
Thanks,
p/s : I can sync with Gradle successully, but when run, it get above errors.
I used Android studio 0.5.5
EDIT
build.gradle of ActionBarSherlock, it has only one android-support-v4.jar:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
setting.gradle like this :
include ':fitness', ':google-play-services',':actionbarsherlock'
#Garbriele : I updated new question, show build.gradle of project and build.gradle of main module
build.gradle of project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
build.gradle of main module after edited :
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar' // Get following error in this line
}
I got this error in below :
Okay, thanks for #Garbriele comment, I already fixed this by using this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar' // Get following error in this line
}
EDIT 2 When I put like this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:+'
}
Still get First Issue Multiple dex files define error.
What I want now is how to add com.google.android.gms:play-services library via Maven successfully,
Please help me,
Thanks,
UPDATE
After followed these steps :
Put the library via Maven in build.gradle of main module : compile 'com.google.android.gms:play-services:+'
Restart Android Studio
Sync project with gradle
No longer get this error again.
So strange,
When I setup my dependencies like this :
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:+'
}
I still get the First Issue Multiple dex files define error.
But after following these steps:
Put the library via Gradle in build.gradle of main module : compile 'com.google.android.gms:play-services:+'
Restart Android Studio
Sync project with gradle
I no longer get this error.
I had duplicate libraries in my libs directory:
$ ls -la libs/
total 80
drwxr-xr-x 5 wheel 170 25 Sep 22:09 .
drwxr-xr-x 10 wheel 340 25 Sep 22:07 ..
-rw-r--r-- 1 wheel 3736 25 Sep 21:36 ApiComponent.jar
-rw-r--r-- 1 wheel 28741 25 Sep 21:36 DependencyService.jar
-rw-r--r-- 1 wheel 3736 25 Sep 22:09 classes.jar
Removing classes.jar worked for me. I modified my DependencyService Project to produce DependencyService.jar instead of classes.jar causing the duplication.
Related
I created an Android library that uses JavaPoet to generate classes. It works well on my local workspace ; even if I include the library module into another project.
Now I'm trying to put my project online through bintray. The project is uploaded correctly, but then when I include it in a new project and build the projet I get this message :
Error:Bad service configuration file, or exception thrown while
constructing Processor object: javax.annotation.processing.Processor:
Provider me.aflak.filter_processor.FilterProcessor could not be
instantiated: java.lang.NoClassDefFoundError:
com/squareup/javapoet/TypeName
I guess it comes from the way I manage the dependencies... Compiletime, Runtime stuff...
This is processor build.gradle :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':filter-annotation')
api 'com.squareup:javapoet:1.9.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.google.auto.service:auto-service:1.0-rc3'
}
This is annotation buid.gradle :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.8.1'
}
This is how I include the library in an empty project :
// build.gradle project
repositories {
maven{
url 'https://dl.bintray.com/omaflak/maven'
}
}
// build.gradle module
dependencies {
compile 'me.aflak.libraries:filter-annotation:1.0'
annotationProcessor 'me.aflak.libraries:filter-processor:1.0'
}
Could someone point me out to the right direction ? Thanks !
I finally got the solution (a bit randomly though :p).
I had to add mavenLocal() in the library module.
I created a new library module to my project in Android Studio. A class in this new module accesses org.json.JSONObject.
I'm getting the error:
failed to resolve org.json:json:20141113
when trying to build the project.
Here's how my build.gradle file looks:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':app')
compile files('libs/volley.jar')
compile 'org.json:json:20141113'
}
Please let me know if I'm missing anything.
Thanks.
Try adding a repository to your configuration maybe that helps.
repositories {
mavenCentral()
}
For more information see here:
User-guide: Dependency Management Basics
Test This one , Worked for me
dependencies {
implementation 'com.cedarsoftware:json-io:4.10.1'
}
Hello I am working on a project for which I am using Android Studio. I have setup everything but when I run my project then I get below errors. I could not resolve it for last 2 days. What could be the problem in my project that causing this error
Please help if anyone know about this.
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "in.xyz"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.+'
//compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
//compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
...
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ': app:dexDebug'.
settings.gradle
include ':app'
include ':multiStateToggleButton'
Your problem i believe is that wherever you are linking the Library to your Main Project you have the same dependencies between the two for your support library and annotations.
If you have the library project as a dependency in your application you will only need the dependency to be placed in the library dependencies closure.
The issue is that you have two dex files because there are two Files with the same name because the overlap in files with your dependencies.
First copy your module to your libs/ folder of your main project then,
create your settings.gradle file in the root of the main project:
include 'app_name', 'library_name'
project(':LibraryNameGoesHere').projectDir = new File('libs/LibraryNameGoesHere')
For your library's build.gradle
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
Then for your main project build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.+'
compile project(":libs:LibraryNameGoesHere")
}
Since facebook sdk configed for using Android 2.3.3, it requires annotaion lib.
My app configed for using Anndoid > 4.x.x, which is contains Annotation, the conflict was emarged.
I have changed, in the facebbok mainfest, to work with Android > 4.x.x and it solved the problem.
if you migrate the project from eclipse to studio , and then your project need a new module, you add the build.gradle which in the module, add the dependencies like this,
compile 'com.android.support:support-annotations:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
//recyclerview
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
you might be see this stupid problem because the old project has include the jar file like android-support-v4.jar
this shit is overlay the compile(thing) so you must remove the *.jar file,
this shit takes my hole afternoon, so good luck ,my english is pool,
fogiven me please
For what it's worth I was getting this error after using Android Studio to import a project from Eclipse. In the /app/build.gradle file I had two entries in the dependencies section, it looked like this
dependencies {
compile files('libs/android-support-v13.jar')
compile files('libs/android-support-v4.jar')
}
I removed the reference to v4 like below
dependencies {
compile files('libs/android-support-v13.jar')
}
I cleaned the project and was able to build my APK. I don't know if this was the correct way to fix it but it worked for me.
I have a basic Android app that I created with Android Studio, and I'm having problems adding butterknife to my build. I get this error:
Error:: duplicate files during packaging of APK C:\apps\orion\app\build\apk\app-debug-unaligned.apk
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor
File 1: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
File 2: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
My dependencies look like this:
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.jakewharton:butterknife:4.0.1'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:appcompat-v7:+'
compile project(':lib')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Later versions of the plugin will tell you how to fix this. I think we introduced the fix in 0.8 so you should probably upgrade. Then the fix is to put this in your build.gradle
android {
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
This will exclude this file from the packaging which is fine since it's not actually needed in the APK.
That's because you wrote compile for dagger-compiler, replace it with provided and the issue will be fixed.
compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
The best option in version >= 0.9.1 of Gradle build tools is probably:
android {
packagingOptions {
pickFirst 'META-INF/services/javax.annotation.processing.Processor'
}
}
For more, see the Android Tools Project page: New Build System.
Edit:
One last note here if you start having problems with generated code, make sure to structure your dependencies properly. I ended up removing any exclusion of the Processor line and structuring my annotation processed dependencies like:
compile "org.parceler:parceler-api:0.2.15"
apt "org.parceler:parceler:0.2.15"
and
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
If after applying above given solutions you still face the same issue as I was, then if you are using glide library then change the version of the glide to it's max.
eg.
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
Good day, i am following this tutorial http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part5 where you have to use HttpTransport but for some reason, android-studio does not seem to find it. I have imported the libraries (some even unnecessary) that are needed but no success. here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.+'
compile 'com.google.http-client:google-http-client-android3:1.9.0-beta#jar'
compile 'com.google.http-client:google-http-client:1.17.0-rc#jar'
compile 'com.google.http-client:google-http-client-android:1.17.0-rc#jar'
compile 'com.google.code.gson:gson:2.1#jar'
compile 'com.fasterxml.jackson.core:jackson-core:2.1.3#jar'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.4#jar'
compile 'com.google.code.findbugs:jsr305:1.3.9#jar'
compile 'com.google.protobuf:protobuf-java:2.2.0#jar'
compile 'com.google.http-client:google-http-client:1.10.3-beta#jar'
compile 'com.google.http-client:google-http-client-android2:1.10.3-beta#jar'
compile 'com.google.http-client:google-http-client-android3:1.10.3-beta#jar'
compile 'com.google.http-client:google-http-client:1.10.3-beta#jar'
compile 'com.google.api-client:google-api-client:1.10.3-beta#jar'
compile 'com.google.api-client:google-api-client-android2:1.10.3-beta#jar'
compile 'com.google.oauth-client:google-oauth-client:1.11.0-beta#jar'
compile 'com.google.guava:guava:11.0.1#jar'
}
anything am not importing or what could be wrong?.. many Thanks in Advance.
Though late, still writing wondering if can help other developers...
The HttpTransport class resides in google-http-client jar. As you have added this dependency in the build.gradle file as shown above, I guess either you don't have network connectivity or your gradle settings is set to offline.
You can download the jar files form https://developers.google.com/api-client-library/java/google-http-java-client/download Unzip the zipped file. Copy the required jar files to the project libs directory & add them as library.