How to solve conflict dependence with SKMaps.jar and guava - java

I'm working on a project which use OSM by Skobbler. my project needs to use a Google's library called guava. I have the SKMaps.jar placed on libs/SKMaps.jar, also another jars too. On the other side i got some dependencies like:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.+'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
}
This cause a conflict when you build the project, like this
Error:Execution failed for task ':app:dexPlatoDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/opt/android-studio/sdk/build-tools/21.1.0/dx --dex --no-optimize --output /home/alex/Android/proy/app/build/intermediates/dex/plato/debug --input-list=/home/alex/Android/proy/app/build/intermediates/tmp/dex/plato/debug/inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/common/annotations/Beta;
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:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
As we can see here the conflict arise because SKMaps has a dependence from
Lcom/google/common/annotations/Beta;
And I say SKMaps because i have been doing some tests on a side project to detect which jars has conflicts, and SKMaps.jar and guava combinations has this conflict. Now here is my question:
How can i exclude the guava dependence from SKMaps.jar?
or
Is possible to aisle both jars to not cause conflict?
Thanks

There are 2 options, the first being easier than the second one:
Deleting the Google package from the already compiled 'SKMaps.jar' file
make a backup of the SKMaps.jar file
open the .jar file with an archive reader, for ex. 7zip
from the 3 folders, enter 'com' -> then select the google folder & delete it
close the archive saving it automatcally, there will be no error after this
*BUT you have to ensure the availibility of the Guava library along with the SKMaps.jar in the project (have it included in the lib folder)
Write a gradle script which decompiles the SKMaps.jar and recompiles it with the com/google/ folder excluded (which is basically the same thing as the first option) and including the new jar in the build process
the difference is that this option will not modify the original SKMaps.jar but make a copy of it without the duplicate package
Applying either approach, the project will compile without any problems.

Related

Gradle Dependencies

I'm trying to use JSON Simple to parse a JSON file into Java in a Gradle JavaFX project.
I've tried a few things:
Adding implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' to the build.gradle file. ... Won't let me do import org.json.simple.JSONParser;
Error: error: package org.json.simple does not exist
Adding implementation 'com.googlecode.json-simple:json-simple:1.1.1' to the build.gradle file. ... gives same error as above.
In IntelliJ, I've tried manually downloading and adding the jar file:
First I added a new directory to the root called 'libs' and added the jar file there. Went to File > Project Structure > Libraries > '+' > Java, selected the file and pressed the module I wanted to add it to. Then I added requires json.simple; into the module-info.java file.
IntelliJ does not come up with any errors, but when I do gradle run, it comes up with an error in the modules-info.java file that says error: module not found: json.simple
I have no idea why that last error is happening, I made sure the module was applied to the root as well (Where the modules-info.java file is.
I've tried gradle clean, invalidating caches and removing caches altogether.
If anyone knows why this issue is occuring (or can suggest another way I can parse a JSON file), that would be great!
Thanks in advance.

More than one library with package name 'com.google.android.gms.license'

I'm using angular 4 and ionic 3. Now when i run "ionic cordova run android"
It gives me the following error:
"more than one library with package name 'com.google.android.gms.license'"
My project.property file:
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.android.support:support-v4:27.1.0
cordova.system.library.2=com.android.support:support-v4:27.1.0
cordova.system.library.3=com.android.support:support-v4:27.1.0
cordova.system.library.4=com.android.support:appcompat-v7:25.+
cordova.gradle.include.1=cordova-plugin-firebase/starter-build.gradle
cordova.system.library.5=com.google.gms:google-services:+
cordova.system.library.6=com.google.android.gms:play-services-tagmanager:+
cordova.system.library.7=com.google.firebase:firebase-core:+
cordova.system.library.8=com.google.firebase:firebase-messaging:+
cordova.system.library.9=com.google.firebase:firebase-crash:+
cordova.system.library.10=com.google.firebase:firebase-config:+
My dependencies in build.gradle file :
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile "com.android.support:support-v4:27.1.0"
compile "com.android.support:appcompat-v7:25.+"
compile "com.google.gms:google-services:+"
compile "com.google.android.gms:play-services-tagmanager:+"
compile "com.google.firebase:firebase-core:+"
compile "com.google.firebase:firebase-messaging:+"
compile "com.google.firebase:firebase-crash:+"
compile "com.google.firebase:firebase-config:+"
// SUB-PROJECT DEPENDENCIES END
}
Thanks in advance :)
Please update your build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
changes your version to 2.3.0
its worked for me...
Thanks
Change your project.property file to:
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.android.support:support-v4:27.1.0
cordova.system.library.2=com.android.support:support-v4:25.+
cordova.system.library.3=com.android.support:appcompat-v7:25.+
cordova.system.library.6=com.google.firebase:firebase-core:11.8.0
cordova.system.library.7=com.google.firebase:firebase-messaging:11.8.0
cordova.system.library.8=com.google.firebase:firebase-crash:11.8.0
cordova.system.library.9=com.google.firebase:firebase-config:11.8.0
cordova.system.library.9=com.google.firebase:firebase-auth:11.8.0
cordova.system.library.9=me.leolin:ShortcutBadger:1.1.4#aar
I think your issue comes here:
compile "com.google.gms:google-services:+"
compile "com.google.android.gms:play-services-tagmanager:+"
Rather than importing gms services like this, you should only import specific libraries.
You are using together those both library.
compile "com.google.gms:google-services:+"
compile "com.google.android.gms:play-services-tagmanager:+"
this "com.google.gms:google-services:+" library has all play service libraries.
Remove this dependency "com.google.android.gms:play-services-tagmanager:+" and it will work.
But still This is not a good way to add com.google.gms:google-services:+, because un-necessary you are adding all google's dependency.
Instead of this dependecy you can use specific dependency, for example if you are using map, then use only map play service.
Here is the list of all play service dependency https://developers.google.com/android/guides/setup .
I suggest you add only required dependency instead of play service universal dependency.
If you've already changed version at /android/build.gradle but not work yet. Maybe you need check some library package at node_modules.
Eg: react-native-onesignal also compile some play-services with highest version (they use +) so it can make this issue.
You can put a script at root directory and add {"scripts": {"postinstall": "node changeVersionGoogleService.js"}} in package .json so it can run to auto change your version when you npm install.
This is the script: https://gist.github.com/duytq94/47ef945131b61de538447d449813b3d4
My script at now auto change 'react-native-onesignal',
'react-native-admob',
'react-native-maps',
'react-native-google-sign-in'
None of the solutions discussed here worked for me so I went on to
renamed the /platform/android folder and Remove android platform
add android platform ionic cordova platform add android
faced another issue with facebook due to this which has a solution here where you need to add your app id and name in platforms/android/app/src/main/res/values/strings.xml file
compiled worked fine after that.
The problem occurred for me when upgrading to cordova 7.
just Add :
googlePlayServicesVersion=11.8.0
to your gradle.properties
have fun ...

Add .jar to dependencies in React Native

I am quite new to React Native but I need to create an Android Module for the Honeywell CT50 barcode scanner.
I have created a libs folder in MyApp/android/app as stated in these two SO posts:
Post 1
Post 2
The second post says I must then add the package name to the dependencies something like this:
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile 'com.facebook.react:react-native:0.19.+'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
}
This the part I am struggling with, the formatting of the name. Here's what the contents of the .jar file looks like:
I would like to reference the AidcManager to do this I have tried:
compile "com.honeywell.aidc.AidcManager"
compile "com.honeywell.aidc:AidcManager"
compile "com.honeywell.aidc:"
Each time I get an error during my build saying something like:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.honeywell.aidc:AidcManager:.
Searched in the following locations:
file:/Users/XXX/.m2/repository/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/Users/XXX/.m2/repository/com/honeywell/aidc/AidcManager//AidcManager-.jar
https://jcenter.bintray.com/com/honeywell/aidc/AidcManager//AidcManager-.pom
https://jcenter.bintray.com/com/honeywell/aidc/AidcManager//AidcManager-.jar
file:/XXX/node_modules/react-native/android/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/XXX/node_modules/react-native/android/com/honeywell/aidc/AidcManager//AidcManager-.jar
file:/Users/XXX/Library/Android/sdk/extras/android/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/Users/XXX/Library/Android/sdk/extras/android/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.jar
file:/Users/XXX/Library/Android/sdk/extras/google/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/Users/XXX/Library/Android/sdk/extras/google/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.jar
Required by:
MyApp:app:unspecified
Can anyone point me in the right direction? Many thanks in advance.
Just copy .jar files in libs folder and import classes or packages from it in your .java file. There is no need to reference them in .gradle file.
Answering wayyyyyyy to late, but might be helpful to others who are looking for this answer,
just add .jar in libs, then add below into gradle
implementation files('libs/<YourJarName>.jar')
Or
Right click the jar and select "Add jar to project" option

Gradle Transitive Dependencies from Modules

Disclaimer:
I'm new to Gradle, have read a lot of docs, and I don't know whether my maven-style understanding is tripping me out, or whether it's the sleep dep (kids - don't ask), but I'm still not getting it.
Problem Background:
I have a project that consists of several modules.
One of the modules, let's call it data-structure defines a data structure
Another module, data-structure-fabsearch, defines an implementation for a data source for the data structure, and finally
A third module, fabsearch-common, defines some common data source classes (eg: connection management to a fabsearch data source etc).
The reason I've done it like this is because there's actually another module that also uses the fabsearch-common stuff.
Anyway, my data-structure-fabsearch build.gradle looks something like this:
dependencies {
compile project(:data-structure)
compile project(:fabsearch-common)
}
The fabsearch-common module declares depedencies for the fabsearch api (let's call it fabsearch-api-1.0.0).
So, the dependency tree for data-structure-fabsearch should look like this:
- data-structure-fabsearch
- data-structure
- fabsearch-common
- fabsearch-api-1.0.0
This was all working wonderfully last night. This morning I came to work and all of a sudden those dependencies don't resolve anymore. References to fabsearch-api-1.0.0 classes are no longer found.
What I've Tried
1. In the parent build.gradle:
project(':data-structure-fabsearch'){
apply plugin: 'java'
dependencies {
compile project(path: ':data-structure', configuration: 'compile')
compile project(path: ':fabsearch-common', configuration: 'compile')
}
}
I've tried this with and without the configuration setting.
2. In the data-structure-fabsearch build.gradle file, adding the configuration parameter.
3. Restarting IntelliJ
4. Clicking the refresh icon in the Gradle tool window (repeatedly)
5. Reading all about transitive dependencies in the Gradle user guides
6. Drinking tea (repeatedly)
None of the above work.
What I'm Expecting
I'm expecting that the fabsearch-common dependencies (the fabsearch-api jars) should also be included in the data-structure-fabsearch dependency tree. All references to fabsearch-api classes in data-structure-fabsearch should resolve etc etc.
My Question[s]
Whilst this is possible in Maven, is it possible in Gradle?
What do I have to do to get it to work?
How much sleep dep can you take without dying?
Many thanks for any help.
Turns out the problem wasn't gradle at all. The problem was IntelliJ.
It got it's knickers into a proper twist!
Solution:
1. Close the project in IntelliJ
2. Delete the .idea directory
3. Delete all .iml files and any other IntelliJ cra-useful files
4. Open project in IntelliJ, choose same directory. Problem disappears.

how to fix build.gradle for map application on android

I am developing a basic map example but I'm in trouble with android studio.
I got this error :
Error:(9, 0) Cause: startup failed:build file 'C:\Users\Tugrul\AndroidStudioProjects\ServiceTextSender\build.gradle': 9: expecting '}', found ':' # line 9, column 31.
compile ‘com.android.support:appcompat-v7:+’1 error
And here an error resource from my build.gradle file(dependencies :
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
compile ‘com.android.support:appcompat-v7:+’
compile ‘com.google.android.gms:play-services:3.1.36′
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
How can I fix this? Could you help me please? I'm in trouble with Android Studio. I'm in trouble with this error.
Regarding the error:
Looks like you are adding this to the wrong gradle file, should be added to the app's gradle file (the one in the app's folder), not the module (the top one). The top one specifies the gradle plugin to use and as you have it listed here, I'm assuming you are editing the wrong build-gradle file.
If you instead check in the same directory that contains the src-folder (not inside src) you will find the app's dependencies section where you can add that line.
And/Or you are just using the wrong characters should be ' and not ‘.
Suggested easier solution:
Create a new Google Map Activity using the template when starting a new project, or right click in your project package and choose (in the popup menu):
New -> Google -> Google Maps Activity
And everything will be set up for you.
I think your problem is character error. ' and ‘ are different.
Try change this :
classpath 'com.android.tools.build:gradle:1.3.0'
compile ‘com.android.support:appcompat-v7:+’
compile ‘com.google.android.gms:play-services:3.1.36′
to this
classpath 'com.android.tools.build:gradle:1.3.0'
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:3.1.36'
Edit:
These are gradle Files:
You need to add your
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:3.1.36'
}
lines to Module Specific build.gradle file shown as above.

Categories