You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向Jitpack上传Android库时遇错误求助

问题

我正尝试将Java编写的Android库上传至jitpack.io,以下是相关配置和报错信息:

库的build.gradle文件

plugins {
    id 'com.android.library'
    id 'maven-publish'
}

android {
    compileSdkVersion 33
    buildToolsVersion "30.0.3"

    defaultConfig {
        minSdkVersion 28
        targetSdkVersion 33
        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.6.1'
//    implementation 'com.google.android.material:material:1.9.0'
    implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

publishing {
    publications {
        release(MavenPublication) {
            groupId = 'com.github.my_github_id'
            artifactId = 'my_library'
            version = '1.0'

            afterEvaluate {
                from components.release
            }
        }
    }
}

Jitpack构建日志

Gradle 'publishToMavenLocal' task not found. Please add the 'maven-publish' or 'maven' plugin.
 See the documentation and examples: https://docs.jitpack.io

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
/home/jitpack/build/upi/build.gradle has component: release
Running: ./gradlew -Pgroup=com.github.my_github_id -Pversion=1.0 publishToMavenLocal
Build-tool 32.0.0 is missing DX at /opt/android-sdk-linux/build-tools/32.0.0/dx
Build-tool 32.0.0 is missing DX at /opt/android-sdk-linux/build-tools/32.0.0/dx
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':upi:compileReleaseAidl'.
> Installed Build Tools revision 32.0.0 is corrupted. Remove and install again using the SDK Manager.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 862ms
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Archive: my_android_project_name:my_library:unspecified
Publication: com.github.my_github_id:my_library:1.0
Publication: my_android_project_name:my_library:unspecified
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
Found artifact: com.github.my_github_id:my_library:1.0
Found artifact: my_android_project:my_library:unspecified
2023-08-23T18:28:11.758414916Z
Exit code: 0

ERROR: No build artifacts found
Expected artifacts in: $HOME/.m2/repository/my_android_project/my_library/unspecified

jitpack.yml配置

jdk:
  - openjdk8

我使用的是最新版本的Gradle和Android Studio,已尝试多种解决方案但均未奏效,由于这是我首次发布库,可能遗漏了某些要点,恳请帮助。


解决方案

1. 修复Build Tools版本问题

日志明确提示Jitpack环境中的Build Tools 32.0.0损坏,直接指定稳定且兼容的版本,替换android块中的buildToolsVersion:

buildToolsVersion "33.0.2"

2. 调整Maven发布配置避免冲突

Jitpack会自动传入group和version参数,硬编码值会导致产物路径混乱,修改publishing块:

publishing {
    publications {
        release(MavenPublication) {
            groupId = project.findProperty("group") ?: "com.github.my_github_id"
            artifactId = "my_library"
            version = project.findProperty("version") ?: "1.0"

            afterEvaluate {
                from components.release
            }
        }
    }
}

3. 更新jitpack.yml指定SDK组件

在配置文件中强制安装指定版本的Build Tools,避免Jitpack拉取损坏版本:

jdk:
  - openjdk8
install:
  - sdkmanager "build-tools;33.0.2"

4. 匹配Android Gradle插件版本

根项目的build.gradle中,使用与compileSdkVersion 33兼容的插件版本(如7.4.2):

plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
}

5. 本地预验证

先在本地执行./gradlew publishToMavenLocal,确认产物能正常生成到本地Maven仓库,再推送代码到GitHub触发Jitpack构建。


内容的提问来源于stack exchange,提问作者George

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 09:14:55