【问题标题】:Program type already present: android.support.customtabs.ICustomTabsCallback$Stub$Proxy程序类型已经存在:android.support.customtabs.ICustomTabsCallback$Stub$Proxy
【发布时间】:2020-02-22 15:40:09
【问题描述】:

过去 2 天我对这个问题感到震惊。当我尝试生成 APK 时,出现以下错误。请帮助我解决此错误。

Progaurd -详细

-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")
                        }
                    }
                }
            }
        }
    }
}

【问题讨论】:

    标签: android build proguard


    【解决方案1】:

    我在本地项目中使用 Android Studio 3.5.2 + gradle-5.4.1 运行了完全相同的依赖项设置,并成功重现了错误。

    导致问题的原因是什么?

    我无法检测到导致构建失败的确切依赖项。但是,问题更可能与使用没有 AndroidX 的依赖项以及使用 AndroidX 的另一个依赖项有关。

    如何解决?

    根据我的测试,我可以通过将现有的非 AndroidX 依赖项迁移到 AndroidX 来完全解决错误。

    打开 gradle.properties 并添加以下 2 行:

    android.useAndroidX=true
    android.enableJetifier=true
    

    build.gradle 文件中,将所有非 AndroidX 依赖项替换为 AndroidX 依赖项。在我们的例子中替换:

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

    api 'androidx.multidex:multidex:2.0.1'
    

    再次清理并重建项目,所有错误都应该消失了。

    【讨论】:

      【解决方案2】:

      如果有多个相同依赖项的副本,就会发生这种情况。可能有 2 个或更多库可能依赖于相同的依赖关系(可能不同的版本)。

      您可以运行 ./gradlew app:depencencies 并找出其中哪些库正在使用 CustomTabs。

      找到后,您可以选择使用 gradle 文件中的 resolutionStrategy 强制选择特定版本。

      【讨论】:

        猜你喜欢
        • 2019-01-25
        • 1970-01-01
        • 2020-03-24
        • 1970-01-01
        • 2019-11-11
        • 2018-09-23
        • 2019-02-22
        • 1970-01-01
        • 2018-10-21
        相关资源
        最近更新 更多