Android最佳实践

来源:互联网 发布:打击网络犯罪新闻评论 编辑:程序博客网 时间:2024/05/16 01:22

导言:因为新工作使用内网代理的关系,涉及到信息安全,外网基本被屏蔽掉了,因此部门内部还是有相当一部分人在使用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。

0 0
原创粉丝点击