Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While I migrate from Android to AndroidX , Error in implementing google play services in my projects. What might be the solution?

Here is my app level build.gradle

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
//apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "threecallistos.jumperr"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'com.google.android.material:material:1.0.0-alpha3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'androidx.multidex:multidex:2.0.0'
}

and gradle.properties is here

org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true

When I remove

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

From app.build file it works fine. But I have to work with google maps and services, so I searched here and there but couldn't find any proper solution. I found one suggestion in github as

I believe this is because com.google.firebase transitively depends on com.android.support:support-v4. To address this you should be able to set android.enableJetifier=true in your gradle.properties file, which will "automatically convert existing third-party libraries as if they were written for AndroidX"

and I already did this but doesn't work!

I got error when I build/ run the project

Program type already present: android.support.v4.app.INotificationSideChannel Message{kind=ERROR, text=Program type already present: android.support.v4.app.INotificationSideChannel, sources=[Unknown source file], tool name=Optional.of(D8)} Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

Please give me some solution.

like image 330
Ramesh Pokharel Avatar asked Jul 31 '18 14:07

Ramesh Pokharel


People also ask

How to migrate project to AndroidX in Android Studio?

Migrate an existing project using Android Studio With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar. The refactor command makes use of two flags. By default, both of them are set to true in your gradle.

Can I use library that used Android support with AndroidX projects?

Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components. You can continue to use the support library.

Why we need to migrate to AndroidX?

The Android Support Library has reached the end of its life. 28.0 was the last release of the Android Support namespace and the namespace is no longer maintained. So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX.


1 Answers

There has been multiple questions with completely different errors that actually all derive from migrating to AndroidX libraries in Android Studio v3.1. I was getting all sorts of weird errors that just could not be resolved without reverting back to Support libraries. Therefore, you may see this same answer for different questions. Because the questions are about errors that differ so greatly in description and context, they are not duplicate questions and therefore all should be answered with this solution. Ironically this explanation is longer than the solution, and was included to help admins understand.

The solution is: Android Studio v3.2+ resolves this issue. It also adds a "Migrate to AndroidX" item under the Refactor menu to make the migration easier. No work-around or rollback required. It is important to migrate to AndroidX libraries, as the old support libraries will end after stable v28 Support libraries are released.

Update Android Studio from the beta channel to use 3.2+ or wait until a stable version is released in the very near future.

EDIT: 9/25/18 - the v3.2 stable version is now available in the stable channel.

like image 193
Always Lucky Avatar answered Sep 21 '22 17:09

Always Lucky