块必须出现在任何插件

块必须出现在任何插件

本文介绍了在 jitpack 中出现“buildscript {} 块必须出现在任何插件 {} 块"错误之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 jitpack 发布我的 android 库.但是获取 buildscript {} 块必须出现在任何 plugins {} blocks 错误之前.

FAILURE:构建失败,出现异常.在哪里:构建文件 '/home/jitpack/build/build.gradle' 行:53* 什么地方出了错:无法编译构建文件/home/jitpack/build/build.gradle".>启动失败:构建文件 '/home/jitpack/build/build.gradle': 53: 所有 buildscript {} 块必须出现在脚本中的任何插件 {} 块之前有关 plugins {} 块的信息,请参阅 https://docs.gradle.org/4.4/userguide/plugins.html#sec:plugins_block@ 第 53 行,第 1 列.构建脚本{^1 错误

这是我的项目级 gradle 脚本,

buildscript {存储库{谷歌()jcenter()maven { url 'https://jitpack.io' }}依赖{类路径 'com.android.tools.build:gradle:3.1.3'}}插件{id "com.jfrog.bintray" 版本 "1.8.3"}所有项目{存储库{谷歌()jcenter()maven { url 'https://jitpack.io' }}}
解决方案

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

 应用插件:'com.android.library'安卓 {compileSdkVersion 27默认配置{minSdkVersion 19目标SDK版本27版本代码 1版本名称1"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}}依赖{实现文件树(目录:'libs',包括:['*.jar'])实现 'com.android.support:appcompat-v7:27.1.1'实现 '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'实现 'com.android.support:support-v4:27.1.1'实现 'com.android.support:design:27.1.1'实现 'com.android.support:percent:27.1.1'实现 'com.google.firebase:firebase-core:16.0.1'实现 'com.google.firebase:firebase-messaging:17.0.0'}所有项目{存储库{maven { url "https://jitpack.io" }行家{网址https://oss.sonatype.org/content/repositories/ksoap2-android-releases"}}}

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

应用插件:'com.google.gms.google-services'

I am trying to publish my android library with jitpack. But getting buildscript {} blocks must appear before any plugins {} blocks error.

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
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' }
    }
}
解决方案

If above mentioned build.gradle file is complete then I believe it's not complete. Your library's build.gradle file should look something like this:

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

    }

}

and if you are using google services then include below lines too at the end of file:

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

这篇关于在 jitpack 中出现“buildscript {} 块必须出现在任何插件 {} 块"错误之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 10:12