项目编译异常,添加kotlin支持后,神奇的异常transformDexArchiveWithExternalLibsDexMergerForDebug和transformResourcesWithM

添加kotlin依赖后突然出现神奇错误transformDexArchiveWithExternalLibsDexMergerForDebug和transformResourcesWithM,各种查资料各种改,耗时良久无果,不得以挨着注释掉使用的库,最终发现是recyclerview依赖库有重复,各种排除依赖无效,突然发现recyclerview是从lib文件夹中引入的,于是改为网络引用模式,然后编译就正常了,做个记录备忘,再次发现,开发中不能联网是多么坑爹的一件事情!!!

apply plugin: 'com.android.application'
//kotlin依赖相关
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.hisense.myapplication"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        //开启多dex支持
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    //解决Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
    //> More than one file was found with OS independent path 'META-INF/androidx.recyclerview_recyclerview.version'
//    packagingOptions {
//        exclude 'META-INF/androidx.recyclerview_recyclerview.version'
//    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


//    implementation (name:'BaseRecyclerViewAdapterHelper-2.9.30',ext:'aar')
    implementation 'com.google.code.gson:gson:2.8.5'
    //万能适配器
    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    //Glide依赖--图片加载库
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    //glide扩展
    implementation 'jp.wasabeef:glide-transformations:2.0.2'
    implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
    //okgo依赖--网络连接库
    implementation 'com.lzy.net:okgo:3.0.4'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    //banner
    implementation 'com.youth.banner:banner:1.4.9'
    //上拉加载下拉刷新
    implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-21'
    implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-21'
    //    数据库操作库
    implementation 'org.litepal.android:core:1.6.1'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.lzy.widget:ninegridview:0.2.1'
    //    implementation project(':UdeskSDKUI')
    //二维码长按识别
    implementation 'com.github.BolexLiu:PressScanCode:v1.0.0'
    //---------------------------------------------极光推送-----------------------------------------
    //    implementation 'cn.jiguang.sdk:jpush:3.1.0'  // 此处以JPush 3.0.9 版本为例。
    //    implementation 'cn.jiguang.sdk:jcore:1.1.8'  // 此处以JCore 1.1.7 版本为例。
    //---------------------------------------------极光推送-----------------------------------------
    //---------------------------------------------分包---------------------------------------------
    implementation 'com.android.support:multidex:1.0.3'
    //---------------------------------------------分包---------------------------------------------
    //高德地图定位
    implementation 'com.amap.api:location:4.5.0'
    //权限申请
    implementation 'pub.devrel:easypermissions:2.0.1'

    //屏幕适配需要在manifest文件中进行配置
//    implementation 'me.jessyan:autosize:1.1.2'

//    implementation(name: 'recyclerview-lib-1.0.0', ext: 'aar')

    //butterknife依赖,添加后报错,support库和Androidx库不能共存,智能使用其中之一
    //https://www.jianshu.com/p/f7a7a8765294
    //FAILURE: Build failed with an exception.
    //* What went wrong:
    //Execution failed for task ':app:processDebugManifest'.
    //> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    //     is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    //     Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-23:19 to override.
    //* Try:
    //Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    //* Get more help at https://help.gradle.org
//    implementation 'com.jakewharton:butterknife:10.1.0'
//    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

    //    //沉浸式状态栏
    //引用后报错
    //FAILURE: Build failed with an exception.
    //* What went wrong:
    //Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
    //> More than one file was found with OS independent path 'META-INF/androidx.recyclerview_recyclerview.version'
    //* Try:
    //Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    //* Get more help at https://help.gradle.org
//    implementation ('com.readystatesoftware.chuck:library:1.0.4' ){
//        exclude group: 'com.google.code.gson'
//        exclude group: 'com.squareup.okhttp3:okhttp'
//    }
    //FAILURE: Build failed with an exception.引用后报错
    //* What went wrong:
    //Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
    //> More than one file was found with OS independent path 'META-INF/androidx.recyclerview_recyclerview.version'
    //* Try:
    //Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    //* Get more help at https://help.gradle.org
//    implementation 'com.lzy.widget:imagepicker:0.5.5'

    implementation('com.readystatesoftware.chuck:library:1.0.4') {
//        exclude group: 'com.google.code.gson', module: 'gson'
//        exclude group: 'com.squareup.okhttp3', module: 'okhttp'
//        exclude group: 'com.android.support', module: 'appcompat-v7'
//        exclude group: 'com.android.support', module: 'support-v4'
//        exclude group: 'com.android.support', module: 'recyclerview-v7'
//        exclude group: 'com.android.support', module: 'design'
    }
    implementation('com.lzy.widget:imagepicker:0.5.5') {
//        exclude group: 'com.android.support', module: 'recyclerview-v7'
//        exclude group: 'com.android.support', module: 'appcompat-v7'
    }

    //直接从libs中依赖recyclerview会导致出现异常Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
    //> More than one file was found with OS independent path 'META-INF/androidx.recyclerview_recyclerview.version'
    //因为imagepiker和chuck库中有recyclerview的依赖,transformDexArchiveWithExternalLibsDexMergerForDebug,
    //异常同样是因为直接从lib中引入该库导致,gradle以网络依赖的方式则不会出现任何异常
//    implementation(name: 'recyclerview-v7-28.0.0', ext: 'aar')

    //添加com.lzy.widget:imagepicker和com.readystatesoftware.chuck:library依赖后报错
    // app:transformClassesWithJarMergingForDebug,原因为工程中design库版本和recyclerview版本有冲突
    //添加注释掉的内容后运行成功,然后注释掉添加内容也不再报错,但是,design库的依赖必须单独添加
    //
//    implementation 'com.android.support:design:28.0.0'
//    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
}
configurations.all {
    //gradle强制使用某个版本的依赖
//    resolutionStrategy.force 'com.android.support:recyclerview-v7:28.0.0'  &&!requested.name.startsWith("recyclerview-v7")
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.0.0'
            }
        }
    }
//消除-Xlint:deprecation警告
gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
}
}
repositories {
    mavenCentral()
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值