java - 在 Jitpack 的脚本中,所有 buildscript {} block 必须出现在任何插件 {} block 之前

标签 java android gradle jitpack build-script

我正在尝试使用 jitpack 发布我的 android 库。但是获取 buildscript {} block 必须出现在任何插件 {} block 错误之前。 我已经提到过这个问题:Getting 'buildscript {} blocks must appear before any plugins {} blocks' error in jitpack但没有找到任何解决方案。

错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/home/jitpack/build/build.gradle' line: 26

* What went wrong:
Could not compile build file '/home/jitpack/build/build.gradle'.
> startup failed:
  build file '/home/jitpack/build/build.gradle': 26: all buildscript {} blocks must appear before any plugins {} blocks in the script
  
  See https://docs.gradle.org/7.0.2/userguide/plugins.html#sec:plugins_block for information on the plugins {} block
  
   @ line 26, column 1.
     buildscript {
     ^
  
  1 error

这是我的项目级 gradle 的样子:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.2"

        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

plugins {
    id "com.jfrog.bintray" version "1.8.4"
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我的应用级别 gradle 的样子:

plugins {
    id 'com.android.application'
    id "com.jfrog.bintray"
}

android {
    compileSdk 30

    defaultConfig {
        applicationId "com.siddydevelops.logutil"
        minSdk 23
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
 

我的 gradle 版本是 7.0.2。

我很确定这个 block 导致了错误:(在项目级 gradle 中)

plugins {
    id "com.jfrog.bintray" version "1.8.4"
}

我无法将其移动到应用级别的 gradle。

最佳答案

我也有同样的问题,我只是像这样更改build.gradle项目中的位置:

buildscript {
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.1"

    }
}

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

关于java - 在 Jitpack 的脚本中,所有 buildscript {} block 必须出现在任何插件 {} block 之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69386231/

相关文章:

java - POST curl 请求在 Spring tc 服务器上返回语法错误

java - 尝试向标记添加信息窗口时遇到困难?

android - 微调器 getSelectedItem() 返回 null

android - 与官方 Google plus 应用程序一样的水平 View 切换

android - 我可以在 Android Studio 中以其他格式而不是 WebM 录制视频吗?

android - 将库项目作为依赖项添加到另一个库项目

gradle 前缀排除依赖项

没有身份验证或存储的 Java SSL 套接字?

java - 如何启动一个新 Activity 并在该 Activity 中启动一个方法

android - 如何使用 Gradle 构建在 Android Studio 中导入 com.google.android.gms.*?