I got a Gradle Error:
Error converting bytecode to dex: Cause: com.android.dex.DexException:
Multiple dex files define Lcom/coremedia/iso/AbstractBoxParser$1;I
want to used both isoparser-1.0.6.jar and compile
'com.googlecode.mp4parser:isoparser:1.+'
for my development purpose.My Gradle given below
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.googlecode.mp4parser:isoparser:1.+'
compile 'org.apache.commons:commons-io:1.3.2'
compile files('libs/aspectjrt-1.7.3 (1).jar')
compile files('libs/isoparser-1.0.6.jar')
}
Multiple dex files define Lcom/coremedia/iso/
You don't need the JAR files. The fact that you are using them is causing duplicate files, which Gradle can resolve on its own, but only when using Maven dependencies.
You compiled this ISO parser library already . And it depends on aspectjrt, so you don't need to explicitly compile that unless you really want to
https://mvnrepository.com/artifact/com.googlecode.mp4parser/isoparser/1.0.6
compile 'com.googlecode.mp4parser:isoparser:1.0.6'
compile 'org.aspectj:aspectjrt:1.8.2' // This version is used by isoparser:1.0.6
// compile files('libs/aspectjrt-1.7.3 (1).jar')
// compile files('libs/isoparser-1.0.6.jar')
You need to actually delete the JAR files because this line will compile them anyway. In other words, putting compile files() was redundant
compile fileTree(dir: 'libs', include: ['*.jar'])
Related
Say I have a library module which contains some 3rd party libraries like OkHttp. When I include this library in my application I was unable to use these 3rd party libraries. I read the following articles Article 1,
Article 2
and tried
1. compile project(':library-name')
{after importing the .aar file(of library) as a module into myproject}
2. I included the .aar file in libs folder and added following dependencies
build.gradle(project level)
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
build.gradle(application level)
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.myapp.package:library-name:1.0.0#aar'){
transitive=true
}
3. similar to 2nd but in
build.gradle(application level)
compile fileTree(dir: 'libs', include: ['*.jar'])
compile (name:'library-name', ext:'aar'){
transitive=true
}
But, still I was unable to use the transitive libraries which are present in my library. I am getting following exception.
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/MediaType;
Can someone help
EDIT:
The following is build.gradle of my library
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'org.apache.httpcomponents:httpcore:4.4.4'
compile 'org.apache.httpcomponents:httpclient:4.5.1'
compile 'com.squareup.okhttp:okhttp:2.6.0'
compile 'petrov.kristiyan.colorpicker:colorpicker-library:1.0.3'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.hamcrest:hamcrest-library:1.1'
compile files('notificationlog-0.1.0.jar')
I was able to use the notificationlog in my application which was a dependency in my library, but I was unable to use okhttp and colorpicker
The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
It doesn't make sense:
compile (name:'library-name', ext:'aar'){
transitive=true
}
because the aar is without a pom file which describes the dependencies, then gradle is unable to add any dependencies because it can't know them.
I have imported two libraries in my Android Studio project through gradle. One is support library v7 which is a necessary component to handle action bar in my app for different platforms. Another is the one I intent to use for UI components called MaterialDesign.
Problem is that both libraries have defined an attribute in their values.xml called rippleColor and gradle identifies the conflict.
How can I tell gradle to exclude one definition and accept the other?
Manifest Merging in android developers hub seem to do that over the entire xml file whereas my problem is only one specific attribute in that file.
Is there any way that I can get around this problem?
P.S. my gradle dependencies are as follows:
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'org.xwalk:xwalk_core_library:15.44.384.13'
compile 'com.github.navasmdc:MaterialDesign:1.5#aar'
Write below code in your grade file. It might help:
dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile 'com.google.code.gson:gson:2.2.2'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile fileTree(dir: 'libs', include: '*.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
}
I want to build my app while flashing custom ROM on the device. I'm trying to find proper way to include project dependencies in the Android.mk. My dependencies look like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.timehop.stickyheadersrecyclerview:library:0.4.2#aar'
How to put it into the makefile? As static libraries? Or maybe as extra packages? Waiting for your help!
Earlier this week Android Studio started randomly deleting dependencies from my build.gradle file whenever I create a new file.
Is there a particular order that's expected?
My dependencies section looks like this:
dependencies {
compile project(':ParallaxScroll')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:4.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.android.support:support-v13:19.+'
compile 'com.android.support:appcompat-v7:19.+'
compile group: 'com.squareup.picasso', name: 'picasso', version: '2.2.0'
compile group: 'com.squareup.retrofit', name: 'retrofit', version: '1.4.1'
compile 'com.github.gabrielemariotti.cards:library:1.5.0'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.crashlytics.android:crashlytics:1.+'
}
When I create a new activity in the project it ends up looking like this (this happens every time):
dependencies {
compile project(':ParallaxScroll')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile group: 'com.squareup.picasso', name: 'picasso', version: '2.2.0'
compile group: 'com.squareup.retrofit', name: 'retrofit', version: '1.4.1'
compile 'com.google.android.gms:play-services:4.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.android.support:support-v13:19.+'
compile 'com.android.support:appcompat-v7:19.+'
}
It took a little while to figure out what was happening.
Which of the two compile formats I'm using is correct? Is this potentially causing issues? It wasn't an issue until this week.
I can of course restore my dependencies but this doesn't explain why AS is deleting things all the time.
I'm also concerned about both support libraries being included. As far as I know I'm using only v4 stuff. Is using both bad practice?
This is a bug that will be fixed in 0.5.9. You can track it here:
https://code.google.com/p/android/issues/detail?id=60749
In the meantime, as a workaround, just create new activities by hand, or save off the contents of the build file before creating them through the wizard.
I was trying to integrate my project in android studio. but i am little confused when adding dependencies. I don't know which one is works good.I have tried Compile fileTree and compile files.Its not working for me . I found some methods.can any one tell me which one is appropriate for adding library (jar file only like admob).
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:+'
compile project(":libraries:libraryname")
compile files('libs/libraryname.jar')
can any one tell me which one is appropriate for adding library (jar file only like admob).
If the library is available as an artifact in a Maven or Ivy repository, like Maven Central, add the repository to your repositories block (e.g., mavenCentral()) and then use compile 'com.android.support:appcompat-v7:+', replacing the quoted string with the one that identifies the artifact that you want.
If the library is not available as an artifact, put the JAR in the appropriate directory (e.g., libs/ at the project level) and use compile fileTree(dir: 'libs', include: '*.jar').
compile project(":libraries:libraryname") is for sub-projects, which you probably do not have.
compile files('libs/libraryname.jar') works, but compile fileTree(dir: 'libs', include: '*.jar') is more flexible, as you do not have to change your build.gradle file for every JAR.