如果您使用的是新的 android studio 版本和 gradle 7.0.3
Android Studio 北极狐 | 2020.3.1 补丁 3
构建 #AI-203.7717.56.2031.7784292,构建于 2021 年 10 月 1 日
运行时版本:11.0.10+0-b96-7249189 amd64
虚拟机:Oracle 公司的 OpenJDK 64 位服务器虚拟机
视窗 10 10.0
GC:G1年轻代,G1老年代
内存:1280M
核心:2
注册表:external.system.auto.import.disabled=true
创建模块
- 使用空活动创建新项目
- 点击文件->新建->新模块->选择android库。
- 创建新模块后,您可以添加 java 类或其他东西
你的图书馆
将库导出到 AAR 文件
您可以查看this了解更多信息
将库导出到 jitpack.io
这样设置这个文件
build.gradle(项目)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (module:app)
plugins {
id 'com.android.application'
}
android {
lintOptions {
abortOnError false
}
}
android {
compileSdk 31
defaultConfig {
minSdk 16
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
build.gradle(模块:YourLibraryName)
plugins {
id 'com.android.library'
id 'maven-publish'
}
task androidSourcesJar(type: Jar) {
classifier 'sources'
from android.sourceSets.main.java.srcDirs
}
project.afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId 'com.github.YourGithubUsername'
from components.release
artifact androidSourcesJar // optional sources
}
}
}
}
android {
compileSdk 31
defaultConfig {
minSdk 16
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
在根项目(YourProjectName -> Gradle -> 右键 -> 新建 -> 文件 -> 将其命名为“jitpack.yml”并将此代码放入 jitpack.yml 文件中创建文件 jitpack.yml
jdk:
- openjdk11
before_install:
- chmod +x gradlew
install:
# - ./gradlew build :lib:publishToMavenLocal
- ./gradlew build publishToMavenLocal
Share your project to Github
访问jitpack网站
按照this 步骤上传您的库