gradle2.14升级到4.4

gradle 2.x升级到4.4

起因说来也神奇,是为了因为opus音频无法播放的问题
用的exoplayer的extension的解决方案,刚好项目之前用的也是google的ExoPlayer
由于项目足够老,用的gradle版本过低,ExoPlayer本地导入的时候需要的一些gradle语法不能识别,所以需要升级

现在记录一下gradle升级可能会遇到的错误

gradle 2.14.1 ->gradle-4.4
com.android.tools.build:gradle:2.2.3->3.1.2

首先你需要先解决网络问题,先确定问题是不是由于代理不通畅导致的

其次语法问题

问题一 compile project(':basic') 导致的 Cannot choose between the following configurations of project
Gradle sync failed: Cannot choose between the following configurations of project :ailib:
				- debugApiElements
				- debugRuntimeElements
				- releaseApiElements
				- releaseRuntimeElements
				All of them match the consumer attributes:
				- Configuration 'debugApiElements':
				- Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
				- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
				- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
				- Found org.gradle.api.attributes.Usage 'java-api' but wasn't required.
				- Configuration 'debugRuntimeElements':
				- Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
				- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
				- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
				- Found ... (show balloon)
解决方案:修改 compile project(':basic')implementation project(':basic')

具体可能涉及比较多的compile关键字

    compile project(':appstatistics')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
修改为
    implementation project(':appstatistics')
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
问题二 instrumentTest 被弃用导致的 The SourceSet ‘instrumentTest’ is not recognized by the Android Gradle Plugin
ERROR: The SourceSet 'instrumentTest' is not recognized by the 
Android Gradle Plugin. Perhaps you misspelled something?
Affected Modules: XXXXX, XXXXX

instrumentTest.setRoot(‘tests’) ,你可能在升级 Android Studio 时更新了项目的 gradle 配置,这里的配置中 instrumentTest 已被弃用,不适用于现在的 gradle 版本。

解决办法

用 androidTest 替换 instrumentTest,编译运行即可。

问题三 ERROR: Resource shrinker cannot be used for libraries.

ERROR: Resource shrinker cannot be used for libraries.
Affected Modules: XXXX

原因是在类库的配置文件中使用了混淆的配置,删除掉即可

解决方案
buildTypes {
        release {
            minifyEnabled false
//            shrinkResources true //删除此行即可
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
问题四 ERROR: android-apt plugin is incompatible with the Android Gradle plugin. Please use ‘annotationProcessor’ configuration instead.Affected Modules: XXXXX
解决方案
  1. 删除project/build.gradle中的apt插件声明
buildscript {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        jcenter()
        maven { url 'https://dl.bintray.com/umsdk/release' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
//        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
  1. 删除 app/build.gradle下的apt插件声明
apply plugin: 'com.android.application'
//apply plugin: 'com.neenbedankt.android-apt'
  1. 将apt 改为 annotationProcessor
dependencies {
    ...........
    ...........
    //apt '**********'
    annotationProcessor '**********'
    ..............
    ..........
   
}
问题五Android dependency ‘com.android.support:cardview-v7’ has different version for the compile (21.0.3) and runtime (27.1.0) classpath. You should manually set the same version via DependencyResolution

多个module引用了相同的库但是版本不同

解决办法
  1. 手动查找所有的cardview 修改为相同的版本
  2. Use this code in your buildscript (build.gradle root):
    subprojects {project.configurations.all {
      resolutionStrategy.eachDependency { details ->
         if (details.requested.group == 'com.android.support'
               && !details.requested.name.contains('multidex') ) {
            details.useVersion "version which should be used - in your case 26.0.0-beta2"
         }
      }  
      }
      }
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值