Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program type already present: android.support.customtabs.ICustomTabsCallback$Stub$Proxy

I am struck in this issue for past 2 days. When I tried to generate APK I am getting the below error. Please assist me in resolving this error.

enter image description here

Progaurd -verbose

-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-dontwarn com.badlogic.gdx.utils.GdxBuild
-dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
-dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild


-keep class com.badlogic.gdx.controllers.android.AndroidControllers
-keep class com.facebook.ads.** { *; }
-dontwarn com.facebook.ads.**

-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
   <init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}

-keepclassmembers class com.badlogic.gdx.physics.box2d.World {
   boolean contactFilter(long, long);
   void    beginContact(long);
   void    endContact(long);
   void    preSolve(long, long);
   void    postSolve(long, long);
   boolean reportFixture(long);
   float   reportRayFixture(long, float, float, float, float, float);
}

build.gradle

apply plugin: 'com.android.application'
android {
    buildToolsVersion '28.0.3'
    compileSdkVersion 29
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        androidTest.setRoot('tests')
    }
    defaultConfig {
        applicationId "XXXXXX"
        minSdkVersion 16
        targetSdkVersion 29

        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt', 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

    repositories {
        mavenCentral()
        jcenter()
}

dependencies {
    api 'com.android.support:multidex:1.0.3'
    api 'com.google.android.exoplayer:exoplayer:r1.4.1'
    api 'com.facebook.android:facebook-android-sdk:4.+'
    /*api 'com.facebook.android:audreleaseience-network-sdk:4.+'*/
    api 'com.facebook.android:audience-network-sdk:5.+'
    api 'com.google.android.gms:play-services-analytics:17.0.0'
    api 'com.google.android.gms:play-services-games:18.0.1'
    api 'com.google.firebase:firebase-core:17.2.1'
    api 'com.google.firebase:firebase-analytics:17.2.1'
    api 'com.google.firebase:firebase-invites:17.0.0'
    api 'com.google.firebase:firebase-ads:18.2.0'
    api 'com.google.ads.mediation:facebook:4.25.0.0'
    api 'com.google.android.gms:play-services-auth:17.0.0'
}


apply plugin: 'com.google.gms.google-services'

// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() { 
    file("libs/armeabi/").mkdirs();
    file("libs/armeabi-v7a/").mkdirs();
    file("libs/arm64-v8a/").mkdirs();
    file("libs/x86_64/").mkdirs();
    file("libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
        if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")        
        if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
        if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if(outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}

task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'math.workout.math.games/math.workout.math.games.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
    }

    classpath {
        plusConfigurations += [ project.configurations.compile ]        
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'       
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}

// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");
        scopes = [ COMPILE: [plus:[project.configurations.compile]]]        

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value:"true")
                        }
                    }
                }
            }
        }
    }
}
like image 251
iappmaker Avatar asked Oct 26 '19 17:10

iappmaker


2 Answers

I ran the exact same dependency setup with Android Studio 3.5.2 + gradle-5.4.1 in my local project and successfully reproduced the error.

What causing the issue?

I couldn't detect the exact dependencies for causing build failure. However, The problem is more likely related to using a dependency without AndroidX along with another dependency with AndroidX.

How to solve it?

From my testing, I could fully resolve the errors by migrating the existing non AndroidX dependencies to AndroidX.

Open gradle.properties and add the following 2 lines:

android.useAndroidX=true
android.enableJetifier=true

In build.gradle file replace all non AndroidX dependencies with AndroidX dependency. In our case replace:

api 'com.android.support:multidex:1.0.3'

with

api 'androidx.multidex:multidex:2.0.1'

Clean and Rebuild the project again and all errors should be gone.

like image 147
Prokash Sarkar Avatar answered Oct 17 '22 20:10

Prokash Sarkar


This happens if there are multiple copies of the same depencencies. THere might be 2 or more libraries that may have dependency on a same depencency(Probably different versions).

You can run ./gradlew app:depencencies and find out which of those libraries are using CustomTabs.

Once you find out, you can choose to force choose a specific version using, resolutionStrategy in your gradle file.

like image 1
Dinesh Avatar answered Oct 17 '22 20:10

Dinesh