0

I am using sample google map V2 in my app. In gradle file if I using below lib its working fine but need to implement Multi Dex

 implementation 'com.google.android.gms:play-services:12.0.1'

If I using only google map service it's not able to generate build,I am getting error in Android Manifest

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

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:15:17-25:19 to override.

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.my.samplemap"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            multiDexEnabled true
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
//   implementation 'com.google.android.gms:play-services:12.0.1'(Not getting error but need to enable multi dex)
    implementation 'com.google.android.gms:play-services-maps:17.0.0'(getting error)
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

error in code if using maps lib,refer image below

enter image description here

appukrb
  • 1,507
  • 4
  • 24
  • 53
  • Post your gradle file, then it will be easy to understand the problem – Teja Jul 16 '19 at 07:41
  • you can add 'tools:replace="android:appComponentFactory" is yout manifest to get rid of the problem. it will override the default value set from map dependency. – darwin Jul 16 '19 at 07:51
  • check this https://stackoverflow.com/questions/51793345/android-material-and-appcompat-manifest-merger-failed/53202089 – darwin Jul 16 '19 at 07:52
  • @darwin when adding tools:replace getting error: incompatible types: Fragment cannot be converted to SupportMapFragment – appukrb Jul 17 '19 at 05:51
  • which is not related to this issue, you must use SupportMapFragment if instead of Fragment in your code – darwin Jul 17 '19 at 05:58
  • @darwin see the attached image – appukrb Jul 17 '19 at 06:16
  • you should use as map container in your xml file, then it can be cast to supportMapFragment – darwin Jul 17 '19 at 06:27
  • @darwin same code I used in my xml – appukrb Jul 17 '19 at 06:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/196550/discussion-between-darwin-and-appukrb). – darwin Jul 17 '19 at 06:41

1 Answers1

0

Actually The error is related to new Android Studio version. So the solution is you must migrate your project to Android X. The issue will solved automatically.

 Refactor -> Migrate to AndroidX

May be it can cause some error, but as per new update this is mandatory to move into AndroidX

Mayur Coceptioni
  • 433
  • 4
  • 17