@Xianwei's answer is working, but it is good to always improve our code over time, since there will always a new, better and simpler implementation. Basically it is more detail and improvement from @Xianwei's answer.
Add google()
repository in your top-level build.gradle
allprojects {
repositories {
jcenter()
google()
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
// An alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Add places google play service dependency in your app-level build.gradle
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// Your other dependencies...
implementation 'com.google.android.gms:play-services-places:x.x.x'
}
Where x.x.x is the newest version of play-services-places
, current working version is 15.0.1.
You can check the newest version in the official documentation here