构建.gradle
dependencies {
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.libraries.places:places:2.0.0'
}
功能模块清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
xmlns:tools="http://schemas.android.com/tools"
package="com.demo.app">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<dist:module
dist:instant="false"
dist:onDemand="false"
dist:title="@string/title_feature_module">
<dist:fusing dist:include="true" />
</dist:module>
<application>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="12451000"
tools:replace="android:value" />
<activity android:name=".presenter.MainActivity">
<intent-filter>
<action android:name="action.demo.open" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".presenter.map.MapsActivity"
android:label="@string/title_activity_maps" />
<service
android:name=".service.FetchAddressIntentService"
android:exported="false" />
</application>
执行
private fun startAutocompleteActivity() {
val fields = listOf(
Place.Field.ADDRESS,
Place.Field.ADDRESS_COMPONENTS,
Place.Field.ID,
Place.Field.LAT_LNG,
Place.Field.NAME
)
if (!Places.isInitialized())
Places.initialize(applicationContext, getString(R.string.google_maps_key))
val intentPlacePicker = Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields)
.build(this)
startActivityForResult(intentPlacePicker, KeyUtils.REQUEST_PLACE_PICKER)
}
我遇到了以下问题
Android resource linking failed
/app/build/intermediates/merged_manifests/mockDebug/AndroidManifest.xml:98: error: resource string/places_autocomplete_label (aka com.demo.app.mock:string/places_autocomplete_label) not found.
/app/build/intermediates/merged_manifests/mockDebug/AndroidManifest.xml:98: error: resource style/PlacesAutocompleteThemeOverlay (aka com.demo.app.mock:style/PlacesAutocompleteThemeOverlay) not found.
error: failed processing manifest.
提前致谢!