Building Android Apps — 30 things that experience made me learn the hard way

There are two kinds of people — those who learn the hard way and those who learn by taking someone’s advice. Here are some of the things I’ve learned along the way that I want to share with you:


  1. Think twice before adding any third party library, it’s a really seriouscommitment;
  2. If the user can’t see it, don’t draw it!;
  3. Don’t use a database unless you really need to;
  4. Hitting the 65k method count mark is gonna happen fast, I mean really fast! And multidexing can save you;
  5. RxJava is the best alternative to AsyncTasks and so much more;
  6. Retrofit is the best networking library there is;
  7. Shorten your code with Retrolambda;
  8. Combine RxJava with Retrofit and Retrolambda for maximum awesomeness!;
  9. I use EventBus and it’s great, but I don’t use it too much because the codebase would get really messy;
  10. Package by Feature, not layers;
  11. Move everything off the application thread;
  12. lint your views to help you optimize the layouts and layout hierarchies so you can identify redundant views that could perhaps be removed;
  13. If you’re using gradle, speed it up anyway you can;
  14. Do profile reports of your builds to see what is taking the build time;
  15. Use a well known architecture;
  16. Testing takes time but it’s faster and more robust than coding without tests once you’ve got the hang of it;
  17. Use dependency injection to make your app more modular and therefore easier to test;
  18. Listening to fragmented podcast will be great for you;
  19. Never use your personal email for your android market publisher account;
  20. Always use appropriate input types;
  21. Use analytics to find usage patterns and isolate bugs;
  22. Stay on top of new libraries (use dryrun to test them out faster);
  23. Your services should do what they need to do and die as quickly as possible;
  24. Use the Account Manager to suggest login usernames and email addresses;
  25. Use CI (Continuous Integration) to build and distribute your beta and production .apk’s;
  26. Don’t run your own CI server, maintaining the server is time consuming because of disk space/security issues/updating the server to protect from SSL attacks, etc. Use circleci, travis or shippable, they’re cheap and it’s one less thing to worry about;
  27. Automate your deployments to the playstore;
  28. If a library is massive and you are only using a small subset of its functions you should find an alternative smaller option (rely on proguard for instance);
  29. Don’t use more modules than you actually need. If that modules are not constantly modified, it’s important to have into consideration that the time needed to compile them from scratch (CI builds are a good example), or even to check if the previous individual module build is up-to-date, can be up to almost 4x greater than to simply load that dependency as a binary .jar/.aar.
  30. Start thinking about ditching PNGs for SVGs;
  31. Make library abstraction classes, it’ll be way easier to switch to a new library if you only need to switch in one place (e.g.AppLogger.d(“message”) can contain Log.d(TAG, message) and later realise that Timber.d(message) is a better option);
  32. Monitor connectivity and type of connection (more data updates while on wifi?);
  33. Monitor power source and battery (more data updates while charging?Suspend updates when battery is low?);
  34. A user interface is like a joke. If you have to explain it, it’s not that good;
  35. Tests are great for performance: Write slow (but correct) implementation then verify optimizations don’t break anything with tests.

这个世界上有两种人-从经验教训中学习的人以及听从别人建议的人。这里是我一路走来学到的一些东西,分享给大家:

  1. 在添加任何第三方party之前,请三思:这真的是一个成熟的项目吗?
  2. 如果一个东西用户看不到,就不要绘制它
  3. 除非真的需要,否则别使用数据库;
  4. 达到65k方法数限制来的非常快,真的,非常快!不过 multidexing 可以拯救你;
  5. RxJava 是 AsyncTasks 以及其它杂碎的最佳替代者;
  6. Retrofit 可能是现在最佳的网络请求库;
  7. 使用 Retrolambda来简化你的代码;
  8. 把 RxJava 和 Retrofit 以及 Retrolambda 结合起来会让你酷炸天!
  9. 我使用 EventBus 而且它也很好,但是我并不会用太多,因为这样代码库会变得凌乱;
  10. 包名按照功能来,而不是按分层来;
  11. 把所有东西都移到 application thread之外;
  12. lint 可以帮助你优化布局与布局树,这样你就能识别出那些可能已经被移除的冗余的View;
  13. 如果你在使用gradle,使用一切可能的方式去加速它;
  14. 对builds做profile reports,以便知道什么占据了编译时间;
  15. 使用一个 有名的 架构;
  16. 测试时比较花时间,但是一旦你找到诀窍它可以比不使用测试更快、更健壮;
  17. 使用 依赖注入 让你的app更模块化,从而更易于测试;
  18. 收听 fragmented podcast 将会让你受益;
  19. 千万别用私人邮箱作为你安卓市场的发布者账号;
  20. 总是使用恰当的输入类型;
  21. Use analytics to find usage patterns and isolate bugs;
  22. 关注最新的 libraries(使用dryrun 来快速查看它们的的效果);
  23. 你的service应该做你所需的事情,并且尽快死去;
  24. 使用 Account Manager 来提示登录用户名和邮箱地址;
  25. 使用CI(持续集成)来构建和发布你的beta和产品apk;
  26. 不要运行自己的CI server,维护server是费时的事情,因为磁盘空间,安全问题,更新server以防止SSL攻击等等原因。使用circleci, travis 或者 shippable, 它们便宜,而且你也可以少担心一些事情;
  27. Automate your deployments to the playstore;
  28. 如果一个library很大而你只需要使用其中的一部分功能,你应该寻找一个更小的来替代(比如依靠proguard );
  29. 不要使用多于实际需要的module。从零开始编译一个module或者仅仅是检查上个module是否最新所需要的时间几乎是加载 binary .jar/.aar依赖的4倍以上;
  30. 开始考虑用SVG来替代PNG
  31. Make library abstraction classes, it’ll be way easier to switch to a new library if you only need to switch in one place (e.g.AppLogger.d(“message”) can contain Log.d(TAG, message) and later realise that Timber.d(message) is a better option);
  32. 监控你的连接情况以及连接类型(wifi之下更新更多数据?);
  33. 监控你的电源和电量(在充电的时候更新更多的数据?电量低的时候暂停更新?);
  34. 一个用户界面就如一个笑话那样,如果你需要解释,那么证明它并不够好;
  35. Tests are great for performance: Write slow (but correct) implementation then verify optimizations don’t break anything with tests.

 

 

Original Link: https://medium.com/@cesarmcferreira/building-android-apps-30-things-that-experience-made-me-learn-the-hard-way-313680430bf9#.ui3l0tev8

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s