diff --git a/Readme.md b/Readme.md index 57ac6d2..eeb4dc8 100644 --- a/Readme.md +++ b/Readme.md @@ -1,24 +1,38 @@ Room 数据持久化;Worker管理上传任务,初次上传+重试共5次,重试间隔10s线性增加;多上传任务顺序处理; 网络请求 Retrofit -### aar位置 -根目录 /aar/xxx/trackingPoint-xxx-x.x.x.aar ### debug release 区别 | BuildType | 域名 | 是否打印日志 | |----------|------|--------------| | debug | http://192.168.2.7:18828 | 是 | | release | https://track.23544.com | 否 | + ### 使用 -```groovy -/** - * 因为是本地引入AAR 所以需要手动导入下列必备依赖 版本可根据项目调整 - */ -implementation("com.squareup.retrofit2:retrofit:3.0.0") -implementation("com.squareup.retrofit2:converter-moshi:3.0.0") -implementation("com.squareup.okhttp3:logging-interceptor:5.3.2") -implementation("com.squareup.moshi:moshi:1.15.2") -implementation("androidx.work:work-runtime-ktx:2.11.0") -implementation("androidx.room:room-runtime:2.8.4") -implementation("androidx.room:room-ktx:2.8.4") +#### 1.0.4 +```kotlin +repositories { + google() + mavenCentral() + maven { + url = uri("http://192.168.2.14:8081/repository/maven-releases/") + isAllowInsecureProtocol = true + credentials { + username = "admin" + password = "qwer1234.." + } + } + maven { + url = uri("http://192.168.2.14:8081/repository/maven-snapshots/") + isAllowInsecureProtocol = true + credentials { + username = "admin" + password = "qwer1234.." + } + } +} +//测试环境 +debugImplementation("com.yuanxuan:tracking_point:x.x.x-SNAPSHOT") +//生产环境 +releaseImplementation("com.yuanxuan:tracking_point:x.x.x") ``` ```kotlin /** diff --git a/aar/debug/trackingPoint-debug-1.0.1.aar b/aar/debug/trackingPoint-debug-1.0.1.aar deleted file mode 100644 index 3d6b95a..0000000 Binary files a/aar/debug/trackingPoint-debug-1.0.1.aar and /dev/null differ diff --git a/aar/release/trackingPoint-release-1.0.1.aar b/aar/release/trackingPoint-release-1.0.1.aar deleted file mode 100644 index 932a4bc..0000000 Binary files a/aar/release/trackingPoint-release-1.0.1.aar and /dev/null differ diff --git a/gradle.properties b/gradle.properties index 20e2a01..bde6df6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,4 +20,10 @@ kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true +mavenReleaseRepoUrl=http://192.168.2.14:8081/repository/maven-releases/ +mavenDebugRepoUrl=http://192.168.2.14:8081/repository/maven-snapshots/ +mavenUsername=admin +mavenPassword=qwer1234.. +baseReleaseUrl=https://track.23544.com +baseDebugUrl=http://192.168.2.7:18828 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ee594ac..22eea78 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -39,6 +39,4 @@ androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = android-application = { id = "com.android.application", version.ref = "agp" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } android-library = { id = "com.android.library", version.ref = "agp" } -ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } -maven-publish = { id = "maven-publish" } - +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index b365a38..990f38b 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,12 +1,21 @@ -import org.gradle.api.tasks.Delete +import org.gradle.api.publish.maven.MavenPublication plugins { alias(libs.plugins.android.library) alias(libs.plugins.kotlin.android) alias(libs.plugins.ksp) + id("maven-publish") } +group = "com.yuanxuan" +version = "1.0.5" -version = "1.0.1" + +val baseReleaseUrl: Provider = providers.gradleProperty("baseReleaseUrl") +val baseDebugUrl: Provider = providers.gradleProperty("baseDebugUrl") +val mavenReleaseRepoUrl: Provider = providers.gradleProperty("mavenReleaseRepoUrl") +val mavenDebugRepoUrl: Provider = providers.gradleProperty("mavenDebugRepoUrl") +val mavenUsername: Provider = providers.gradleProperty("mavenUsername") +val mavenPassword: Provider = providers.gradleProperty("mavenPassword") android { namespace = "com.yuanxuan.tracking_point.library" @@ -21,10 +30,10 @@ android { buildTypes { debug { - buildConfigField("String", "BASE_URL", "\"http://192.168.2.7:18828\"") + buildConfigField("String", "BASE_URL", "\"${baseDebugUrl.get()}\"") } release { - buildConfigField("String", "BASE_URL", "\"https://track.23544.com\"") + buildConfigField("String", "BASE_URL", "\"${baseReleaseUrl.get()}\"") isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), @@ -37,10 +46,14 @@ android { targetCompatibility = JavaVersion.VERSION_11 } - buildFeatures { buildConfig = true } + + publishing { + singleVariant("debug") + singleVariant("release") + } } kotlin { @@ -51,6 +64,50 @@ ksp { arg("room.schemaLocation", "$projectDir/schemas") } +afterEvaluate { + publishing { + publications { + register("debug") { + groupId = project.group.toString() + artifactId = "tracking_point" + version = "${project.version}-SNAPSHOT" + + from(components["debug"]) + } + + register("release") { + groupId = project.group.toString() + artifactId = "tracking_point" + version = "${project.version}" + + from(components["release"]) + } + } + + repositories { + maven { + name = "debugRepo" + url = uri(mavenDebugRepoUrl.get()) + isAllowInsecureProtocol = true + credentials { + username = mavenUsername.get() + password = mavenPassword.get() + } + } + maven { + name = "releaseRepo" + url = uri(mavenReleaseRepoUrl.get()) + isAllowInsecureProtocol = true + credentials { + username = mavenUsername.get() + password = mavenPassword.get() + } + } + } + + } +} + dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.work.ktx) @@ -64,42 +121,12 @@ dependencies { ksp(libs.androidx.room.ksp) } -// Task to clean the 'aar' directory -tasks.register("cleanAar") { - group = "build" - description = "Deletes the root 'aar' directory to ensure a clean build." - delete(rootProject.file("aar")) -} - -tasks.register("buildAar") { - group = "build" - description = "Cleans, builds, and copies release and debug AARs." - - dependsOn("cleanAar", "assembleDebug", "assembleRelease") - - doLast { - val releaseDestDir = rootProject.file("aar/release") - val debugDestDir = rootProject.file("aar/debug") - val aarVersion = project.version - - copy { - from(layout.buildDirectory.file("outputs/aar/library-release.aar")) - into(releaseDestDir) - rename { "trackingPoint-release-$aarVersion.aar" } - } - - copy { - from(layout.buildDirectory.file("outputs/aar/library-debug.aar")) - into(debugDestDir) - rename { "trackingPoint-debug-$aarVersion.aar" } - } - - println( - """ - AARs have been built and copied: - - Release: ${releaseDestDir.absolutePath}/trackingPoint-release-$aarVersion.aar - - Debug: ${debugDestDir.absolutePath}/trackingPoint-debug-$aarVersion.aar - """.trimIndent() - ) - } +tasks.register("publishAll") { + group = "publishing" + description = "Publish both Debug and Release artifacts to their repositories." + + dependsOn( + "publishDebugPublicationToDebugRepoRepository", + "publishReleasePublicationToReleaseRepoRepository" + ) }