【问题标题】:Getting 'buildscript {} blocks must appear before any plugins {} blocks' error in jitpack获取 'buildscript {} 块必须出现在 jitpack 中的任何插件 {} 块' 错误之前
【发布时间】:2018-07-05 14:09:57
【问题描述】:

我正在尝试使用 jitpack 发布我的 android 库。但是得到buildscript {} blocks must appear before any plugins {} blocks 错误。

FAILURE: Build failed with an exception.

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

* What went wrong:
Could not compile build file '/home/jitpack/build/build.gradle'.
> startup failed:
  build file '/home/jitpack/build/build.gradle': 53: all buildscript {} blocks must appear before any plugins {} blocks in the script

  See https://docs.gradle.org/4.4/userguide/plugins.html#sec:plugins_block for information on the plugins {} block

   @ line 53, column 1.
     buildscript {
     ^

  1 error

这是我的项目级 gradle 脚本,

buildscript {

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

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}

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

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

【问题讨论】:

  • 这是你完整的 build.gradle 文件吗?
  • 请在此处发布完整的项目级 build.gradle 文件。
  • @Umair 是的,它是项目级 build.gradle 的完整文件
  • 请检查我的回答,看看它是否对你有帮助。

标签: android gradle android-gradle-plugin


【解决方案1】:

如果上面提到的 build.gradle 文件是完整的,那么我认为它不完整。您的库的 build.gradle 文件应如下所示:

    apply plugin: 'com.android.library'

android {


    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:percent:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'

}


allprojects {
    repositories {

        maven { url "https://jitpack.io" }
            maven {
            url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases'
        }

    }

}

如果您使用的是google services,那么在文件末尾也包含以下几行:

apply plugin: 'com.google.gms.google-services'

【讨论】:

  • 我不明白,buildscript块的所有定义,android gradle插件和其他所有东西都应该在哪里?
【解决方案2】:

我在jitpack 上构建项目时遇到了同样的问题。我在我的build.gradle 文件中使用了detekt 插件。我认为主要问题是

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

块在gradle.file 中的位置当我移动我的detekt plugin 定义时,问题得到了解决。

【讨论】:

    【解决方案3】:

    而不是像这样应用插件:

    'com.android.application'.
    

    像这样将它们添加到已经存在的函数中:

     plugins { id 'com.android.application' id 'kotlin-android' id 'com.google.gms.google-services' }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多