3

I want to learn more about Google Maps API, so I decided to create a Google Maps Activity type of project. Immediately after the creation of project, without changing anything in code, I've got message:

ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:12:5-41:19 to override.

I've followed tutorial from https://developers.google.com/maps/documentation/android-sdk/start, so I've updated environment with the newest available SDK and generated API key (which I've inserted in google_maps_api.xml).

What I've found from your website as possible solution is addition of following code segment at the end of app module 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'
            }
        }
    }
}

but after that, I've got error:

Inconvertible types; cannot cast 'android.support.v4.app.Fragment' to 'com.google.android.gms.maps.SupportMapFragment'

for following line:

SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);

Here is how my activity_maps.xml and MapsActivity.java look like:

<?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" />
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;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

I am really desperate at this moment, because I've literally tried everything that I know. I've expected to start from this Hello world project provided by Android studio and to build something more complex, but it seems it doesn't work. Please, I really need help. Thanks in advance

Zoe
  • 27,060
  • 21
  • 118
  • 148
Darian Pudic
  • 45
  • 2
  • 10
  • let me see your AndroidManifest.xml file – Felipe Andrade Jun 19 '19 at 18:10
  • Felipe, here is a link to Google Drive share. Since the content of AndroidManifest.xml is too large for comment, I've uploaded it to Google Drive: https://drive.google.com/open?id=1HuNRFfGP5nkpaoOOMDzaViZbw0XmhX0m – Darian Pudic Jun 19 '19 at 18:20
  • You can edit your question to include more info. I didn't see anything wrong with your manifest, let me see your activtiy and fragment layout – Felipe Andrade Jun 19 '19 at 18:26
  • Maybe this tutorial can help you: https://code.luasoftware.com/tutorials/android/supportmapfragment-in-fragment/ – Felipe Andrade Jun 19 '19 at 18:32
  • Felipe, I've edited question, so you may find there how activity and fragment layout look like. I will also take a look at the tutorial :) – Darian Pudic Jun 19 '19 at 18:42
  • Unfortunately, tutorial that you provided didn't help :( Some new errors are popping up. My feeling is that example that Android Studio provided must work, I am convinced that they wouldn't publish something that doesn't work. Error must be somewhere in gradle or SDK or something third, but I don't know what that could be. Did you take a look at my latest edit? – Darian Pudic Jun 19 '19 at 19:12
  • Here is overcome for this situation: avoid using Google Maps Activity project proposed by Android studio. Instead of that, do it from scratch (follow this tutorial): https://www.youtube.com/watch?v=eiexkzCI8m8 – Darian Pudic Jun 19 '19 at 20:25
  • Possible duplicate of [Manifest Merger fails for appComponentFactory](https://stackoverflow.com/questions/52135251/manifest-merger-fails-for-appcomponentfactory) – Zoe Jun 20 '19 at 11:45

4 Answers4

6

It's just a workaround but I made it work in the following way. In build.gradle(Module:app) file under Gradle Scripts in the Android Studio, in the following lines of code:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

In the line implementation 'com.google.android.gms:play-services-maps:17.0.0', I changed the version from 17.0.0 to 16.0.0 and so the line became

implementation 'com.google.android.gms:play-services-maps:16.0.0'

And it worked. The error was not there anymore.

I had created an app using the Google Map Activity on 19-Jun-2019 and it worked just fine but when I tried to do so on 20-Jun-2019 I got the same error. So I tried comparing the two projects and ran into this. I am very new to all these so I don't know much about it, but it worked.

Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Mrinal Das
  • 61
  • 3
5

In order to use play-services-maps 17.0.0, you have to build against androidx dependencies.

android.support.v4.app.FragmentActivity -> androidx.fragment.app.FragmentActivity.

In order to migrate, every single com.android.support dependency needs to be substituted.

The release notes confirm this - downgrading to 16.0.0 is the other option available.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
1

use version 16 of google maps service and version 16 of location service too . This worked in my case implementation 'com.google.android.gms:play-services-maps:16.0.0' implementation 'com.google.android.gms:play-services-location:16.0.0'

Anish Yadav
  • 191
  • 1
  • 4
0

If u are using older version of Android Studio then u must have to update it to 3.4.1.
u have to update sdk [to compileSdkVersion 29] gradle [to gradle-5.1.1].
or
if u are not interested to update your IDE then use previous version of maps library and that is
implementation 'com.google.android.gms:play-services-maps:16.1.0'