小编Dar*_*dic的帖子

收到错误消息:清单合并在创建Google Maps Activity项目后失败

我想了解有关Google Maps API的更多信息,因此决定创建一个Google Maps Activity类型的项目。在创建项目之后,没有更改任何代码,立即收到消息:

错误:清单合并失败:[com.android.support:support-compat:28.0.0]的属性application @ appComponentFactory value =(android.support.v4.app.CoreComponentFactory)也是AndroidManifest.xml:22:18-91出现在[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value =(androidx.core.app.CoreComponentFactory)。建议:在AndroidManifest.xml:12:5-41:19的元素上添加'tools:replace =“ android:appComponentFactory”'以进行覆盖。

我已经按照https://developers.google.com/maps/documentation/android-sdk/start上的教程进行操作,因此,我已使用最新的可用SDK和生成的API密钥(已插入google_maps_api中)更新了环境。 xml)。

我从您的网站找到的可能解决方案是在应用程序模块build.gradle的末尾添加以下代码段

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是之后,我出现了错误:

不可转换的类型;无法将“ android.support.v4.app.Fragment”转换为“ com.google.android.gms.maps.SupportMapFragment”

对于以下行:

SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
Run Code Online (Sandbox Code Playgroud)

这是我的activity_maps.xml和MapsActivity.java的样子:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />
Run Code Online (Sandbox Code Playgroud)
package com.example.myapplication;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback; …
Run Code Online (Sandbox Code Playgroud)

android

2
推荐指数
2
解决办法
2016
查看次数

标签 统计

android ×1