详解android项目由Gradle 2.2 切换到 3.0的坑
问题1、运行的时候一直报如下错误
Error:Executionfailedfortask':app:transformDexArchiveWithExternalLibsDexMergerForApiTestDebug'.
>java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:Unabletomergedex
查了很多资料,大概意识是引用重复的库或jar的问题。
然后一遍一遍的检查,发现并没有引用重复的jar包。
最后考虑是不是第三方库引用jar出现的问题,然后就一个一个排查第三方库,最后发现我们用支付用的是
compile'com.pingxx:pingpp-alipay:2.1.9'//使用支付宝时添加
发现这个库有些问题,竟然在里面引用两个版本的支付宝的jar包,果断的换了最新版本,检查了一个这次就引用了一个jar包。重新编译了一下项目,运行成功,问题解决了。
特别注意:引用第三方库在gralde3.0版本是更为严格,要特别注意。
问题2、
AAPT2
AAPT2将默认启用,如果遇到离奇的问题,可以尝试禁用,只要在gradle.properties中加入:
android.enableAapt2=false
其他:
应用(app)目录下build.gradle(下面implementation"com.android.support:design:25.4.0"切换为project的统一配置)
applyplugin:'com.android.application' applyplugin:'io.fabric' applyplugin:'com.google.gms.google-services' android{ compileSdkVersion25 buildToolsVersion"26.0.2" defaultConfig{ multiDexEnabledtrue applicationId"com.example" minSdkVersion21 targetSdkVersion23 versionCode1 versionName"1.0" renderscriptTargetApi23 renderscriptSupportModeEnabledtrue } compileOptions{ sourceCompatibilityJavaVersion.VERSION_1_8 targetCompatibilityJavaVersion.VERSION_1_8 } lintOptions{ quiettrue abortOnErrorfalse ignoreWarningstrue disable'InvalidPackage'//Somelibrarieshaveissueswiththis. disable'OldTargetApi' //LintgivesthiswarningbutSDK20wouldbeAndroidLBeta. disable'IconDensities'//Fortestingpurpose.Thisissafetoremove. disable'IconMissingDensityFolder'//Fortestingpurpose.Thisissafetoremove. } dexOptions{ javaMaxHeapSize"8G" } packagingOptions{ exclude'LICENSE.txt' exclude'META-INF/DEPENDENCIES.txt' exclude'META-INF/LICENSE.txt' exclude'META-INF/NOTICE.txt' exclude'META-INF/NOTICE' exclude'META-INF/LICENSE' exclude'META-INF/DEPENDENCIES' exclude'META-INF/notice.txt' exclude'META-INF/license.txt' exclude'META-INF/dependencies.txt' exclude'META-INF/rxjava.properties' } sourceSets{ main.java.srcDirs+='build/generated/source/apt' } } repositories{ flatDir{ dirs'libs' } } dependencies{ implementationfileTree(dir:'libs',include:['*.jar']) implementationproject(':library_api') implementationproject(':library_base') implementationproject(':library_blur_dialog') implementationproject(':library_countrycodepicker_dialog') implementationproject(':library_glow_decorator') implementationproject(':library_icons') implementationproject(':library_loopvideo') implementationproject(':library_section_adaper') implementationproject(':library_taptargetview') implementationproject(':library_ucrop') implementationproject(':library_utils') implementationproject(':library_utils_picasso') implementationproject(':library_vector_compat') implementationproject(':library_view_clock') implementationproject(':library_view_shimmer_recycler') implementation"com.google.android.gms:play-services-cast-framework:11.4.2" compileOnly'com.google.android.wearable:wearable:2.0.3' implementation'com.google.android.support:wearable:2.0.3' implementation'com.google.android.exoplayer:exoplayer:r2.4.1' implementation"com.android.support:mediarouter-v7:25.4.0" implementation"com.android.support:leanback-v17:25.4.0" implementation"com.android.support:design:25.4.0" implementation"com.android.support:appcompat-v7:25.4.0" implementation"com.android.support:support-v4:25.4.0" implementation"com.android.support:gridlayout-v7:25.4.0" implementation"com.android.support:cardview-v7:25.4.0" implementation"com.android.support:recyclerview-v7:25.4.0" implementation"com.android.support:preference-v14:25.4.0" //rxjava implementation'io.reactivex:rxjava:1.2.9' implementation'io.reactivex:rxandroid:1.2.1' implementation'com.github.davidmoten:rxjava-extras:0.8.0.6' //square implementation"com.squareup.retrofit2:retrofit:2.1.0", implementation"com.squareup.retrofit2:converter-gson:2.1.0" implementation"com.squareup.retrofit2:adapter-rxjava:2.1.0" implementation"com.squareup.phrase:phrase:1.1.0" implementation"com.squareup.okhttp3:okhttp:3.6.0" implementation"com.squareup.okhttp3:logging-interceptor:3.6.0" implementation"com.squareup.okhttp3:okhttp-urlconnection:3.6.0" //picasso implementation"com.squareup.picasso:picasso:2.5.2" implementation'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' //dagger implementation"com.google.dagger:dagger:2.10" annotationProcessor"com.google.dagger:dagger-compiler:2.10" implementation"javax.annotation:jsr250-api:1.0" implementation"javax.inject:javax.inject:1" //jakeftw implementation'com.jakewharton:butterknife:8.8.1' annotationProcessor'com.jakewharton:butterknife-compiler:8.8.1' compileOnly'org.projectlombok:lombok:1.16.16' annotationProcessor'org.projectlombok:lombok:1.16.16' //FragmentWithArgs implementation"com.hannesdorfmann.fragmentargs:annotation:3.0.2", annotationProcessor"com.hannesdorfmann.fragmentargs:processor:3.0.2", implementation"org.parceler:parceler-api:1.1.9", annotationProcessor"org.parceler:parceler:1.1.9", implementation'com.hannesdorfmann.fragmentargs:bundler-parceler:3.0.2' implementation"com.github.codekidX:storage-chooser:1.0.34" implementation'io.github.yavski:fab-speed-dial:1.0.6' implementation('com.crashlytics.sdk.android:crashlytics:2.6.7@aar'){ transitive=true; } //intentbuilder implementation"com.github.marcinmoskala.activitystarter:activitystarter:1.00" annotationProcessor"com.github.marcinmoskala.activitystarter:activitystarter-compiler:1.00" implementation'com.android.support.constraint:constraint-layout:1.0.2'//constraint-layout implementation'org.greenrobot:eventbus:3.0.0' //font implementation'uk.co.chrisjenx:calligraphy:2.2.0' implementation'com.github.florent37:expectanim:1.0.6' implementation'com.romandanylyk:pageindicatorview:0.2.0@aar' implementation'com.github.rubensousa:gravitysnaphelper:1.2' implementation'com.flaviofaria:kenburnsview:1.0.7' implementation'com.github.florent37:arclayout:1.0.2' implementation'com.jakewharton.rxbinding:rxbinding:1.0.1' implementation'com.wang.avi:library:2.1.3' implementation'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' implementation'com.borax12.materialdaterangepicker:library:1.9' implementation'com.github.scottyab:showhidepasswordedittext:0.8' //Location implementation"com.google.android.gms:play-services-maps:11.4.2" implementation'pl.charmas.android:android-reactive-location:0.10@aar' implementation"com.google.android.gms:play-services-location:11.4.2" //youcanusenewerGMSversionifyouneed implementation"com.google.android.gms:play-services-places:11.4.2" implementation'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar' implementation'commons-validator:commons-validator:1.4.1' implementation'com.balysv:material-ripple:1.0.2' implementation'com.googlecode.libphonenumber:libphonenumber:8.5.2' implementation'ru.egslava:MaskedEditText:1.0.5' implementation'com.futuremind.recyclerfastscroll:fastscroll:0.2.5' implementation"com.google.firebase:firebase-core:11.4.2" implementation'com.labo.kaji:swipeawaydialog:0.1.1' implementation'io.supercharge:shimmerlayout:1.0.1' implementation'hanks.xyz:htextview-library:0.1.5' implementation'com.github.castorflex.smoothprogressbar:library:1.1.0'//progressbarforactionbar implementation'io.reactivex:rxjava-math:1.0.0' implementation'jp.wasabeef:picasso-transformations:2.1.2' implementation'com.afollestad.material-dialogs:core:0.9.1.0' implementation('com.github.ihsanbal:LoggingInterceptor:2.0.2'){ excludegroup:'org.json',module:'json' } }
项目(project)目录下build.gradle:
//Top-levelbuildfilewhereyoucanaddconfigurationoptionscommontoallsub-projects/modules. buildscript{ repositories{ maven{url'http://maven.aliyun.com/nexus/content/groups/public/'} maven{ url'https://maven.google.com/' name'Google' } jcenter() //maven{url'http://maven.aliyun.com/nexus/content/repositories/jcenter'} } dependencies{ classpath'com.android.tools.build:gradle:3.0.1' classpath'com.meituan.android.walle:plugin:1.1.1' //NOTE:Donotplaceyourapplicationdependencieshere;theybelong //intheindividualmodulebuild.gradlefiles } } allprojects{ repositories{ maven{url'http://maven.aliyun.com/nexus/content/groups/public/'} //maven{url'http://maven.aliyun.com/nexus/content/repositories/jcenter'} maven{url"https://jitpack.io"} maven{url'https://maven.google.com'} maven{url"https://dl.google.com/dl/android/maven2/"} jcenter() google() } } taskclean(type:Delete){ deleterootProject.buildDir } ext{ targetSdkVersion=26 minSdkVersion=14 compileSdk=26 buildTools="26.0.2" junit='junit:junit:4.12' recyclerview='com.android.support:recyclerview-v7:26.0.2' appcompat='com.android.support:appcompat-v7:26.0.2' design='com.android.support:design:26.0.2' percent='com.android.support:percent:26.0.2' glide='com.github.bumptech.glide:glide:3.7.0' retrofit='com.squareup.retrofit:retrofit:1.9.0' gson='com.google.code.gson:gson:2.8.0' okhttp='com.squareup.okhttp3:okhttp:3.6.0' //converterGson='com.squareup.retrofit:converter-gson:2.0.0-beta2' //converterJackson='com.squareup.retrofit:converter-jackson:1.9.0' commonsio='commons-io:commons-io:2.4' }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。