Android最佳实践

导言:因为新工作使用内网代理的关系,涉及到信息安全,外网基本被屏蔽掉了,因此部门内部还是有相当一部分人在使用eclipse,不过我还是打算申请外网,尼玛还要钱,兼用android studio 和eclipse 毕竟前者基本上沦为主流开发工具,github上很多优秀的开源项目都迁到studio上了,本来是打算在eclipse中搭建gradle环境,网上也是存在相应的解决方案,不过我还是觉得eclipse+ant, studio+gradle已是行业标准,瞎配乱搭,不伦不类,辣眼睛不习惯。

1.看下两者的区别与建议:
If your project uses the old Ant & Eclipse ADT project structure, consider it legacy and start porting it to the new Gradle & Android Studio project structure. 建议把eclipse上的项目移植到Studio。

主要的区别在于Studio结构把Src源码集一分为二,Main源码目录和AndroidTest测试代码目录,add source sets ‘paid’ and ‘free’ into src which will have source code for the paid and free flavours of your app.同一套代码方便地构建不同类型的版本。Having a top-level app is useful to distinguish your app from other library projects (e.g., library-foobar) that will be referenced in your app. The settings.gradle then keeps references to these library projects, which app/build.gradle can reference to。 Gradle相比ant地优势除了上面提到的几点,还包括依赖地自动下载,定制化签名等。

2.Gradle遵循如下几点规则:

  • 2.1. Put passwords and sensitive data in gradle.properties 在正式签名的时候,尽量避免在signingConfigs中显示的添加,应该添加到属性文件gradle.properties中。防止密码泄露,出现在版本控制系统中,而Instead, make a gradle.properties file which should not be added to the version control system:
  • 2.2. Prefer Maven dependency resolution instead of importing jar files 使用maven依赖库,If you explicitly include jar files in your project, they will be of some specific frozen version, such as 2.1.1. Downloading jars and handling updates is cumbersome, 你要不嫌烦,也可以。
  • 2.3. Avoid Maven dynamic dependency resolution 在添加第三方库时,避免使用such as 2.1.+ 这种动态版本形式,相比较于the use of static versions such as 2.1.1 helps create a more stable, predictable and repeatable development environment. 版本固定,稳定性。
  • 2.4. Use different package name for non-release builds 对于测试版本建议使用不同的包名,Use applicationIdSuffix for debug build type to be able to install both debug and release apk on the same device (do this also for custom build types, if you need any). 在编译脚本中通过对applicationIdSuffix字段的声明可以使同一台机器同时安装多个不同版本的同一应用,This will be especially valuable later on in the app’s lifecycle, after it has been published to the store. 如果想进一步在图标和名字上进行区别,使用如下添加方法:simply put debug icon in app/src/debug/res and release icon in app/src/release/res. You could also change app name per build type, as well as versionName。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值