为什么 Android Studio 无法应用插件“com.cinnober.gradle.semver-git”?
敏锐的眼睛能发现上周困扰我的事情吗? 我克隆了这个存储库,但构建失败并出现以下异常:
失败:构建因异常而失败。
其中:脚本“C:\Users\MyUser\Desktop\repos\project\Launcher\git.gradle”行:4
出了什么问题:评估脚本时出现问题。 无法应用插件“com.cinnober.gradle.semver-git”
无法运行程序“git”(在目录“C:\Users\MyUser\Desktop\repos\project\Launcher”中):CreateProcess error=2,系统找不到指定文件
我的 build.gradle
:
apply from: "check.gradle"
buildscript {
ext.buildConfig = [
"sdkCompile" : 31,
"sdkMinimum" : 19,
"sdkTarget" : 28,
"tools" : "30.0.2",
"versionCode": 1549,
"versionName": "1.0.14",
]
ext.versions = [
"kotlin" : "1.3.72",
"okhttp" : "3.12.12", // This version is the latest supporting API 19
"retrofit": "2.6.4", // This version is the latest supporting API 19
"room" : "2.2.5",
]
ext.lib = [
"androidx": [
"appcompat" : "androidx.appcompat:appcompat:1.1.0",
"async_inflate": "androidx.asynclayoutinflater:asynclayoutinflater:1.0.0",
"cardview" : "androidx.cardview:cardview:1.0.0",
"constraint" : "androidx.constraintlayout:constraintlayout:1.1.3",
"core" : "androidx.core:core-ktx:1.3.1",
"fragment" : "androidx.fragment:fragment-ktx:1.2.5",
"material" : "com.google.android.material:material:1.1.0",
"multidex" : "androidx.multidex:multidex:2.0.1",
"preference" : "androidx.preference:preference-ktx:1.1.1",
"swipe_refresh": "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0",
"work" : "androidx.work:work-runtime-ktx:2.4.0",
],
"date" : [
"core": "com.jakewharton.threetenabp:threetenabp:1.2.4",
],
"debug_db": "com.amitshekhar.android:debug-db:1.0.6",
"firebase": [
"analytics": "com.google.firebase:firebase-analytics:17.4.4",
"crash" : "com.google.firebase:firebase-crashlytics:17.1.1@aar",
],
"glide" : "com.github.bumptech.glide:glide:4.11.0",
"viewpage": [
"indicator": "com.romandanylyk:pageindicatorview:1.0.3@aar",
],
"kotlin" : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}",
"kb_event": "net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.3.0",
"okhttp" : [
"core" : "com.squareup.okhttp3:okhttp:${versions.okhttp}",
"curl" : "com.github.mrmike:ok2curl:0.4.5",
"logging": "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}",
],
"play" : [
"location": "com.google.android.gms:play-services-location:17.0.0",
],
"retrofit": [
"core": "com.squareup.retrofit2:retrofit:${versions.retrofit}",
"gson": "com.squareup.retrofit2:converter-gson:${versions.retrofit}",
],
"room" : [
"compiler" : "androidx.room:room-compiler:${versions.room}",
"core" : "androidx.room:room-runtime:${versions.room}",
"coroutines": "androidx.room:room-ktx:${versions.room}",
],
"timber" : "com.jakewharton.timber:timber:4.7.1",
]
repositories {
google()
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "com.google.gms:google-services:4.3.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath "com.cinnober.gradle:semver-git:2.5.0"
classpath "com.google.firebase:firebase-crashlytics-gradle:2.2.0"
classpath "com.google.firebase:firebase-appdistribution-gradle:2.0.0"
classpath "com.github.ben-manes:gradle-versions-plugin:0.29.0"
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()
flatDir {
dirs "${rootProject.rootDir}/libs"
}
maven { url 'https://jitpack.io' }
}
}
task sendHomologToFirebase {
group = "Firebase"
dependsOn "Launcher:assembleHomologRelease"
finalizedBy "Launcher:appDistributionUploadHomologRelease"
}
task sendProductionToFirebase {
group = "Firebase"
dependsOn "Launcher:assembleProductionRelease"
finalizedBy "Launcher:appDistributionUploadProductionRelease"
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我的 git.gradle
:
ext.nextVersion = "patch"
ext.snapshotSuffix = "<count><dirty>"
ext.dirtyMarker = ".d"
apply plugin: "com.cinnober.gradle.semver-git"
task git_count {
def process = ("git rev-list --count HEAD").execute(null, project.rootDir)
process.waitFor()
if (process.exitValue() != 0) {
ext.count = 0
return
}
ext.count = process.text.trim().toInteger()
}
我尝试过的事情:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.cinnober.gradle:semver-git:2.5.0"
}
}
apply plugin: "com.cinnober.gradle.semver-git"
并且:
plugins {
id "com.cinnober.gradle.semver-git" version "2.5.0"
}
也尝试过直接下载 .pom
文件并使用以下方式在本地加载:
flatDir {
dirs "${rootProject.rootDir}/libs"
}
我什至尝试过 这个解决方案来自另一个SO答案:
包括在我的 build.gradle< /code>
plugins {
id 'com.cinnober.gradle.semver-git'
}
并将其包含在我的 settings.gradle
中
pluginManagement {
buildscript {
repositories {
flatDir {
dirs '/libs'
}
}
dependencies {
classpath ':semver-git:2.5.0'
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息的相关部分可能是结尾:
表示它尝试运行程序 git 但找不到它。看来该插件尝试运行 git 作为应用过程的一部分,但在执行此操作时失败了。
自从克隆存储库以来,您的系统上已经有了 git,但它可能尚未添加到您的 PATH 中,因此当脚本尝试运行命令
git
时,它无法找到Windows 设置
-> 下系统环境变量
->路径
。通过将完整路径附加到 git 可执行文件所在的文件夹来编辑Path
变量。即:
C:\Program Files\Git\bin
(如果您的 git.exe 所在的位置)。这是一个相关问题,其中包含更多内容有关如何将 git 添加到 PATH 的详细说明以及详细示例。
The relevant part of the error message is likely the end:
It's saying that it tried to run the program git but couldn't find it. It seems the plugin tries to run git as part of the process of applying it and it failed while doing so.
You already have git somewhere on your system since you cloned the repo, but it likely hasn't been added to your PATH so the script can't find it when it tries to run the command
git
Windows Settings
->System Environment Variables
->Path
. Edit thePath
variable by appending the full path to the folder your git executable is in.i.e:
C:\Program Files\Git\bin
if that's where your git.exe lives.Here is a related question which has more detailed instructions about how to add git to the PATH with detailed examples.