Skip to content

Instantly share code, notes, and snippets.

View PaoloMilano's full-sized avatar

PaoloMilano

View GitHub Profile
"Buddy" : {
//Connesione tra utente 1 e 2
"<id generata da firebase>" : {
//Utente 1
"f0Wr68igQjYQ5WcqCrONxDFzOBQ2" : {
"Like" : 0
},
//Utente 2
"hXEacGlT7NSqIsOiHK14ysz4Z312" : {
"Like" : 0
rootProject.name='PluginSample'
include ':app', 'buildSrc'
apply plugin: 'java-gradle-plugin' // Allows us to create and configure custom plugins
apply plugin: 'kotlin' //Needed as we'll write our plugin in Kotlin
buildscript {
ext.kotlin_version = '1.3.71'
ext.gradle_version = '3.5.3'
repositories {
google()
jcenter()
}
class MyFirstPlugin : Plugin<Project> {
override fun apply(project: Project) {
// Magic goes here
}
}
fun Project.android(): BaseExtension {
val android = project.extensions.findByType(BaseExtension::class.java)
if (android != null) {
return android
} else {
throw GradleException("Project $name is not an Android project")
}
}
fun BaseExtension.variants(): DomainObjectSet<out BaseVariant> {
class MyFirstPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.android().variants().all { variant ->
// Make a task for each combination of build type and product flavor
val myTask = "myFirstTask${variant.name.capitalize()}"
// Register a simple task as a lambda. We can later move this to its own
// class to make our code cleaner and also add some niceties.
gradlePlugin {
plugins {
create("MyFirstPlugin") {
id = "MyFirstPlugin"
implementationClass = "MyFirstPlugin"
}
}
}
apply plugin: 'MyFirstPlugin'
<color name="color1"/>
<color name="color2"/>
<color name="color3"/>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/color_1_view"