为什么 Android Studio 无法应用插件“com.cinnober.gradle.semver-git”?

发布于 2025-01-10 01:56:12 字数 6610 浏览 0 评论 0 原文

敏锐的眼睛能发现上周困扰我的事情吗? 我克隆了这个存储库,但构建失败并出现以下异常:

失败:构建因异常而失败。

  • 其中:脚本“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()
}

我尝试过的事情:

Gradle semver-git 插件页面

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'
        }
    }
}

Could some sharp eye find what has been bugging me for the last week?
I cloned this repo but build fails with this exception:

FAILURE: Build failed with an exception.

  • Where: Script "C:\Users\MyUser\Desktop\repos\project\Launcher\git.gradle" line: 4

  • What went wrong: A problem occurred evaluating script.
    Failed to apply plugin 'com.cinnober.gradle.semver-git'

Cannot run program "git" (in directory "C:\Users\MyUser\Desktop\repos\project\Launcher"): CreateProcess error=2, System cannot find specified file

My 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
}

This is my 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()
}

Things I've tried:

Both solutions described in this Gradle semver-git plugin page

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"

And:

plugins {
  id "com.cinnober.gradle.semver-git" version "2.5.0"
}

Also tried directly downloading the .pom file and loading it locally using:

flatDir {
    dirs "${rootProject.rootDir}/libs"
}

I even tried this solution from another SO answer:

Including this on my build.gradle

plugins {
    id 'com.cinnober.gradle.semver-git'
}

And including this on my settings.gradle

pluginManagement {
    buildscript {
        repositories {
            flatDir {
                dirs '/libs'
            }
        }
        dependencies {
            classpath ':semver-git:2.5.0'
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放飞的风筝 2025-01-17 01:56:12

错误消息的相关部分可能是结尾:

无法运行程序“git”(在目录中)
"C:\Users\MyUser\Desktop\repos\project\Launcher"): CreateProcess
error=2,系统找不到指定的文件

表示它尝试运行程序 git 但找不到它。看来该插件尝试运行 git 作为应用过程的一部分,但在执行此操作时失败了。

自从克隆存储库以来,您的系统上已经有了 git,但它可能尚未添加到您的 PATH 中,因此当脚本尝试运行命令 git 时,它无法找到

  1. 它步骤是找到 git 可执行文件在系统上的位置。
  2. 假设您使用的是 Windows,您将需要编辑系统环境变量。它应该位于 Windows 设置 -> 下系统环境变量 -> 路径。通过将完整路径附加到 git 可执行文件所在的文件夹来编辑 Path 变量。
    即:C:\Program Files\Git\bin(如果您的 git.exe 所在的位置)。
  3. 之后重新启动 android studio 以强制其加载新的环境变量。

这是一个相关问题,其中包含更多内容有关如何将 git 添加到 PATH 的详细说明以及详细示例。

The relevant part of the error message is likely the end:

Cannot run program "git" (in directory
"C:\Users\MyUser\Desktop\repos\project\Launcher"): CreateProcess
error=2, System cannot find specified file

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

  1. The first step is to find where the git executable is on your system.
  2. Assuming that you're on windows, you will want to edit your system environment variables. It should be under Windows Settings -> System Environment Variables -> Path. Edit the Path 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.
  3. Restart android studio afterwards to force it to load the new environment variables.

Here is a related question which has more detailed instructions about how to add git to the PATH with detailed examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文