Depend gradle build on google maps only - android

My project depends on maps. So I have compile 'com.google.android.gms:play-services-maps:7.0.0' in my build.gradle file. But gradle downloads all the play services, including fitness, games, wallet, etc. How to depend just on map and it's dependencies, but not the whole play-services?

Ok, I found a problem. The issue was that gradle was configured to work in offline and for unknown reason it was adding all the play-services into the project (perhaps, because full play-services was the only downloaded dependency, that contained play-services-maps).
Allowing gradle to work online and doing gradle sync — and viola, now only play-services-base and play-services-maps are dependencies.

Related

error: package com.google.android.gms.ads.identifier does not exist when deploying to target

I'm a bit new to the Gradle build system. My app already had some working integrations with Google Play Services, including the Ads library. I'm trying to add the Android Nearby service to my build.gradle, but the import for the ads library no longer works specifically after I added in the Nearby library.
In my build.gradle:
dependency {
implementation "com.google.android.gms:play-services-nearby:$rootProject.ext.playServicesLibraryVersion"
}
playServicesLibraryVersion is 15.0.1, which is the latest. The project builds successfully, but the errors arise specifically when I'm deploying to target. My target device is running Android P and I'm using Android Studio 3.1.2.
If I add implementation "com.google.android.gms:play-services-ads:$rootProject.ext.playServicesLibraryVersion" I get a Multiple Dex error.
Any ideas?
Update: issue was resolved when I did a clean build, invalidated cache, and used api instead of implementation in the build.gradle. I added both libraries to my dependencies.

Google play services version automatically changes to 11.8

Recently i upgraded my project to android studio 3
In my build.gradle , i have: compile "com.google.android.gms:play-services-maps:10.2.1"
So it must use gms 10.2.1 , but in "#integer/google_play_services_version" i have following:
<integer name="google_play_services_version">11910000</integer>
And in the project --> External libraries i can clearly see that it compiles gms version 11.8:
Why this happens?
Use ./gradlew dependencies to check the dependency tree.
You are simply using a library that has a dependency with 11.8.0 and gradle uses the newest version.

How does Gradle choose between more than 1 versions of the same library in a gradle tree?

Let say I have added Facebook and Twitter dependencies in my app.
com.facebook.android:facebook-android-sdk:4.22.1
com.twitter.sdk.android:twitter:2.1.0
When i look at Gradle tree, They come up with bunch of other transitive dependencies.
Now If Facebook uses com.android.support:support-annotations:24.1.1 and twitter uses com.android.support:support-annotations:25.0.3
Then which version gradle will use.
In gradle tree, It shows -> in front of older version of dependency. I learnt that this means gradle will use the newer version, and will not use the older version.
But this can be a problem, because some libraries are meant to run on the specific versions, and i have faced this problem.
In one of article i found out how npm manages these dependencies conflicts, but i am still unsure how gradle will manage between different version of same library.
You can't have different versions of the same library inside an apk.
As you mentioned, by default, Gradle puts the newest one to the build. If you want to specify a concrete version of the library that should be used in your project, you can add a direct compile (or implementation / api for Android Gradle Plugin v3+) statement with a required version to get one.
Also, you can force version using a special syntax, but it can lead to some problems later. You can find more information about version conflicts resolution in this post

Compile latest google play-services as dependency in build.gradle file

Am using a Java plugin as I am building a very simple SDK for users to fire an HTTP request from their android phone.
My SDK is packages as a JAR which other users can import in their app and use the methods to fire the request.
I use Grade to build my project and get the Jar file. Until now, I was using a older version of Google Play-Services which had a jar file in my android_home/extras/google/google_play_services/libproject/google-play-services-libs/libs
But I upgraded my Google Play Services to latest version I see this path is no longer available. I see a new path and the packaging is changed to .aar.
I tried to follow some of the methods specified in this forum to convert this .aar file into jar and use it as a dependancy but when I unzip I could not see any classes.jar inside this .aar. I could only see AndroidManifest.xml and R.txt
I am unable to use compile fileTree option in Gradle. Please help me on how can I build my project or what modifications I need to do on my build.gradle file?
Current hack that I am doing is manually download the jar file from:
https://dl-ssl.google.com/android/repository/google_play_services_3159130_r09.zip and using compile fileTree option. I need to get rid of this manual step.
Looking for suggestions.

Execution failed for task ':packageAllDebugClassesForMultiDex'

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

Categories

Resources