开发者社区> 问答> 正文

添加Firebase和OneSignal SDK后出现Unity错误:“重复的类android.su

我通常使用IL2CPP(支持64位)使用Unity 2017.4.34f1构建我的项目。首先,将项目导出到Android Native Project,因为我想在AndroidManifest.xml中删除一些权限。

使用以下build.gradle配置,构建通常会成功生成APK。

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
    repositories {
        jcenter()       
        google()
        mavenCentral()
        maven {
            url "https://jitpack.io"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
    }
}

allprojects {
   repositories {
      google()
      jcenter()
      maven {
           url "https://jitpack.io"
      }
      flatDir {
        dirs 'libs'
      }
   }
}


apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    implementation(name: 'GoogleAIDL', ext:'aar')
    implementation(name: 'GooglePlay', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-drive-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-games-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-gcm-12.0.1', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-iid-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-nearby-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-tasks-11.0.4', ext:'aar')
    implementation(name: 'common', ext:'aar')
    implementation(name: 'unity-ads', ext:'aar')
    implementation project(':GoogleMobileAdsPlugin')
    implementation project(':common_lib')
    implementation project(':youtube_lib')
}

android {
    compileSdkVersion 29
    buildToolsVersion '21.1.1'

    task removeBuildConfig(dependsOn: "compileReleaseSources") {
        doFirst {
            file("$buildDir/intermediates/classes/release/pathToFile/BuildConfig.class").delete()
        }
    }

    defaultConfig {
        targetSdkVersion 29
        applicationId 'com.snowyenglish.flashcard'

        minSdkVersion 19
        multiDexEnabled true
        versionCode 508
        versionName "1.2.508"
        ndk {
          abiFilters 'armeabi-v7a','arm64-v8a'
        } 
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb'
    }

    signingConfigs { release {
        storeFile file('/Users/zukinaru/Dropbox/SNOWY_KEY/snowy_flashcard_english.keystore')
        storePassword 'xxx'
        keyAlias 'my snowy beta'
        keyPassword 'xxx'
    } }

    buildTypes {
        debug {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt','proguard-user.txt'
            jniDebuggable true
        }
        release {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt','proguard-user.txt'
            signingConfig signingConfigs.release
        }
    }

}

但是,添加了Firebase(分析和崩溃分析)和OneSignal SDK之后。生成成为错误:

原因1:java.util.concurrent.ExecutionException:java.lang.RuntimeException:在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0中找到重复的类android.support.v4.app.INotificationSideChannel )和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)重复的类android.support.v4.app.INotificationSideChannel $ Stub在模块core-1.0.0-中找到runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)复制类android.support.v4.app .INotificationSideChannel $ Stub $ Proxy在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support- compat:27.1.1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0。)中找到了重复的类android.support.v4.os.IResultReceiver。0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)在模块core-1.0.0中找到重复的类android.support.v4.os.IResultReceiver $ Stub -runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)复制类android.support.v4。在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support)中找到os.IResultReceiver $ Stub $ Proxy -compat:27.1.1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-中找到重复的类android.support.v4.os.ResultReceiver runtime.jar(com.android.support:support-compat:27.1.1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0)中找到重复的类android.support.v4.os.ResultReceiver $ 1 。0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)在模块core-1.0.0中找到重复的类android.support.v4.os.ResultReceiver $ MyResultReceiver -runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)复制类android.support.v4。 os.ResultReceiver $ MyRunnable在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat)中找到:27.1.1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1)中找到ResultReceiver $ MyRunnable .1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1)中找到ResultReceiver $ MyRunnable .1)

转到文档以了解如何修复依赖性解析错误。在com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:102)在java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)在com.android.build.gradle.internal.tasks .com.android.build.gradle.internal.tasks.CheckDuplicateClassesTask.doTaskAction(CheckDuplicateClassesTask.kt:61)的.CheckDuplicateClassesDelegate.run(CheckDuplicateClassesDelegate.kt:67)在com.android.build.gradle.internal.tasks.NonIncrementalTask​​ $ taskAction com.android.build.gradle.internal.tasks.NonIncrementalTask​​ $ taskAction $$ inlined $ recordTaskAction $ 1.invoke(AndroidVariantTask.kt:31)位于com.android的$$ inlined $ recordTaskAction $ 1.invoke(AndroidVariantTask.kt:51) .build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:

由以下原因引起:java.lang.RuntimeException:模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1中发现重复的类android.support.v4.app.INotificationSideChannel。 1-runtime.jar(com.android.support:support-compat:27.1.1) 在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com)中找到重复的类android.support.v4.app.INotificationSideChannel $ Stub .android.support:support-compat:27.1.1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)中找到重复的类android.support.v4.app.INotificationSideChannel $ Stub $ Proxy )和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)在模块core-1.0.0-runtime中发现重复的类android.support.v4.os.IResultReceiver。 jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)复制类android.support.v4.os.IResultReceiver在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1)中找到$ Stub。1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime中找到重复的类android.support.v4.os.IResultReceiver $ Stub $ Proxy .jar(com.android.support:support-compat:27.1.1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)中找到重复的类android.support.v4.os.ResultReceiver )和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)在模块core-1.0.0-runtime中发现重复的类android.support.v4.os.ResultReceiver $ 1 .jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1.1)重复的类android.support.v4.os。在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar(com.android.support:support-compat:27.1)中找到ResultReceiver $ MyResultReceiver 。1)在模块core-1.0.0-runtime.jar(androidx.core:core:1.0.0)和support-compat-27.1.1-runtime.jar中找到重复的类android.support.v4.os.ResultReceiver $ MyRunnable (com.android.support:support-compat:27.1.1)

转到文档以了解如何修复依赖性解析错误。在com.android.ide.common.workers.ExecutorServiceAdapter $ submit $ submission $ 1.run(ExecutorServiceAdapter.kt:68)在com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable.run(CheckDuplicateClassesDelegate.kt:128) java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)处的java.util.concurrent.ForkJoinTask $ AdaptedRunnableAction.exec(ForkJoinTask.java:1386)java.util.concurrent.ForkJoinTask.externalInterruptibleAwaitDone(ForkJoinTask.java: 361)at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1001)...还有102个

添加firebase和OneSignal SDK之后,我看到的内容如下:build.gradle文件如下:

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
    repositories {
        jcenter()       
        google()
        mavenCentral()
        maven {
            url "https://jitpack.io"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
    }
}

allprojects {
   repositories {
      google()
      jcenter()
      maven {
           url "https://jitpack.io"
      }
      flatDir {
        dirs 'libs'
      }
   }
}


// Android Resolver Repos Start
([rootProject] + (rootProject.subprojects as List)).each { project ->
    project.repositories {
        def unityProjectPath = "file:///" + file(rootProject.projectDir.path + "/../../").absolutePath
        maven {
            url "https://maven.google.com"
        }
        maven {
            url "file:////Users/zukinaru/Snowy2019/sfcen-free-2017.4.ORI/Assets/Firebase/m2repository" // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:20, Assets/Firebase/Editor/CrashlyticsDependencies.xml:20
        }
        maven {
            url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
        }
        mavenLocal()
        jcenter()
        mavenCentral()
    }
}
// Android Resolver Repos End
apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'com.android.support:cardview-v7:[26.0.0, 27.2.0[' // Assets/OneSignal/Editor/OneSignalDependencies.xml:7
    implementation 'com.android.support:customtabs:[26.0.0, 27.2.0[' // Assets/OneSignal/Editor/OneSignalDependencies.xml:8
    implementation 'com.android.support:support-v4:[26.0.0, 27.2.0[' // Assets/OneSignal/Editor/OneSignalDependencies.xml:6
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9' // Assets/Firebase/Editor/CrashlyticsDependencies.xml:15
    implementation 'com.google.android.gms:play-services-ads:12.0.1' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
    implementation 'com.google.android.gms:play-services-base:[10.2.1, 12.1.0[' // Assets/OneSignal/Editor/OneSignalDependencies.xml:3
    implementation 'com.google.android.gms:play-services-location:[10.2.1, 12.1.0[' // Assets/OneSignal/Editor/OneSignalDependencies.xml:5
    implementation 'com.google.firebase:firebase-analytics:17.2.0' // Assets/Firebase/Editor/AppDependencies.xml:15
    implementation 'com.google.firebase:firebase-analytics-unity:6.7.0' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
    implementation 'com.google.firebase:firebase-app-unity:6.7.0' // Assets/Firebase/Editor/AppDependencies.xml:20
    implementation 'com.google.firebase:firebase-common:19.2.0' // Assets/Firebase/Editor/AppDependencies.xml:13
    implementation 'com.google.firebase:firebase-crashlytics-unity:6.7.0' // Assets/Firebase/Editor/CrashlyticsDependencies.xml:20
    implementation 'com.google.firebase:firebase-messaging:[10.2.1, 12.1.0[' // Assets/OneSignal/Editor/OneSignalDependencies.xml:4
// Android Resolver Dependencies End
    implementation(name: 'GoogleAIDL', ext:'aar')
    implementation(name: 'GooglePlay', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-drive-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-games-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-gcm-12.0.1', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-iid-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-nearby-11.0.4', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-tasks-11.0.4', ext:'aar')
    implementation(name: 'common', ext:'aar')
    implementation(name: 'onesignal-unity', ext:'aar')
    implementation(name: 'unity-ads', ext:'aar')
    implementation project(':Firebase')
    implementation project(':GoogleMobileAdsPlugin')
    implementation project(':OneSignalConfig')
    implementation project(':common_lib')
    implementation project(':youtube_lib')
}

// Android Resolver Exclusions Start
android {
  packagingOptions {
      exclude ('/lib/armeabi/*' + '*')
      exclude ('/lib/mips/*' + '*')
      exclude ('/lib/mips64/*' + '*')
      exclude ('/lib/x86/*' + '*')
      exclude ('/lib/x86_64/*' + '*')
  }
}
// Android Resolver Exclusions End
android {
    compileSdkVersion 29
    buildToolsVersion '21.1.1'

    task removeBuildConfig(dependsOn: "compileReleaseSources") {
        doFirst {
            file("$buildDir/intermediates/classes/release/pathToFile/BuildConfig.class").delete()
        }
    }

    defaultConfig {
        targetSdkVersion 29
        applicationId 'com.snowyenglish.flashcard'

        minSdkVersion 19
        multiDexEnabled true
        versionCode 509
        versionName "1.2.509"
        ndk {
          abiFilters 'armeabi-v7a','arm64-v8a'
        } 
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb','google-services-desktop.json'
    }

    signingConfigs { release {
        storeFile file('/Users/zukinaru/Dropbox/SNOWY_KEY/snowy_flashcard_english.keystore')
        storePassword 'xyz'
        keyAlias 'my snowy beta'
        keyPassword 'xyz'
    } }

    buildTypes {
        debug {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt','proguard-user.txt'
            jniDebuggable true
        }
        release {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt','proguard-user.txt'
            signingConfig signingConfigs.release
        }
    }

}

任何想法来解决上述错误?

先感谢您...

展开
收起
垚tutu 2019-12-04 16:20:39 4303 0
1 条回答
写回答
取消 提交回答
  • 在gradle.properties中添加以下内容:

    android.useAndroidX=true android.enableJetifier=true

    AndroidX 是对 android.support.xxx 包的整理后产物。由于之前的 support 包过于混乱,所以,Google 推出了AndroidX android.enableJetifier=true 表示将依赖包也迁移到androidx 。如果取值为false,表示不迁移依赖包到androidx,但在使用依赖包中的内容时可能会出现问题,如果项目中没有使用任何三方依赖,可以设置为false。

    2020-02-11 11:30:37
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
从 SDK 到编解码:视频直播架构解析 立即下载
跨平台的云服务SDK需要什么 立即下载
一个跨平台的云服务SDK需要什么 立即下载