Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Get started with AAR

4,309 views

Published on

A short introduction to the new AAR library format for android app projects.
Talk on Droidcon 2014

  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/LRaRu ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Get started with AAR

  1. 1. Get started with AAR archives How to create and work with the new AAR archive format using gradle and android studio
  2. 2. René Mertins Senior Java Architect with more then 10 years experience. Architect of the apponsormonetization platform. Email: r.mertins@bitforce-it.de g+: +ReneMertinsHH www.apponsor.com www.bitforce-it.de
  3. 3. WTF is AAR? -Introduced I/O 2013 -Library project packaging format -AAR is Android ARchive
  4. 4. It‘s a simple zip
  5. 5. Benefits 1.Never handle complete library projects any more 2.No need to publish a library in source
  6. 6. For distributors -Provide precompiled -Optimized and obfuscated for best performance -Be more sure that no one changes what shouldn‘t changed -Easer publishing and distribution over maven
  7. 7. For developers -reference like support lib or play services -Clean project structure -Online update if remote repository
  8. 8. Actual situation -Full copies of lib projects in source -Reference by file path -Build every time with your app -Difficult to optimize and obfuscate -Difficult to manage different lib versions
  9. 9. Actual situation -Full copies of lib projects in source -Reference by file path -Build every time with your app -Difficult to optimize and obfuscate -Difficult to manage different lib versions
  10. 10. Actual situation -Full copies of lib projects in source -Reference by file path -Build every time with your app -Difficult to optimize and obfuscate -Difficult to manage different lib versions
  11. 11. The idea compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar‚ compile 'com.jeremyfeinstein.slidingmenu.lib:slidingmenu:1.3@aar' -Library projects are separated from app projects -Published as desired in to AAR -App developer only declare dependencies
  12. 12. Good to know Or how we failed the first time
  13. 13. Creating AAR is easy -Create lib project -Call „bundleRelease“
  14. 14. But now? -Place in project structure? Fail -Gradle include? Fail -Gradle file dependency? Fail
  15. 15. The trick -Provide as maven repo like google does -Publish into maven repo is easy with gradle -Reference AAR in access able repositories -New trick, import
  16. 16. The trick -Provide as maven repo like google does -Publish into maven repo is easy with gradle -Reference AAR in access able repositories -New trick, import
  17. 17. The trick -Provide as maven repo like google does -Publish into maven repo is easy with gradle -Reference AAR in access able repositories -New trick, import
  18. 18. A working example Decide what‘s next: live coding or slides ?
  19. 19. Start a library Use the project wizard to create an initial android library project.
  20. 20. Add something useful I added a static method which returns „Hello [name]! How are you?“
  21. 21. Tweak gradle -Add the android-maven plugin -Apply adroid-maven and maven plugin -Define maven meta data -Define upload archive task
  22. 22. Use gradle tasks -Call bundleReleaseto create AAR in build folder -Call uploadArchivesto upload the AAR to your locale repository
  23. 23. review That’s the repository created by gradle task „uploadArchives“
  24. 24. A new app Create a simple app to test our library.
  25. 25. Define dependency -Apply the maven plugin -Define your locale repository -Setup the dependency to the new library
  26. 26. Use it
  27. 27. Test
  28. 28. Note A referenced AAR library is not shown in Android Studio. You can use the library, you get auto completion etc. But you can it inspect it in the project structure! For Support-Lib and some other stuff from google it‘s working. I‘m sure it will come in future. One point I want to address!
  29. 29. Hint Martin Liersch who is well known for his gradle build system talk is providing a maven repository where he places a lot of useful library projects as AAR artifacts. GitHub: https://github.com/Goddchen/mvn-repo Repo URL: https://github.com/Goddchen/mvn-repo/raw/master/
  30. 30. Hint The gradle project webpage includes a very good documentation. http://www.gradle.org/docs/current/userguide/userguide.html In the maven plugin chapters is a part about uploading artifacts to repositories. Also explaining using different transports like ssh to a remote repository. http://www.gradle.org/docs/current/userguide/maven_plugin.html# uploading_to_maven_repositories
  31. 31. Observe Without the android-maven plugin this solution would be much more complicated. You can find the project at gitHub https://github.com/dcendents/android-maven-plugin
  32. 32. Pull requests Most off the public library projects for android can be found on github. Nearly all are still using ADT and are not providing AAR artifacts. But most often there is a smart guy already done the work to port to android studio and make it easy to publish an aar. So look up the pull requests for your favorite lib and you will find a fork for android studio. Like stefanrusk did for andengine: https://github.com/stefanrusek/AndEngine/tree/GLES2
  33. 33. Hint In one of the last releases of Android Studio they added an import feature for aarpackages. When that happens? I don’t know… You can find it over: File -> New Module -> Import JAR or AAR package New way to define dependency in gradle.build artifacts.add("default", file('myedulibrary-0.1.aar')) In 0.9.x is not working, updated in 1.0 rc1 not tested
  34. 34. Hint Inspect an aarlibrary in your app project. There is trick to do that. 1. Close all open files. 2. Select your app module in project view 3. switch to structure view Then you will see your aarlibrary expanded in the tree view.
  35. 35. Thank you Feel free to approach me for any question. r.mertins@bitforce-it.de G+: ReneMertinsHH

×