I'm currently having an issue in my Android project based on Gradle. My project has two dependencies:
compile project(':Library:lib1')
compile files('libs/libGoogleAnalyticsServices.jar')
libGoogleAnalyticsServices is version v3 for google analytics.
the problem is that lib1 is an old library depending on version v2 of google analytics:
compile files('libs/libGoogleAnalyticsV2.jar')
At the end there's a conflict between both jars (even if v2 should be only visible by lib1) and v2 is taking over v3. In my main module I'm having missing references.
So two problems:
Why is v2 even visible from the main module?
Why is v2 taking over v3?
Ideally I'd like to keep v2 only visible from my lib1 and v3 only visible from my main module.
Any idea?
I don't know much about Android, but I would assume that the situation is the same as for standard Java applications: You can only use one version of a particular library per application, and have to make sure that all code that ships with your application is compatible with that version.
Related
I have the following library for the google maps and it works fine
implementation 'com.google.android.gms:play-services-maps:16.1.0'
But when I try to add this one for location,
implementation 'com.google.android.gms:play-services-location:16.1.0'
the following error occurs
Failed to resolve: com.google.android.gms:play-services-location:16.1.0
Which library for the location should I use?
THANK YOU.
You will get latest gradle dependencies here
https://developers.google.com/android/guides/setup
It is probably because 16.1.0 does not exist for this library. Google Play Services libraries do not always have the same version. So maps might be on 16.1.0 but location might not even have this version.
To get the latest versions, check the official release page: https://developers.google.com/android/guides/releases
And as you are just starting, make sure to use the latest ones:
com.google.android.gms:play-services-location:17.0.0
com.google.android.gms:play-services-maps:17.0.0
Yes, it is a coincident that those versions are currently the same. As you can see in the list there are already libraries on 19.0.0, like appindexing
com.google.firebase:firebase-appindexing:19.0.0
Edit
A small practical tip: If you replace the version by + and sync the project, gradle will get the newest one and afterwards you can use the IDE warning to replace the + again with the newest version number. That eases a bit the checking on different pages if there is a new version or not etc
My Android app has been successfully using maps by including the following in my gradle ...
compile project(':googleplayservices_lib')
My SDK manager says I have rev 32 which appears to be the latest. So with this, everything has been working just fine.
Now I'm enhancing the app and I saw some posts that says I can now use zIndex parameter when adding a marker to control the Z Index. But to do this I must add the following to my gradle . . .
compile 'com.google.android.gms:play-services-maps:9.2.0'
So now my gradle file has this dependencies section . . .
dependencies {
compile project(':library')
compile project(':googleplayservices_lib')
compile files('libs/gson-2.2.4.jar')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:design:22.2.1'
compile 'com.google.android.gms:play-services-maps:9.2.0'
}
Now I'm able to set zIndex but this new version apparently comes with breaking changes. For instance the following no longer works . . .
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
map is a GoogleMap. The compiler cannot resolve the getMap() method. My problem is that I can't seem to locate the documentation on this new maps revision where it discusses breaking changes for this new version. Does anyone know where I can find such information?
My Android app has been successfully using maps by including the following in my gradle
Presumably, that is an in-project copy of the old Eclipse library project edition of the Play Services SDK. Ideally, you would have moved off of that to the Play Services SDK artifacts back when you moved to Android Studio.
My SDK manager says I have rev 32 which appears to be the latest
Since you are using a local in-project copy, what the SDK Manager reports is not directly relevant.
Also, Google has not been maintaining that library project for at least the past several months, so "latest" of that library is meaningless with respect to using the latest version of the Play Services SDK.
So now my gradle file has this dependencies section . . .
I am surprised that compiles. Remove compile project(':googleplayservices_lib'). If you are using parts of the Play Services SDK beyond Maps V2, use appropriate and compatible artifacts for those APIs as well.
The compiler cannot resolve the getMap() method.
getMap() was deprecated about 20 months ago, in favor of getMapAsync().
My problem is that I can't seem to locate the documentation on this new maps revision where it discusses breaking changes for this new version.
Maps V2 release notes are in the Play Services documentation. A subset of Maps V2 release notes are incorporated in the overall Play Services release notes.
I would like to include libraries of different versions in my Google Project.
For example, I'm using
compile "com.google.android.gms:play-services-base:6.5.87"
compile "com.google.android.gms:play-services-location:6.5.87"
compile "com.google.android.gms:play-services-maps:6.5.87"
I would like to include
compile 'com.google.android.gms:play-services-identity:7.5.0'
as well, but I get compiler errors that analytics and gcm classes can't be found.
Is the only solution to upgrade all the libs to 7.5.0? Is it possible to use different versions of Google Play Services libs? I would like to know what are all the different solutions.
The list of selective APIs includes all of the available APIs. For GCM, you'd need the play-services-gcm library included.
However, all APIs you include must be from the same version of Google Play services - all must be 7.5.0 or all 6.5.87.
I am try to use the new android multidex support for a project. I have some problem with this exception:
Error:Execution failed for task ':shineV3:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/google/android/gms/analytics/internal/Command$1.class
about the problem. I use 2 different jar package as dependency, and some class will be duplicated in classes.dex because both jars contains they. any idea?
thanks in Advance
For those that are coming into this, I figured out why this was happening. For me it was that I was compiling the Google Analytics V2 jar as well as the full play services. Google allows you to break down what play services you really need for you app and compile those individual items. Check them out here. I excluded the Google Play Analytics which is on V4 right now and it worked
If you are integrating Google Analytics V2 and Google play services in your app, then you need to do the following in your gradle file:
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile files('libs/libGoogleAnalyticsServices.jar')
}
It worked for me. Hope it will work for others too. :)
adding this to your grdale compile "com.google.android.gms:play-services:7.5.+" means adding all play services including analytics, maps, vcm .. etc. you can add
as guides mentions:
In versions of Google Play services prior to 6.5, you had to compile
the entire package of APIs into your app. In some cases, doing so made
it more difficult to keep the number of methods in your app (including
framework APIs, library methods, and your own code) under the 65,536
limit.
From version 6.5, you can instead selectively compile Google Play
service APIs into your app. For example, to include only the Google
Fit and Android Wear APIs, replace the following line in your
build.gradle file:
compile 'com.google.android.gms:play-services:7.5.0' with these lines:
compile 'com.google.android.gms:play-services-fitness:7.5.0' compile
'com.google.android.gms:play-services-wearable:7.5.0'
https://developers.google.com/android/guides/setup
I'm adding a wear module to an app. (using this sample code as a reference)
So I have 3 modules, each one depends on a version of com.google.android.gms:play-services:
app - compile 'com.google.android.gms:play-services:6.1.11'
wear - 'com.google.android.gms:play-services-wearable:6.5.+'
shared - compile 'com.google.android.gms:play-services:6.1.11'
When compiling the Wear module, I get this error:
Error:Execution failed for task ':wear:processDebugResources'.
Error: more than one library with package name 'com.google.android.gms'
You can temporarily disable this error with android.enforceUniquePackageName=false
However, this is temporary and will be enforced in 1.0
Obviously, if I change play-services-wearable play-services in the wear module's build.gradle, everything works fine, however from what I understand, play-services-wearable is a light-weight version of play-services.
Is there a way, considering my app's structure, to use play-services-wearable in my wear module?
The issue is more that you have multiple different versions of Google Play Services being used within the same app (version 6.1 and version 6.5). You can update your shared (and app) modules to use compile 'com.google.android.gms:play-services:6.5.+ and then you'll only have one version of Google Play Services and avoid the issue you are facing.
In your case, you only need to define Google Play Services in the shared module - assuming your app and wear modules both have a dependency on it, they'll automatically inherit any dependencies so redeclaring them is unnecessary (although it doesn't harm things if you prefer to do it anyways).
Note: the play-services-wearable library is one of the many split libraries available in Google Play Services 6.5 - these do indeed allow you to only include the parts of Google Play Services you need in your application. In almost all cases, you should consider moving to explicitly depending on only the parts of Google Play Services rather than using com.google.android.gms:play-services in its entirety: by including the entire com.google.android.gms:play-services even once you pull in all of Google Play services even if later you declare or use a single portion of the library.