2. Objective What are shared libraries? When are they needed? What goes inside?
3. What is a shared library? Logical container for shared assets To create multiple app versions Hidden inside the final product Typically linked statically
4. Why compartmentalize code? Follows DRY / DIE principles Promotes better architecture Easy for collaborative environments
7. Make it a library project Package Explorer, Properties "Android" properties group, Library Set checkbox for "is Library" Click Apply/OK You can also convert an existing application project into a library.
11. Reference the library Package Explorer, Properties Select "Android,” Library Click Add to open Project Selection dialog Select from available library projects
12. Library ordering Can reference multiple libraries Must set relative priority To set, use Upand Down buttons
13. Declare imports in manifest Must declare all components that are imported Just like library’s manifest file <activity>, <service>, <receiver>, <provider>, <permission>, <uses-library>, etc. Use fully-qualified package names, like com.example.app.MainActivity instead of .MainActivity
15. Make three projects Common (Library) Almost everything goes here Paid All functionality like a regular app DRM, if applicable Free Special manifest permissions for ads AdMob conditional inclusions Different layouts as needed Alternate settings
16. What to put where Shared Library Backgrounds and other shared resources Layouts for common screens Shared activities Helper functions 3rd-party libraries Settings Activity App Projects Title images depicting version Unique string resources Ads (if applicable) Settings XML
17. What to put where Shared Library “strings.xml” App Projects “strings.xml” Library’s resources will be replaced by those in app project => easy version testing
18. Duplicates are replaced Works like OOP overloading Acts on activities and resources Project priority matters! Current project gets highest priority (expected behavior)
20. Next steps Create unit tests Watch your dependencies Don’t make more libraries than necessary Usually you only need one
21. Next steps Consider DRM for the paid version Built into Google’s Android Market Supported by Amazon Appstore
22. Testing Method one: a distinct test project Set up a test project Test project instruments an application project that depends on the library Add tests to the project for library-specific features Method two: integrated testing Set up a standard project that depends on the library Put instrumentation into that project Self-contained project will contain both tests/instrumentations and the code to test
23. Final thoughts Libraries are not code packages; they contain code packages Overall goal is to reduce redundancies Not everything will go into a library
24. Working example: KeenDriver Locate alt. fuel stations CNG, LPG, HY, ELEC, LNG, E85, etc. Filter by fuel type and public/private 15,000 stations around USA, AU, DE
25. Working example: KeenDriver Free version has ads No ad on map, tricky placement Paid version has richer layout Paid version has more settings Paid version: less than 50 LOC
26. External links “Adventures with Android Library Projects” http://androidblogger.blogspot.com/2010/09/android-library-projects.html “Managing Projects from Eclipse with ADT” http://developer.android.com/guide/developing/projects/projects-eclipse.html “Testing from Eclipse with ADT” (O.T.) http://developer.android.com/guide/developing/testing/testing_eclipse.html