0

构建.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.

提前致谢!

4

1 回答 1

1

implementation 'com.google.android.libraries.places:places:2.0.0' 也将其添加到您的应用程序模块 gradle 中。这不是一个正确的解决方案,但它似乎可以解决问题。我希望谷歌发布一个带有修复的新版本。

于 2019-08-27T14:27:48.547 回答