BoofCV gradle building Errors in Android studio - android

When I integrated BoofCV into Android Studio, the following error happened,
com.android.dex.DexException: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/jdk1.8.0_60/bin/java'' finished with non-zero exit value 2
My build.gradle file is
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.huayu.boofcvandroidstart"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
//multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile group: 'org.boofcv', name: 'all', version: '0.20'
}

Here's how I handled the issue. Include the BoofCV jars as you originally did. Then add the following to your app/build.gradle
configurations {
all*.exclude group: "xmlpull", module: "xmlpull"
}
That will remove the offending xmlpull. You also might want to include the android module, which isn't part of 'all'.
Here's an example on BoofAndroidDemo
https://github.com/lessthanoptimal/BoofAndroidDemo/blob/master/app/build.gradle

I have used BoofCV in one of my projects. You should add all the other BoofCV jars except the XmlPullParser because this jar conflicts with the already existing XmlPullParser present in Android.
I added BoofCV by downloading all the jars and only including the relevant ones like this:
dependencies {
compile files('libs/BoofCV-android-0.19.jar')
compile files('libs/BoofCV-calibration-0.19.jar')
compile files('libs/BoofCV-feature-0.19.jar')
compile files('libs/BoofCV-geo-0.19.jar')
compile files('libs/BoofCV-io-0.19.jar')
compile files('libs/BoofCV-ip-0.19.jar')
compile files('libs/BoofCV-recognition-0.19.jar')
compile files('libs/BoofCV-sfm-0.19.jar')
compile files('libs/BoofCV-visualize-0.19.jar')
compile files('libs/BoofCV-xuggler-0.19.jar')
compile files('libs/core-0.26.jar')
compile files('libs/ddogleg-0.7.jar')
compile files('libs/georegression-0.8.jar')
compile files('libs/xpp3_min-1.1.4c.jar')
compile files('libs/xstream-1.4.7.jar')
}
Although this is a naive way to add the jars you could just include the relevant jars in the libs folder and add this line:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

Related

Android studio 2.3.1 Error converting bytecode to dex

I had just added this dependency(compile 'com.google.guava:guava:21.0') to the gradle and when I try to run the app I get the error below.I tried cleaning the project, but it didn't help me.Can somebody please help me with a solution
Error:
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex 'C:\Users\Zabit\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar' to 'E:\Ohxee\app\build\intermediates\transforms\dex\debug\folders\1000\10\guava-21.0_c8c319a8080e46e7bfc8243fe4c3e3b2a6150f16'
build.gradle(app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.xxxx.xxx"
minSdkVersion 16
targetSdkVersion 25
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'
}
}}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.borax12.materialdaterangepicker:library:1.9'
compile 'com.iceteck.silicompressorr:silicompressor:1.1.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.patrickpissurno:ripple-effect:1.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.android.gms:play-services-maps:10.2.4'
testCompile 'junit:junit:4.12'
compile 'com.roughike:bottom-bar:1.4.0.1'
compile 'com.github.darsh2:MultipleImageSelect:3474549'
compile 'com.google.guava:guava:21.0'
compile 'com.android.support:multidex:1.0.1'
}
The problem is with the Guava/Java version. From Guava version 21 and up the requirement is Java 8 according to the documentation.
Android Studio (and Android to this point) are still on JDK 7 with some of JDK 8 features. Thankfully they provide a Guava flavor for that according to this.
Basically all you have to do is:
compile 'com.google.guava:guava:22.0-android'
Hope this helps.
First Clean the project
Than try Make Project
Now Run the project module

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' while using YouTube API

I'm using the YouTube SDK to play videos in a viewpager. As soon as I run the app, this error is thrown:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/youtube/player/internal/u.class
Manifest.xml:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.xxxxx.www.xxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
mavenLocal()
maven { url "https://jitpack.io" }
}
dependencies {
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 'com.android.support:support-v4:23.1.1'
compile 'com.thefinestartist:ytpa:1.2.1'
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
compile 'com.mxn.soul:flowingdrawer-core:1.2.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.xgc1986.android:parallaxpagertransformer:1.0.3'
compile('com.github.afollestad.material-dialogs:core:0.8.5.7#aar') {
transitive = true
}
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32#aar'
}
I can't include
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
as viewpager uses support library v4
That error comes when any of your jar dependency have same class. Make sure you have not added support jar both as gradle and jar dependency. There might be duplicate references to the same API.
Try ./gradlew yourBuildVariantName --debug from the command line. You can safely remove it from the project or from your build file(s), clean using the command ./gradlew clean and rebuild the project(repeat if necessary).
Check this related SO questions Gradle Duplicate Entry: java.util.zip.ZipException and java.util.zip.ZipException: duplicate entry during packageAllDebugClassesForMultiDex.
I observed the same issue after Android Studio upgrade to version 2.2 Preview 6
Then I deleted lines:
compile(name: 'YouTubeAndroidPlayerApi', ext: 'jar')
and
flatDir { dirs 'libs'}
from two build.gradle files and the issue is gone.
Looks like 'libs' directory is built automatically now but I'm not able to find any confirmation on Google pages.
Add
dependencies {
compile 'com.android.support:support-v4:24.2.1'
}
in build.gradle file.

Duplicate entry using Parse and Multidex

My project is a Chat app that uses Parse. After added other dependencies, this problem started appearing:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 2
Searching here in StackOverflow, some folks told me that it could be the 65K limit from Android.
So, to solve I followed the steps below:
1 - Add Multidex
DefaultConfig {
         multiDexEnabled true
}
and
compile 'com.android.support:multidex:1.0.0'
https://developer.android.com/tools/building/multidex.html
2 - Enable Jumbo Mode in Android Gradle Settings
dexOptions {
jumboMode = true
}
I cleaned the project and ran the gradle build. It did not generate any errors. Great! But when I click "Run app" it generates this error below.
Error: Execution failed for task ': app:
packageAllDebugClassesForMultiDex'. > Java.util.zip.ZipException:
duplicate entry: bolts / AggregateException.class
If I remove the dependency 'com.parse.bolts: bolts-android: 1. +' the "Run app" works, but I can not do without the dependency of Parse.
This is my Gradle build script:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "br.com.triangulum.mink"
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode = true
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile('com.android.support:multidex:1.0.0') {
exclude group: 'com.parse.bolts',
module: 'bolts-android'
}
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: 'Parse*.jar')
compile project('libraries:httprequest')
compile project('libraries:cameralibrary')
compile project('libraries:bgarefreshlayout')
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:palette-v7:+'
compile 'com.android.support:design:+'
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.code.gson:gson:2.2.+'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.afollestad:material-dialogs:0.7.4.0'
compile 'com.getbase:floatingactionbutton:1.10.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'de.greenrobot:eventbus:2.4.+'
compile'com.edmodo:cropper:1.0.+'
compile 'com.github.ksoichiro:android-observablescrollview:+'
compile 'com.etsy.android.grid:library:1.0.5'
compile('com.mikepenz:actionitembadge:3.0.2#aar') {
transitive = true
}
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'com.android.support:multidex:1.0.+'
}
try to change this:
compile('com.android.support:multidex:1.0.0') {
exclude group: 'com.parse.bolts',
module: 'bolts-android'
}
To this:
compile('com.android.support:multidex:1.0.0');
the bolds module is used sometimes to fix Duplicated dexLibs
Regards
Your com.facebook.android:facebook-android-sdk:4.1.0 library is messing with parse as both use same bolts-android module internally and having a different version of this module. Try to exclude this module from any of parse or facebook gradle dependency.
compile('com.facebook.android:facebook-android-sdk:4.1.0') {
exclude group: 'com.parse.bolts',
module: 'bolts-android'
}
I was having the same problem and When I run ./gradlew yourModuleName:dependencies by the terminal, I found exactly which two libraries are messing with each other having a different version of the same module internally.

Error:Execution failed for task ':app:dexDebug'. when integrating projects

I am getting same error every-time I add the following files in gradle.
Error:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:7.3.0'
compile project(':androidHorizontalListView')
compile 'com.ocpsoft:ocpsoft-pretty-time:1.0.6'
compile project(':httpclientandroidlib-1.1.2')
compile 'net.danlew:android.joda:2.7.2'
compile project(':facebook')
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:cardview-v7:22.1.0'
compile 'com.android.support:recyclerview-v7:22.1.0'
compile 'jp.wasabeef:recyclerview-animators:1.2.0#aar'
compile 'jp.wasabeef:picasso-transformations:1.0.5'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okio:okio:1.0.1'
}
I don't know how I can resolve the error.I really appreciate any help.
There has to be a jar file being compiled twice, either add each jar in your libs folder individually:
compile files('libs/yourjarfile.jar')
rather than:
compile fileTree(include: ['*.jar'], dir: 'libs')
or determine the file in your libs folder that is being compiled twice, and remove it keeping the fileTree compilation. Your best bet would probably be to do what I say with compiling each file individually, then looking to see the duplication in the gradle file
I think I also experienced similar problem.
You are using the latest appcompat-v7 22.2.1:
dependencies {
(...)
compile 'com.android.support:appcompat-v7:22.2.1'
(...)
}
Then maybe you should use the same version of CardView and RecyclerView.
dependencies {
(...)
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
(...)
}
At least for me this solution worked.
Remove all the jar files and dependencies and clean project .Now add one by one each jar file and also remove
compile fileTree(dir: 'libs', include: ['*.jar']) .Now Sync,clean and rebuild.Done.

issue in getting dex file while adding google play service and osm jar android

i m implement osm app with google play store so i add below jars.
When i run my project i getting below error
Error Code:2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/googleapis/notifications/json/gson/GsonNotificationCallback;
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)
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.pkg.name"
minSdkVersion 14
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.2.0'
compile project(':mapsForgeForOsmdroid')
compile project(':oSMBonusPack')
compile 'com.android.support:gridlayout-v7:22.2.0'
compile files('libs/picasso-2.5.2.jar')
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-gson:1.20.0'
compile 'com.google.apis:google-api-services-calendar:v3-rev125-1.20.0'
compile 'com.google.android.gms:play-services:7.5.0'
/* compile 'com.google.android.gms:play-services:7.5.0'
compile files('libs/google-api-client-appengine-1.20.0.jar')
compile files('libs/google-api-client-1.20.0 (2).jar')
compile files('libs/google-api-client-gson-1.19.0.jar')
compile files('libs/google-api-services-calendar-v3-rev133-1.20.0.jar')
compile files('libs/google-api-client-android-1.20.0 (1).jar')*/
//compile files('libs/google-api-client-util-1.2.1-alpha.jar')
}
I think OsmBonusPack brings in a copy of Gson. Try adding an exclusion for it.
Edit:
You can find the offending library using
gradle dependencies
once it's located, you can exclude it using (a few examples)
compile('group:artifact:version') {
exclude module: 'cglib' //by artifact name
exclude group: 'org.jmock' //by group
exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
}

Categories

Resources