diff --git a/README.md b/README.md index ba66a91..ec1039a 100644 --- a/README.md +++ b/README.md @@ -6,23 +6,25 @@ Example Android library project that works with jitpack.io. See this [Tutorial](https://medium.com/@ome450901/publish-an-android-library-by-jitpack-a0342684cbd0) on how to publish an Android Library with JitPack. -For more details check out the [documentation](https://github.com/jitpack/jitpack.io/blob/master/ANDROID.md) +For more details check out the [documentation](https://docs.jitpack.io/android/) https://jitpack.io/#jitpack/android-example -Add it to your build.gradle with: +Add it to your settings.gradle with: ```gradle -allprojects { - repositories { - maven { url "https://jitpack.io" } - } -} + dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + mavenCentral() + maven { url 'https://jitpack.io' } + } + } ``` and: ```gradle dependencies { - compile 'com.github.jitpack:android-example:{latest version}' + implementation 'com.github.jitpack:android-example:{latest version}' } ``` @@ -33,16 +35,31 @@ https://github.com/jitpack-io/android-jitpack-library-example ## Adding the maven plugin -To enable installing into local maven repository and JitPack you need to add the [android-maven](https://github.com/dcendents/android-maven-gradle-plugin) plugin: +To enable installing into local maven repository and JitPack you need to add the [maven-publish](https://developer.android.com/studio/build/maven-publish-plugin) plugin: -1. Add `classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'` to root build.gradle under `buildscript { dependencies {` -2. Add `com.github.dcendents.android-maven` to the library/build.gradle +Then add the publishing section to your library build.gradle: +```gradle +publishing { + publications { + release(MavenPublication) { + groupId = 'com.my-company' + artifactId = 'my-library' + version = '1.0' + + afterEvaluate { + from components.release + } + } + } +} +``` After these changes you should be able to run: - ./gradlew install + ./gradlew publishToMavenLocal -from the root of your project. If install works and you have added a GitHub release it should work on jitpack.io +from the root of your project. +If `publishToMavenLocal` works and you have added a GitHub release it should work on jitpack.io ## Adding a sample app diff --git a/build.gradle b/build.gradle index 07a3910..dd5a3dc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,23 +1,12 @@ buildscript { - ext.kotlin_version = "1.6.10" + ext.kotlin_version = "1.8.20" repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.2' + classpath 'com.android.tools.build:gradle:8.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } -allprojects { - repositories { - google() - maven { url "https://jitpack.io" } - mavenCentral() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e589..19cfad9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..bbaedec --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,3 @@ +jdk: + - openjdk17 + diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/library/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index eaa0646..f4f5bb5 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,20 +1,18 @@ plugins { id 'com.android.library' - id 'kotlin-android' + id 'org.jetbrains.kotlin.android' id 'maven-publish' } -group = 'com.github.jitpack' -version = '1.0' - android { - compileSdkVersion 31 + namespace 'io.jitpack.library' + compileSdk 34 defaultConfig { - minSdkVersion 21 - targetSdkVersion 31 - versionCode 1 - versionName "1.0" + minSdk 24 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" } buildTypes { @@ -23,28 +21,33 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '11' } } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.core:core-ktx:1.15.0' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } -afterEvaluate { - publishing { - publications { - // Creates a Maven publication called "release". - release(MavenPublication) { +publishing { + publications { + release(MavenPublication) { + groupId = 'io.jitpack' + artifactId = 'library' + version = '1.0' + + afterEvaluate { from components.release - groupId = 'com.github.jitpack' - artifactId = 'android-example' - version = '1.0' } } } diff --git a/library/src/main/kotlin/io/jitpack/api/JitPack.kt b/library/consumer-rules.pro similarity index 100% rename from library/src/main/kotlin/io/jitpack/api/JitPack.kt rename to library/consumer-rules.pro diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro index bb15926..481bb43 100644 --- a/library/proguard-rules.pro +++ b/library/proguard-rules.pro @@ -1,11 +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 -# Add any project specific keep options here: - # 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 \ No newline at end of file diff --git a/library/src/androidTest/java/io/jitpack/library/ExampleInstrumentedTest.kt b/library/src/androidTest/java/io/jitpack/library/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..b4119a3 --- /dev/null +++ b/library/src/androidTest/java/io/jitpack/library/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package io.jitpack.library + +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("io.jitpack.library.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 4aefbf3..a5918e6 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + + - - - + \ No newline at end of file diff --git a/library/src/test/java/io/jitpack/library/ExampleUnitTest.kt b/library/src/test/java/io/jitpack/library/ExampleUnitTest.kt new file mode 100644 index 0000000..a82ead2 --- /dev/null +++ b/library/src/test/java/io/jitpack/library/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package io.jitpack.library + +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) + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index d8f14a1..a726ca5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,10 @@ include ':library' + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + maven { url 'https://jitpack.io' } + } +}