SlideShare una empresa de Scribd logo
1 de 32
1
2
Building next-gen
Android library
with Gradle
Anton Rutkevich
Android developer
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
4
Old-style library projects
The past, the present…
5
What’s wrong?
• Hard to update
• Hard to distribute
• Eclipse, eclipse…
6
Gradle &
The New Build System
The present, the future…
7
Gradle - build automation evolved
• Build scripts on Groovy
• Flexible build setup
• Runs everywhere (Java required)
• Dependency management
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’)
}
9
The New Build System
• Brings Gradle features to Android builds
• Provides Android Studio integration
10
.aar format
• Zip archive
• Structure is similar to old-style library project
• /AndroidManifest.xml
• /classes.jar
• /res/
• /R.txt
• /assets/
• /libs/*.jar
• /jni/<abi>/*.so
• /proguard.txt
11
A good library
12
Self sufficient
• plain java jar-file ?
• maven plain java jar?
• maven Android jar ?
- dependencies
+/- obfuscation
- AndroidManifest.xml
13
Friendly
• Does not create conflicts with other
libraries
14
Stable
• Behavior does not change over time
15
Building next-gen
Android library
The right way
16
Key components
/AndroidManifest.xml
/classes.jar
/res/
/R.txt
/assets/
/libs/*.jar
/jni/<abi>/*.so
/proguard.txt
17
Resources
Lint will warn you!
android {
resourcePrefix 'mylib_'
}
Use resource prefix for library resources
18
Obfuscation. DON’Ts for library
-repackageclasses ‘’
-allowaccessmodification
// hidden -> public
a.class
b.class
…
a.class
b.class
…
first.jar second.jar
error:
duplicate class
19
Obfuscation. Rules for users
Will be packaged into aar
defaultConfig {
consumerProguardFiles ‘pro-consumer.txt’
}
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
21
Dependencies. Maven only!
What’s wrong with
local jars?
libs/
lib-1.0.jar
libs/
lib-1.0.jar
first.aar second.aar
error:
duplicate class
22
Manifest. Static values
Will be copies into app’s manifest file ‘as is’.
<uses-permission android:name="android.permission.INTERNET"
/>
<application>
<activity android:name="com.my.app.SomeActivity”/>
</application>
Include required values only!
23
Manifest. Dynamic values 1
defaultConfig {
manifestPlaceholders
= [ userAppPackage: "${packageName}” ]
}
<uses-permission
android:name="${userAppPackage}.LIB_PERMISSION" />
Library’s build.gradle
Library’s AndroidManifest.xml
24
Manifest. Dynamic values 2
<uses-permission
android:name="${packageName}.LIB_PERMISSION" />
Will give
in library’s aar AndroidManifest.xml
25
Manifest. Dynamic values 3
Library’s aar AndroidManifest.xml
Application’s build.gradle
<uses-permission
android:name="${packageName}.LIB_PERMISSION" />
defaultConfig {
packageName = "com.my.app”
}
26
How to use it
depending on your build system
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. …
28
Case 2. Using Gradle & local aar
project-folder/
build.gradle
repo/library-1.0.aar
repositories {
flatDir { dirs ‘repo’ }
}
dependencies {
compile ‘com.company:library:1.0@aar’
}
29
Case 3. Using Gradle & Maven
dependencies {
compile ‘com.company:library:1.0’
// or
compile ‘com.company:library:1.0@aar’
}
30
What’s next?
31
Uncovered topics
• Maven Central publication
• Multiple library variant generation
• Native libraries
• …
32
Thank you for your attention!
Anton Rutkevich
antonrut@yandex-team.ru
anton.rutkevich@gmail.com

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
ECS19 - Daniel Neumann - AZURE FUNCTIONS 2.0 - RUNNING SERVERLESS EVERYWHERE
ECS19 - Daniel Neumann - AZURE FUNCTIONS 2.0 - RUNNING SERVERLESS EVERYWHEREECS19 - Daniel Neumann - AZURE FUNCTIONS 2.0 - RUNNING SERVERLESS EVERYWHERE
ECS19 - Daniel Neumann - AZURE FUNCTIONS 2.0 - RUNNING SERVERLESS EVERYWHERE
 
AWS for the Java Developer
AWS for the Java DeveloperAWS for the Java Developer
AWS for the Java Developer
 
Building Scalable Applications with Laravel
Building Scalable Applications with LaravelBuilding Scalable Applications with Laravel
Building Scalable Applications with Laravel
 
Presentation1
Presentation1Presentation1
Presentation1
 
React native: building native iOS apps with javascript
React native: building native iOS apps with javascriptReact native: building native iOS apps with javascript
React native: building native iOS apps with javascript
 
Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and YouApache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and You
 
Docker - A Container Full of Chocolatey
Docker - A Container Full of ChocolateyDocker - A Container Full of Chocolatey
Docker - A Container Full of Chocolatey
 
Managing Changes to the Database Across the Project Life Cycle (presented by ...
Managing Changes to the Database Across the Project Life Cycle (presented by ...Managing Changes to the Database Across the Project Life Cycle (presented by ...
Managing Changes to the Database Across the Project Life Cycle (presented by ...
 
Joe Damato
Joe DamatoJoe Damato
Joe Damato
 
Kiss.ts - The Keep It Simple Software Stack for 2017++
Kiss.ts - The Keep It Simple Software Stack for 2017++Kiss.ts - The Keep It Simple Software Stack for 2017++
Kiss.ts - The Keep It Simple Software Stack for 2017++
 
Quick dive into Ruby on Rails
Quick dive into Ruby on RailsQuick dive into Ruby on Rails
Quick dive into Ruby on Rails
 
Queick: A Simple Job Queue System for Python
Queick: A Simple Job Queue System for PythonQueick: A Simple Job Queue System for Python
Queick: A Simple Job Queue System for Python
 
CodeFlow, an advanced IDE for Lua
CodeFlow, an advanced IDE for LuaCodeFlow, an advanced IDE for Lua
CodeFlow, an advanced IDE for Lua
 
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
 
Skinny Framework 1.0.0
Skinny Framework 1.0.0Skinny Framework 1.0.0
Skinny Framework 1.0.0
 
Custom angular libraries
Custom angular librariesCustom angular libraries
Custom angular libraries
 
Native Script Overview
Native Script OverviewNative Script Overview
Native Script Overview
 
SGCE 2015 REST APIs
SGCE 2015 REST APIsSGCE 2015 REST APIs
SGCE 2015 REST APIs
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 

Similar a Building next gen android library with gradle

Антон Руткевич, Сборка Android-библиотеки нового поколения с помощью Gradle
Антон Руткевич, Сборка Android-библиотеки нового поколения с помощью GradleАнтон Руткевич, Сборка Android-библиотеки нового поколения с помощью Gradle
Антон Руткевич, Сборка Android-библиотеки нового поколения с помощью Gradle
Yandex
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build Technology
Philip Johnson
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
Fabio Fumarola
 

Similar a Building next gen android library with gradle (20)

Антон Руткевич, Сборка Android-библиотеки нового поколения с помощью Gradle
Антон Руткевич, Сборка Android-библиотеки нового поколения с помощью GradleАнтон Руткевич, Сборка Android-библиотеки нового поколения с помощью Gradle
Антон Руткевич, Сборка Android-библиотеки нового поколения с помощью Gradle
 
Building an Ionic hybrid mobile app with TypeScript
Building an Ionic hybrid mobile app with TypeScript Building an Ionic hybrid mobile app with TypeScript
Building an Ionic hybrid mobile app with TypeScript
 
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Libraries
 
Android Internal Library Management
Android Internal Library ManagementAndroid Internal Library Management
Android Internal Library Management
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
 
Deploying artifacts to archiva
Deploying artifacts to archivaDeploying artifacts to archiva
Deploying artifacts to archiva
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build Technology
 
Patterns in a Containerized World (Matthias Luebken Technology Stream)
Patterns in a Containerized World (Matthias Luebken Technology Stream)Patterns in a Containerized World (Matthias Luebken Technology Stream)
Patterns in a Containerized World (Matthias Luebken Technology Stream)
 
New Perl module Container::Buildah - SVPerl presentation
New Perl module Container::Buildah - SVPerl presentationNew Perl module Container::Buildah - SVPerl presentation
New Perl module Container::Buildah - SVPerl presentation
 
Building Distributed Systems without Docker, Using Docker Plumbing Projects -...
Building Distributed Systems without Docker, Using Docker Plumbing Projects -...Building Distributed Systems without Docker, Using Docker Plumbing Projects -...
Building Distributed Systems without Docker, Using Docker Plumbing Projects -...
 
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
 
Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)
 
Gradle
GradleGradle
Gradle
 
Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)
 
OpenStack Summit
OpenStack SummitOpenStack Summit
OpenStack Summit
 
Introduction to Containers & Diving a little deeper into the benefits of Con...
 Introduction to Containers & Diving a little deeper into the benefits of Con... Introduction to Containers & Diving a little deeper into the benefits of Con...
Introduction to Containers & Diving a little deeper into the benefits of Con...
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
 
Container Patterns
Container PatternsContainer Patterns
Container Patterns
 
Docker
DockerDocker
Docker
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 

Building next gen android library with gradle