pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

為什么我在運行我的 Android 項目時得到重復的類

Why I#39;m Getting Duplicate Class When Running My Android Project(為什么我在運行我的 Android 項目時得到重復的類)
本文介紹了為什么我在運行我的 Android 項目時得到重復的類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在為我的應用添加導航抽屜.我遇到了錯誤.應用程序 gradle 同步得很好.但是當我運行應用程序時,我得到了一堆重復的類錯誤.我認為這可能是因為我添加了沖突的依賴項,并且我使用的是 v7 28.0.0 并且一些錯誤提到了 app: v4.我在網上看到的所有示例都使用 v7 28.0.0,盡管我在使用 v4 的 main_activity.xml 中有這個.不知道是否與錯誤有關.android.support.v4.widget.DrawerLayout

I'm in the process of adding a navigation drawer to my app. and I'm getting errors. The app gradle synchs just fine. but when I run the app I get a bunch of duplicate class error. I think it might be because I have conflicting dependencies added and that I'm using v7 28.0.0 and some of the errors mention app: v4. all the examples I've seen online use v7 28.0.0 eventhough I have this in main_activity.xml which uses v4. don't know if it's got something to do with the error. android.support.v4.widget.DrawerLayout

Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$Delegate found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$DelegateProvider found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$SlideDrawable found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$1 found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$OnRequestPermissionsResultCallback found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)

gradle 文件

apply plugin: 'com.android.application'

android {    
    
    compileSdkVersion 28
    defaultConfig {
        applicationId "org.pctechtips.netdroid"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 8
        versionName "1.7"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled = false
        signingConfig signingConfigs.config
    }
    buildTypes {
        release {
            shrinkResources false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable false

        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    /*androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
                        exclude group: 'com.android.support', module: 'support-annotations'
                        firebase
                        implementation 'com.google.firebase:firebase-core:10.2.1'
                    })*/
    //    compile 'com.android.support:appcompat-v7:25.3.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    /*google play plugin for adMob*/
    implementation 'com.google.android.gms:play-services:10.2.1'
    implementation 'commons-net:commons-net:3.6'
    implementation 'org.samba.jcifs:jcifs:1.3.3'
}

推薦答案

異常的意思是,在2個或多個不同的依賴中存在重復的類,編譯器將無法區分應該在run-time 并拋出異常.

The exception means, There were duplicated classes in 2 or more different dependencies and the compiler wouldn't be able to distinguish which of them should be used at run-time and the exception was thrown.

大多數情況下,當您嘗試導入帶有所需庫的模塊時會發生重復性.(傳遞依賴)

Most often, Duplicity happens when you are trying to import modules that carrying their required libraries. (transitive dependencies)

您必須從 build.gradle 中的庫中排除重復的類.如 Log 所示,support-core-uisupport-compat 模塊有重復的類.

You have to exclude duplicated classes from libraries in the build.gradle. As Log shows, support-core-ui and support-compat modules have duplicated classes.

apply plugin: 'com.android.application'

android {
    ...
    defaultConfig {
        ...
    }
    buildTypes {
        ...
    }
    configurations {
        all { // You should exclude one of them not both of them 
            exclude group: "com.android.support", module: "support-core-ui"
            exclude group: "com.android.support", module: "support-compat"
        }
    }
}

有時你不需要排除任何東西,你只需要將導入的模塊更改為不帶依賴關系的模塊.

其他情況導致類重復是當您將*.jar添加到項目libs目錄時.因此,如果它們沒有在項目中開始使用,則需要刪除它們.

Other situation that causes duplicated classes is when you have added *.jar to the project libs directory. Therefore, You need to delete them if they are not begin used in the project.

project->app->libs->*.jar

我看到使用這兩行提到的一些解決方案可以解決問題但是如果您已遷移到 Androidx,它將默認啟用.

I see there are some solutions mentioned using these 2 lines will resolve the problem But if you've migrated to Androidx it would be enabled by default.

android.useAndroidX=true
android.enableJetifier=true

噴射器是

Jetifier 工具將支持庫依賴的庫遷移到依賴而是等效的 AndroidX 包.該工具可讓您遷移直接使用單個庫,而不是使用 Android gradle與 Android Studio 捆綁在一起的插件.

Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. The tool lets you migrate an individual library directly, instead of using the Android gradle plugin bundled with Android Studio.

有關更多信息,請查看排除傳遞依賴項

隨著應用范圍的擴大,它可以包含許多依賴項包括直接依賴和傳遞依賴(庫您的應用程序的導入庫所依賴的).排除及物不再需要的依賴項,可以使用 exclude關鍵詞

As an app grows in scope, it can contain a number of dependencies including direct dependencies and transitive dependencies (libraries which your app's imported libraries depend on). To exclude transitive dependencies that you no longer need, you can use the exclude keyword

如果您在排除類時遇到問題,請查看此線程:如何排除...

If you have problems excluding classes, check this thread: How do I exclude...

這篇關于為什么我在運行我的 Android 項目時得到重復的類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現 IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中獲取當前風味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復“意外元素lt;查詢gt;在“清單中找到錯誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風味庫的多風味應用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運行時有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 山东风淋室_201/304不锈钢风淋室净化设备厂家-盛之源风淋室厂家 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 金属抛光机-磁悬浮抛光机-磁力研磨机-磁力清洗机 - 苏州冠古科技 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | FFU_空气初效|中效|高效过滤器_空调过滤网-广州梓净净化设备有限公司 | 卫生纸复卷机|抽纸机|卫生纸加工设备|做卫生纸机器|小型卫生纸加工需要什么设备|卫生纸机器设备多少钱一台|许昌恒源纸品机械有限公司 | 培训无忧网-教育培训咨询招生第三方平台| 选矿设备,选矿生产线,选矿工艺,选矿技术-昆明昆重矿山机械 | 丹佛斯压力传感器,WISE温度传感器,WISE压力开关,丹佛斯温度开关-上海力笙工业设备有限公司 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | HV全空气系统_杭州暖通公司—杭州斯培尔冷暖设备有限公司 | 石膏基自流平砂浆厂家-高强石膏基保温隔声自流平-轻质抹灰石膏粉砂浆批发-永康市汇利建设有限公司 | 集装箱展厅-住人集装箱住宿|建筑|房屋|集装箱售楼处-山东锐嘉科技工程有限公司 | 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | elisa试剂盒-PCR试剂盒「上海谷研实业有限公司」 | 无机纤维喷涂棉-喷涂棉施工工程-山东华泉建筑工程有限公司▲ | 泰州物流公司_泰州货运公司_泰州物流专线-东鑫物流公司 | 抓斗式清污机|螺杆式|卷扬式启闭机|底轴驱动钢坝|污水处理闸门-方源水利机械 | 开云(中国)Kaiyun·官方网站 - 登录入口 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 户外健身路径_小区健身器材_室外健身器材厂家_价格-浩然体育 | 干培两用箱-细菌恒温培养箱-菲斯福仪器 | 一体化隔油提升设备-餐饮油水分离器-餐厨垃圾处理设备-隔油池-盐城金球环保产业发展有限公司 | 动力配电箱-不锈钢配电箱-高压开关柜-重庆宇轩机电设备有限公司 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 | 即用型透析袋,透析袋夹子,药敏纸片,L型涂布棒-上海桥星贸易有限公司 | 食品无尘净化车间,食品罐装净化车间,净化车间配套风淋室-青岛旭恒洁净技术有限公司 | 创客匠人-让IP变现不走弯路 | 长沙网站建设制作「网站优化推广」-网页设计公司-速马科技官网 | 一级建造师培训_一建培训机构_中建云筑建造师培训网校 | 手机存放柜,超市储物柜,电子储物柜,自动寄存柜,行李寄存柜,自动存包柜,条码存包柜-上海天琪实业有限公司 | 全自动固相萃取仪_高通量真空平行浓缩仪-勤业永为 | 算命免费_生辰八字_免费在线算命 - 卜算子算命网 | 齿轮减速机电机一体机_齿轮减速箱加电机一体化-德国BOSERL蜗轮蜗杆减速机电机生产厂家 | 特种阀门-调节阀门-高温熔盐阀-镍合金截止阀-钛阀门-高温阀门-高性能蝶阀-蒙乃尔合金阀门-福建捷斯特阀门制造有限公司 | 密集架|电动密集架|移动密集架|黑龙江档案密集架-大量现货厂家销售 | 山东PE给水管厂家,山东双壁波纹管,山东钢带增强波纹管,山东PE穿线管,山东PE农田灌溉管,山东MPP电力保护套管-山东德诺塑业有限公司 | 粘度计维修,在线粘度计,二手博勒飞粘度计维修|收购-天津市祥睿科技有限公司 | 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 全自动五线打端沾锡机,全自动裁线剥皮双头沾锡机,全自动尼龙扎带机-东莞市海文能机械设备有限公司 | 混合反应量热仪-高温高压量热仪-微机差热分析仪DTA|凯璞百科 |