Building next gen android library with gradle

  • Published on
    29-Aug-2014

  • View
    126

  • Download
    3

DESCRIPTION

 

Transcript

<ul><li> 1 </li> <li> 2 Building next-gen Android library with Gradle Anton Rutkevich Android developer </li> <li> 3 About me 3+ years of Android development Mobile game-dev experience At Yandex: Android development Continuous Integration At Google Developer Group Minsk: Co-organizer Speaker </li> <li> 4 Old-style library projects The past, the present </li> <li> 5 Whats wrong? Hard to update Hard to distribute Eclipse, eclipse </li> <li> 6 Gradle &amp; The New Build System The present, the future </li> <li> 7 Gradle - build automation evolved Build scripts on Groovy Flexible build setup Runs everywhere (Java required) Dependency management </li> <li> 8 Dependency management Maven artifacts Local artifacts Library projects dependencies { compile com.google.code.gson:gson:2.2.4 compile fileTree(dir: libs, include: *.jar) compile project(:my-library) } </li> <li> 9 The New Build System Brings Gradle features to Android builds Provides Android Studio integration </li> <li> 10 .aar format Zip archive Structure is similar to old-style library project /AndroidManifest.xml /classes.jar /res/ /R.txt /assets/ /libs/*.jar /jni//*.so /proguard.txt </li> <li> 11 A good library </li> <li> 12 Self sufficient plain java jar-file ? maven plain java jar? maven Android jar ? - dependencies +/- obfuscation - AndroidManifest.xml </li> <li> 13 Friendly Does not create conflicts with other libraries </li> <li> 14 Stable Behavior does not change over time </li> <li> 15 Building next-gen Android library The right way </li> <li> 16 Key components /AndroidManifest.xml /classes.jar /res/ /R.txt /assets/ /libs/*.jar /jni//*.so /proguard.txt </li> <li> 17 Resources Lint will warn you! android { resourcePrefix 'mylib_' } Use resource prefix for library resources </li> <li> 18 Obfuscation. DONTs for library -repackageclasses -allowaccessmodification // hidden -&gt; public a.class b.class a.class b.class first.jar second.jar error: duplicate class </li> <li> 19 Obfuscation. Rules for users Will be packaged into aar defaultConfig { consumerProguardFiles pro-consumer.txt } </li> <li> 20 Dependencies. Stable vs dynamic versions Stable versions give stable builds dependencies { // 1.6.0 only compile com.squareup.okhttp:okhttp:1.6.0 // Latest version compile com.squareup.okhttp:okhttp:+ } Dynamic versions do not require redeploy Use stable versions for library dependencies </li> <li> 21 Dependencies. Maven only! Whats wrong with local jars? libs/ lib-1.0.jar libs/ lib-1.0.jar first.aar second.aar error: duplicate class </li> <li> 22 Manifest. Static values Will be copies into apps manifest file as is. 23 Manifest. Dynamic values 1 defaultConfig { manifestPlaceholders = [ userAppPackage: "${packageName} ] } Librarys build.gradle Librarys AndroidManifest.xml </li> <li> 24 Manifest. Dynamic values 2 Will give in librarys aar AndroidManifest.xml </li> <li> 25 Manifest. Dynamic values 3 Librarys aar AndroidManifest.xml Applications build.gradle defaultConfig { packageName = "com.my.app } </li> <li> 26 How to use it depending on your build system </li> <li> 27 Case 1. Using Eclipse, etc 1. Unzip aar 2. Attach as library project 3. Add classes.jar (and libs/) to classpath 4. Add native libraries 5. Add proguard entries 6. </li> <li> 28 Case 2. Using Gradle &amp; local aar project-folder/ build.gradle repo/library-1.0.aar repositories { flatDir { dirs repo } } dependencies { compile com.company:library:1.0@aar } </li> <li> 29 Case 3. Using Gradle &amp; Maven dependencies { compile com.company:library:1.0 // or compile com.company:library:1.0@aar } </li> <li> 30 Whats next? </li> <li> 31 Uncovered topics Maven Central publication Multiple library variant generation Native libraries </li> <li> 32 Thank you for your attention! Anton Rutkevich antonrut@yandex-team.ru anton.rutkevich@gmail.com </li> </ul>

Recommended

View more >