Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Create an Android plugin using Kotlin
Search
Bruno Oliveira
September 24, 2016
Programming
77
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Create an Android plugin using Kotlin
Presentation @Google Developers Group Lisbon
27/09/2016
Bruno Oliveira
September 24, 2016
Transcript
30 slides
Create your Gradle plugin using Kotlin Bruno Oliveira Mobile developer
@Faber-Ventures
Build a Gradle plugin using Kotlin • Why Kotlin •
Localizable.io • Android specific plugin • Build the plugin step-by-step
Localizable.io • Managing strings in a live app is a
problem
Localizable.io • Making the developer life easier
Localizable.io • Change directly in Produc3on
Our vision • Localizable.setup(this) • Localizable.getString(R.string.welcome) • Localizable.availableLocales() • Localizable.setLocale(Localizable.availableLocales().get(0))
Our vision
Why do we need a plugin? • Build (me analyse
android resources • Parse generated values folders • Extract Strings • Manifest • Make a seamless experience
What/How are we doing with it? • Extract strings from
values • Cache and send to server • Try to automate as much as possible
Biggest problems at start • Android studio • Trying to
implement the sample right in the same project • Deploy development dependency to local maven repo
Let's start
Let's start
Let's start
Setup dependencies aka build.gradle • Kotlin • GradleApi • Build
Tools apply plugin: "kotlin" dependencies { compile gradleApi() compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.3" compile "com.android.tools.build:gradle:2.1.3" }
Declare a plugin • src/main/resources/META-INF.gradle-plugins
Declare a plugin • Plugin class class LocalizablePlugin : Plugin<Project>
{ override fun apply(project: Project?) { project?.let { ProjectHandler(it).createTasks() } } }
Declare a plugin • Use the plugin apply plugin: 'localizable'
buildscript { dependencies { classpath "io.localizable:sync:1.0.4-SNAPSHOT" } }
When tasks added fun createTasks() { if (!isAndroidProject) { throw
Throwable("You should apply android to your project first") } tasks.whenTaskAdded { handleTask(it) } }
Android build tools check private val isAndroidProject: Boolean by lazy
{ project.plugins.hasPlugin(AppPlugin::class.java) } private val appExtension: AppExtension by lazy { project.extensions.getByType(AppExtension::class.java) } private val flavorNames: List<String> by lazy { val configs = appExtension.productFlavors.map { it.name } if (configs.isNotEmpty()) configs else listOf("") } private val buildTypes: Collection<BuildType> by lazy { appExtension.buildTypes }
Handle everything • We don't wanna miss a thing. private
fun handleTask(task: Task) { buildTypes.forEach { build -> flavorNames.forEach { flavor -> processBuild(build.name, flavor, task) } } }
Find the One private fun processBuild(buildName: String, flavorName: String, task:
Task) { val taskAffix = LocalizableHelper.taskAffix(buildName, flavorName) val processTask = "process${taskAffix}Resources" if (processTask.equals(task.name)) { createLocalizableFromTask(task, taskAffix, buildName, flavorName) } }
Create a task val localizableTaskName = "localizable$taskAffix" val nTask =
project.task(localizableTaskName)
Execute • Execute block • Follow the behaviors • Use
the build cache folders if needed nTask.doFirst { val manifest = LocalizableHelper.manifestFileForTarget(project, buildName, flavorName) if (manifest == null) { println("Could not find any manifest file") return@doFirst } nTask.didWork = LocalizableTask(project, manifest, localizableTaskName).syncResources() }
Add task to Android stack • Task in the middle
• mergeDebugEpicResources > localizableEpicResources > ProcessDebugEpicResources task.dependsOn(nTask) val mergeTask = "merge${taskAffix}Resources" project.tasks.getByName(localizableTaskName).dependsOn(mergeTask)
Execute order • mergeEpicDebugResources • localizableEpicDebugResources • processEpicDebugResources
Deploy locally Run the task - Command line ./gradlew :plugin:uploadArchives
uploadArchives { repositories { mavenDeployer { repository(url: mavenLocal().url) pom.groupId = GROUP_ID pom.artifactId = ARTIFACT_PLUGIN_ID pom.version = PLUGIN_VERSION } } }
Deploy locally Run the task - On interface
Debug :( • Network interceptor private val interceptor: HttpLoggingInterceptor by
lazy { val interceptor = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { println(" -> $it") }) interceptor.level = HttpLoggingInterceptor.Level.BODY interceptor }
Deploy to Maven • guide to maven • h/p:/ /zserge.com/blog/gradle-maven-publish.html
• jitpack • jitpack.io
Contacts •
[email protected]
• github.com/bmoliveira • twi5er.com/_bmoliveira Localizable.io
More Decks by Bruno Oliveira
See All by Bruno Oliveira
Speedy Development with Kotlin
bmoliveira
1
82
Other Decks in Programming
See All in Programming
SODA - FACT BOOK(EN)
sodainc
1
290
正解の無い問題を 「できるだけ上手く」解く ヒューリスティックで感性を磨こう。〜現実課題をプログラミングで解きあうコミュニティについて〜
allegrogiken
0
120
Promiseの向こう側へコンテキストを届ける ― proposal-async-context
seriseri
0
630
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
280
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
180
Agentic AI with the Power of Jakarta EE
ivargrimstad
0
230
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
340
AIエージェントの「テストは通るのに本番で壊れる」を減らす
shibuiwilliam
3
130
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
自宅サーバはどこまで再現できるのか - Proxmox VE上のVM環境をIaCとバックアップで戻してみた
youto
0
450
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
710
SODA - FACT BOOK(JP)
sodainc
1
40k
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
550
The untapped power of vector embeddings
frankvandijk
2
2k
Well, that’s weird…
csswizardry
3
250
Speed Design
sergeychernyshev
33
2.3k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Become a Pro
speakerdeck
PRO
31
6.4k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
390
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
43k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Build your cross-platform service in a week with App Engine
jlugia
234
19k