Android Studio 3.0 项目升级简要指南

本文介绍如何将Android项目从旧版本迁移到Gradle 3.0,包括必要的准备工作、项目修改步骤、常见错误及解决方案,如依赖冲突、dex合并失败等问题。

前言

3.0工具下老项目不做修改,正常使用要求:

gradle 依旧使用 2.3.3

3.0修改文档官方地址:
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

项目改造

准备工作:

1.要较好的网络,要自动下载很多东西,另外4.1如果下载不到,可以直接到官方下
https://gradle.org/releases

项目修改:

(1)最好的参照项目:用3.0的工具去创建一个新项目

tip:貌似现在新建项目不会自动创建根文件夹坑

(2)gradle 3.0.0对应的buildToolsVersion ‘26.0.2’以上

(3)把compile 改成,找对应的修改,这个在新项目中可以找到

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
implementation project(':networklib')

(4)类似如下配置

apply plugin: ‘com.neenbedankt.android-apt’

要修改成:

annotationProcessor ‘com.neenbedankt.gradle.plugins:android-apt:1.8’

说明:如果不知道版本可以项目设置中的Library dependency搜,除去版本号全名搜,搜不到再后面逐步删除单个单词再搜索,保存后再把implementation改成annotationProcessor

遇到的问题:

错误一:

Error:Execution failed for task ‘:app:preReleaseBuild’.
Android dependency ‘com.android.support:design’ has different version for the compile (22.2.1) and runtime (25.0.0) classpath. You should manually set the same version via DependencyResolution

解决:
思路:包重复,剔除即可。
最终逐个排除,查到下面这个包含

implementation ‘com.foamtrace:photopicker:1.0’,{
exclude group: ‘com.android.support’, module: ‘design’
}

//下面这个包含23.3.2的版本(解决recyclerview-v7重复问题)。

implementation ‘com.malinskiy:superrecyclerview:1.1.4’,{
exclude group: ‘com.android.support’, module: ‘recyclerview-v7’
}

使用butterknife要注意修改成如下:

annotationProcessor ‘com.jakewharton:butterknife-compiler:8.4.0’

另外注意在主项目中要添加annotationProcessor ‘com.jakewharton:butterknife-compiler:8.4.0’,否则会空指针

错误二:

Error:Execution failed for task ‘:app:transformDexArchiveWithExternalLibsDexMergerForDebug’.java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

解决同下:

错误三: 主项目无法使用lib的jar包问题

答:
在解决这个问题前,先填个坑。。在lib工程,要把 implementation改成api,否则你无法在主项目中调用。
我这里代码重复错误就是因为主项目又再去引用一次。

apk包无法在其他手机安装

情景:打包到测试机A,然后把outputs里的apk包发到测试机B,C,B和C都显示测试包,无法安装。

描述:==巨坑==,不知道这是bug,还是我哪里配错了,解决被周末因为这个问题拉来加班。。。。

解决办法:使用新的命令,在Build选卡中选择Build APK(s),然后这些包都是可以安装到其他手机的。

NetWork无法查看详细问题

I finally got it to work by doing the following:

  • Leave compile SDK at 26
  • In the run configuration have “Enable advanced profiling” activated, even though it states this is only needed for API level < 26
  • Disable Proguard (this seems to be the most important)

大意:
1. compile 26
2. 点击那个run confiuration把这个选项Enable advanced profiling选上
3. 需要关闭混淆
4.

多渠道打包配置修改

Caused by: org.gradle.process.internal.ExecException: Process ‘command ‘D:\androidstudio\sdk\build-tools\26.0.2\aapt.exe” finished with non-zero exit value 1
Execution failed for task ‘:moduletest01:verifyBaiduReleaseResources’.

总的来说:

注意如下配置:

    flavorDimensions "default"

    productFlavors {
        normal {
        }

        baidu {
        }
    }

    lintOptions {
        abortOnError false
        checkReleaseBuilds false
        // 防止在发布的时候出现因MissingTranslation导致Build Failed!
        disable 'MissingTranslation'
    }

参考:http://blog.youkuaiyun.com/chenlin1989/article/details/78415873

输入法显示异常问题

先参照该博主的:http://blog.youkuaiyun.com/yechaoa/article/details/78390583

然后参照:http://blog.youkuaiyun.com/kjy_772875381/article/details/78410375

亲测有效

其他问题还有待发现,遇到问题的可以留言给我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值