【问题标题】:Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy程序类型已经存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy
【发布时间】:2019-01-25 20:22:23
【问题描述】:

我知道它可能看起来像 This Question,但我无法使用建议的解决方案修复它,我也无法对此发表评论。 错误是:

Program type already present: 
android.support.v4.app.INotificationSideChannel$Stub$Proxy
Message{kind=ERROR, text=Program type already present: 
android.support.v4.app.INotificationSideChannel$Stub$Proxy, sources=[Unknown 
source file], tool name=Optional.of(D8)}

我正在尝试使用 firebase 创建一个应用程序,这是我的 gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
    minSdkVersion 27
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
aaptOptions {
    noCompress "tflite"
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0-rc01'

// ML Kit dependencies
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-ml-vision:17.0.0'
}
apply plugin: 'com.google.gms.google-services'

我传递每个文件以确保导入是好的,我还添加了

android.useAndroidX = true
android.enableJetifier = false

这是我的项目 Gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath 'com.google.gms:google-services:4.1.0'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我使用 Android Studio 3.1.4

【问题讨论】:

  • 现在,我只是停止使用androidx,它工作得尽可能好,我仍然希望能够找到问题并合并到androidx
  • 我回答了here。希望它对你有用。
  • 感谢@AshuTyagi,我能够迁移。我使用您的solution + Refractor > Migrate to AndroidX。之后,我查看我的导入以手动将它们迁移到 androidx(例如 Nullable)。它编译并运行,但我的应用程序无法再在我的设备上启动,我必须找出原因,但仍然比以前更接近解决方案。
  • libGDX 项目检查这个:stackoverflow.com/a/61377080/5733853

标签: android android-studio gradle androidx


【解决方案1】:

我在尝试迁移到 Android X 时发生了这种情况。背后的原因是并非所有库都已迁移到 Android X。

  • 您可以手动删除依赖项。:尝试查看所有依赖项并找出冲突的依赖项。您可以使用 Android Studio 的 Gradle View 插件或使用菜单中的 类导航。 (在 android Studio 中:Navigation -> class;现在出现一个搜索框并勾选“包含非项目项”;粘贴整个类名创建错误并立即搜索;找出具有此依赖关系的类并手动删除!)。 请检查您是否在仍然使用非 AndoirdX 依赖项的文件中留下了任何导入语句。如果是,请将它们也删除。

  • 在 Android Studio 中,Refractor -> 迁移到 AndroidX

或者(手动方式)

  • gradle.properties 中添加以下内容。
   android.useAndroidX=true
   android.enableJetifier=true

这会使 Android Studio 迁移所有依赖项。更多信息请查看here

【讨论】:

    【解决方案2】:

    我也有类似的问题。就我而言,这是因为我使用的是 Glide 库和 androidx。这个解决方案对我有用:

    1. 将 enableJetifier 值设置为 true
    2. 使用 Gradle 版本 4.9 将 Gradle 构建工具更新到 3.3.0-alpha08

    source

    【讨论】:

      【解决方案3】:

      在我的情况下,只需从

      更改您的 firebase 版本
      implementation 'com.google.firebase:firebase-auth:19.1.0'
      

      到 实施 'com.google.firebase:firebase-auth:16.1.0'

      【讨论】:

        【解决方案4】:

        您可以通过将这些添加到您的 gradle.properties 来更正它

           android.useAndroidX=true
           android.enableJetifier=true
        

        但在某些情况下,它不会像 libGDX 游戏那样在 libGDX 游戏中正常运行,您应该在 build.gradle 中更改这些代码:

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

        对此:

        configurations.getByName("natives").copy().files.each { jar ->
            def outputDir = null
            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-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
            if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
            if (jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
            if (outputDir != null) {
                copy {
                    from zipTree(jar)
                    into outputDir
                    include "*.so"
                }
            }
        }
        

        它将正常工作。

        【讨论】:

          【解决方案5】:

          在 Android Studio 菜单 Navigate --> Class --> All(选中“Include in all places”复选框)键入您的 Class (INotificationSideChannel),您将看到多个依赖包 - 只需删除其中一个它来自你的 gradle.build! 在一个项目中同时使用 android 和 androidx 依赖项时经常会出现问题。

          【讨论】:

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