Skip to content

Commit

Permalink
Integrate Android example (#275)
Browse files Browse the repository at this point in the history
* Upgrade Gradle version to 8.0
* Refactor Android example
* Add 2 Android gradle plugins (without applying) to the root build (haven't managed to isolate them in Android example module)
* Add android.useAndroidX property to the root gradle.properties (for some reason defining this property in the Android submodule doesn't work)
* Add libp2p.gradle.custom per project property which indicates whether common gradle code for submodules should be skipped (set it up for Adnroid example)
* Move Maven repositories definitions to settings.gradle
* In the settings.gradle detect if Android SDK is installed and conditionally include :examples:android-chatter module
* Add Setup Android SDK GitHub action
  • Loading branch information
Nashatyrev committed May 17, 2023
1 parent 70f712b commit 98df084
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 305 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Setup Android SDK
uses: android-actions/setup-android@v2

- name: Execute Gradle build
run: ./gradlew -s build dokkaJar
25 changes: 17 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import java.net.URL
description = "a minimal implementation of libp2p for the jvm"

plugins {
kotlin("jvm").version("1.6.21")
val kotlinVersion = "1.6.21"

id("org.jetbrains.kotlin.jvm") version kotlinVersion apply false

id("com.github.ben-manes.versions").version("0.44.0")
id("idea")
Expand All @@ -19,28 +21,35 @@ plugins {
id("org.jmailen.kotlinter").version("3.10.0")
id("java-test-fixtures")
id("io.spring.dependency-management").version("1.1.0")

id("org.jetbrains.kotlin.android") version kotlinVersion apply false
id("com.android.application") version "7.4.2" apply false
}

allprojects {
fun Project.getBooleanPropertyOrFalse(propName: String) =
(this.properties[propName] as? String)?.toBoolean() ?: false

configure(
allprojects
.filterNot {
it.getBooleanPropertyOrFalse("libp2p.gradle.custom")
}
) {
group = "io.libp2p"
version = "develop"

apply(plugin = "kotlin")
apply(plugin = "idea")
apply(plugin = "io.gitlab.arturbosch.detekt")
apply(plugin = "java")

apply(plugin = "io.gitlab.arturbosch.detekt")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "org.jmailen.kotlinter")
apply(plugin = "java-test-fixtures")
apply(plugin = "io.spring.dependency-management")
apply(from = "$rootDir/versions.gradle")

repositories {
mavenCentral()
maven("https://artifacts.consensys.net/public/maven/maven/")
}

dependencies {

implementation(kotlin("stdlib-jdk8"))
Expand Down
58 changes: 23 additions & 35 deletions examples/android-chatter/build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"

}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

repositories {
google()
}

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: "io.spring.dependency-management"
apply from: "$rootDir/versions.gradle"

android {
compileSdkVersion 28
namespace = "io.libp2p.example.chat"
compileSdkVersion 30
defaultConfig {
applicationId "io.libp2p.example.chatter"
minSdkVersion 28
targetSdkVersion 28
applicationId "io.libp2p.example.chat"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -38,20 +22,24 @@ android {
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
}
kotlinOptions {
jvmTarget = "11"
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 1.11
targetCompatibility = 1.11
}
lint {
abortOnError = false
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(':chatter')
annotationProcessor 'org.apache.logging.log4j:log4j-core:2.11.2'
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("com.google.android.material:material:1.2.0")
implementation("androidx.constraintlayout:constraintlayout:2.0.4")
implementation project(':examples:chatter')
}
1 change: 1 addition & 0 deletions examples/android-chatter/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libp2p.gradle.custom = true
3 changes: 1 addition & 2 deletions examples/android-chatter/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.libp2p.example.chat">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import java.util.concurrent.CompletableFuture.runAsync


class MainActivity : AppCompatActivity() {
private lateinit var chatScroller: ScrollView
private lateinit var chatWindow: TextView
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
kotlin.code.style=official

org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx1G
android.useAndroidX=true
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu May 11 18:05:55 GST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=7ba68c54029790ab444b39d7e293d3236b2632631fb5f2e012bb28b4ff669e4b
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 98df084

Please sign in to comment.