maven { url ‘https://www.jitpack.io‘ }在新版Android Studio中的位置

本文讲述了在Android Studio升级到ArcticFox版本后,如何处理因库文件位置变化导致的引用问题,重点介绍了settings.gradle文件中新的配置要求,并展示了通过JitPack.io引入第三方库的正确步骤和常见警告处理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android Studio升级到Arctic Fox后,一些配置项的位置都做了改变。
github上的很多库通过JitPack.io发布的,引用这些库时,除了在模块的build.gradle文件中加入依赖,还要在项目的build.gradle文件中加入maven { url ‘https://www.jitpack.io’ },否则找不到库文件。如:

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

但是新版AS中,如果在项目的build.gradle中加入以上配置,同步时就会报错。把上面的配置删除,引用的库又无法找到。
新版AS中,这些配置放到了settings.gradle文件中,

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        //引用通过JitPack.io发布的第三方库
        maven { url 'https://www.jitpack.io' }
    }
}

回@西雨许954:
这里有一个很好用的吐司框架,我们在Gradle里导入它:
在这里插入图片描述
同步Gradle之后, 你会发现Build窗口里有一个警告:
在这里插入图片描述
完整的警告信息:

Failed to resolve: com.github.getActivity:ToastUtils:10.3
<a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Affected Modules: <a href="openFile:D:/Android/MyApplication/app/build.gradle">app</a>

如果这时候运行App,会报编译错误,拖到最下面,你会看到下图所示:
在这里插入图片描述
右边会显示错误信息:
在这里插入图片描述
这个库就是通过JitPack.io发布的,你需要在settings.gradle中添加配置项:
在这里插入图片描述
同步后再次运行App,没有任何问题了。

项目的build.gradle.kts文件如下: buildscript { repositories { google() mavenCentral() maven { url = uri("https://maven.aliyun.com/repository/public") } maven { url = uri("https://dl.bintray.com/openinstall/maven")} } dependencies { classpath("com.android.tools.build:gradle:8.10.1") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") } } repositories { google() } APP的build.gradle.kts文件如下: plugins { id("com.android.application") id("org.jetbrains.kotlin.android") } android { namespace = "com.example.gyppcx" // Kotlin DSL 使用等号赋值 compileSdk = 36 // 属性名是 compileSdk,不是 compileSdkVersion defaultConfig { applicationId = "com.example.gyppcx" // 使用等号赋值 minSdk = 26 // 属性名是 minSdk,不是 minSdkVersion //noinspection OldTargetApi,EditedTargetSdkVersion targetSdk = 34 // 属性名是 targetSdk,不是 targetSdkVersion versionCode = 1 versionName = "1.0" } signingConfigs { create("release") { storeFile = file("../gyppcx.jks") storePassword = "Liu=123456" keyAlias = "key0" keyPassword = "Liu=123456" } } buildTypes { release { signingConfig = signingConfigs.getByName("release") isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = "17" } buildFeatures { compose = true } composeOptions { kotlinCompilerExtensionVersion = "1.5.10" } } // 添加依赖项(如果有) repositories { google() mavenCentral() maven { url = uri("https://maven.aliyun.com/repository/public") } maven { url = uri("https://dl.bintray.com/openinstall/maven")} } dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) implementation("androidx.appcompat:appcompat:1.7.0") // 确保版本号与项目兼容 implementation("androidx.core:core-ktx:1.13.1") implementation("androidx.webkit:webkit:1.10.0") implementation("com.google.android.material:material:1.11.0") testImplementation("org.junit.jupiter:junit-jupiter:5.10.1") implementation("androidx.compose.ui:ui:1.7.0") implementation("androidx.compose.material3:material3:1.3.0") implementation("androidx.compose.ui:ui-tooling-preview:1.7.0") debugImplementation("androidx.compose.ui:ui-tooling:1.7.0") implementation("androidx.activity:activity-compose:1.8.2") } dependencies { //implementation(files("libs/OpenInstall_v2.8.5.jar")) // 添加这行 implementation("com.openinstall:openinstall-sdk:latest_version") implementation("androidx.appcompat:appcompat:1.7.0") // 确保版本号与项目兼容 implementation("androidx.core:core-ktx:1.13.1") implementation("androidx.webkit:webkit:1.10.0") implementation("com.google.android.material:material:1.11.0") testImplementation("org.junit.jupiter:junit-jupiter:5.10.1") implementation("androidx.compose.ui:ui:1.7.0") implementation("androidx.compose.material3:material3:1.3.0") implementation("androidx.compose.ui:ui-tooling-preview:1.7.0") debugImplementation("androidx.compose.ui:ui-tooling:1.7.0") implementation("androidx.activity:activity-compose:1.8.2") } repositories { maven { url = uri("https://maven.aliyun.com/repository/public") } } build sync时报错如下: Failed to resolve: com.openinstall:openinstall-sdk:latest_version build output时报错如下: FAILURE: Build completed with 10 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseNativeLibs'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkReleaseDuplicateClasses'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 3: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkReleaseAarMetadata'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 4: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mapReleaseSourceSetPaths'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 5: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseResources'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 6: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:processReleaseMainManifest'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 7: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:desugarReleaseFileDependencies'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 8: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseArtProfile'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 9: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseAssets'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== 10: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:collectReleaseDependencies'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * 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. ============================================================================== Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.14.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD FAILED in 5s
最新发布
06-06
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值