Skip to content

Commit

Permalink
Merge pull request #86 from compscidr/jason/lib-repackage
Browse files Browse the repository at this point in the history
Repackage into a library
  • Loading branch information
compscidr authored Aug 6, 2024
2 parents 559a298 + 0e1fe1d commit f1a0a61
Show file tree
Hide file tree
Showing 55 changed files with 914 additions and 19 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and Deploy

on:
push:
# Pattern matched against refs/tags
tags:
- '*' # Push events to every tag not containing /

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "This job is running on a ${{ runner.os }} server hosted by GitHub!"
- uses: actions/checkout@v4
- run: echo "The ${{ github.repository }} repository has been cloned."
- run: echo "Setting up JDK"
- name: set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- run: echo "Setting up cmake"
- run: sudo apt install build-essential cmake
- run: echo "The workflow is now ready to test your code."
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- run: echo "Building Debug APK."
- name: Build with Gradle
run: ./gradlew build
- run: echo "Build status report=${{ job.status }}."
- name: Deploy to Sonatype / Maven Central
run: ./gradlew -PcentralPortalToken=${{ secrets.CENTRAL_PORTAL_TOKEN }} -PcentralPortalPassword=${{ secrets.CENTRAL_PORTAL_PASSWORD }} -PsigningKeyId=${{ secrets.SIGNING_KEY_ID }} -PsigningKeyPassword=${{ secrets.SIGNING_KEY_PASSWORD }} -PsigningKey=${{ secrets.SIGNING_KEY }} deployAll
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Push
name: Build and Test

on:
push:
Expand All @@ -16,15 +16,15 @@ jobs:
- uses: actions/checkout@v4
- run: echo "The ${{ github.repository }} repository has been cloned."
- run: echo "Setting up JDK"
- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- run: echo "Setting up cmake"
- run: sudo apt install build-essential cmake
- run: echo "The workflow is now ready to test your code."
# - run: echo "Setting up cmake"
# - run: sudo apt install build-essential cmake
# - run: echo "The workflow is now ready to test your code."
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- run: echo "Building Debug APK."
Expand Down
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Based on https://github.com/kirillF/icmp-android but updated to work on modern android

## Todo:
- [ ] Structure into a library and an app that uses it
- [x] Structure into a library and an app that uses it
- [ ] Release the library to maven central so it can be used
- [ ] Update the UI in the sample app so that users can select the IP to ping
- [ ] Ensure it works for ipv4 and ipv6
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.org.jetbrains.kotlin.android) apply false
alias(libs.plugins.android.library) apply false
}
File renamed without changes.
13 changes: 2 additions & 11 deletions app/build.gradle.kts → example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ android {

defaultConfig {
applicationId = "com.github.compscidr.icmp_android"
minSdk = 29
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
}
}
}

buildTypes {
Expand All @@ -37,15 +33,10 @@ android {
buildFeatures {
viewBinding = true
}
externalNativeBuild {
cmake {
path(file("src/main/cpp/CMakeLists.txt"))
version = "3.22.1"
}
}
}

dependencies {
implementation(project(":icmp-lib"))
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
android-library = { id = "com.android.library", version.ref = "agp" }
git-version = { id = "me.qoomon.git-versioning", version = "6.4.2" }
sonatype-maven-central = { id = "com.vanniktech.maven.publish", version = "0.28.0" }
gradleup-nmcp = { id = "com.gradleup.nmcp", version = "0.0.7"}
1 change: 1 addition & 0 deletions icmp-lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
122 changes: 122 additions & 0 deletions icmp-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
alias(libs.plugins.git.version) // https://stackoverflow.com/a/71212144
alias(libs.plugins.sonatype.maven.central)
alias(libs.plugins.gradleup.nmcp)
id("signing") // https://medium.com/nerd-for-tech/oh-no-another-publishing-android-artifacts-to-maven-central-guide-9d7f300ebd74
}

android {
namespace = "com.jasonernst.icmp_lib"
compileSdk = 34

defaultConfig {
minSdk = 24

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
externalNativeBuild {
cmake {
path(file("src/main/cpp/CMakeLists.txt"))
version = "3.22.1"
}
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}

version = "0.0.0-SNAPSHOT"
gitVersioning.apply {
refs {
branch(".+") { version = "\${ref}-SNAPSHOT" }
tag("v(?<version>.*)") { version = "\${ref.version}" }
}
}

nmcp {
val props = project.properties
publishAllPublications {
username = props["centralPortalToken"] as String? ?: ""
password = props["centralPortalPassword"] as String? ?: ""
// or if you want to publish automatically
publicationType = "AUTOMATIC"
}
}

mavenPublishing {
coordinates("com.jasonernst.icmp_lib", "icmp_lib", version.toString())
pom {
name = "ICMP Android"
description = "A library for sending and receiving ICMP packets on Android"
inceptionYear = "2024"
url = "https://github.com/compscidr/icmp-android"
licenses {
license {
name = "GPL-3.0"
url = "https://www.gnu.org/licenses/gpl-3.0.en.html"
distribution = "repo"
}
}
developers {
developer {
id = "compscidr"
name = "Jason Ernst"
url = "https://www.jasonernst.com"
}
}
scm {
url = "https://github.com/compscidr/icmp-android"
connection = "scm:git:git://github.com/compscidr/icmp-android.git"
developerConnection = "scm:git:ssh://[email protected]/compscidr/icmp-android.git"
}
}
}

// https://opensource.deepmedia.io/deployer
// https://blog.deepmedia.io/post/how-to-publish-to-maven-central-in-2024
//deployer {
// projectInfo {
// description = "A library for sending and receiving ICMP packets on Android"
// url = "https://github.com/compscidr/icmp-android/"
// groupId = "com.jasonernst"
// artifactId = "icmp-android"
// license("GPL-3.0", "https://www.gnu.org/licenses/gpl-3.0.en.html")
// developer("compscidr", "[email protected]", "Jason Ernst", "https://www.jasonernst.com")
// }
//
// centralPortalSpec {
// // Take these credentials from the Generate User Token page at https://central.sonatype.com/account
// auth.user.set(secret("centralPortalToken"))
// auth.password.set(secret("centralPortalPassword"))
//
// // Signing is required
// signing.key.set(secret("signingKey"))
// signing.password.set(secret("signingKeyPassword"))
// }
//}
Empty file added icmp-lib/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions icmp-lib/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jasonernst.icmp_lib

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.jasonernst.icmp_lib.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions icmp-lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions icmp-lib/src/test/java/com/jasonernst/icmp_lib/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jasonernst.icmp_lib

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dependencyResolutionManagement {
}
}
rootProject.name = "icmp-android"
include(":app")
include(":example")
include(":icmp-lib")

0 comments on commit f1a0a61

Please sign in to comment.