Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'buildscript {} blocks must appear before any plugins {} blocks' error in jitpack

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

Here is my project level gradle script,

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' }
    }
}
like image 773
VivekRajendran Avatar asked Jul 05 '18 14:07

VivekRajendran


3 Answers

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'
like image 122
Umair Avatar answered Sep 20 '22 21:09

Umair


I was getting the same issue while building a project on jitpack. I was using detekt plugin in my build.gradle file. I think the main problem is

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

block's position in gradle.file When I moved my detekt plugin definition, the problem was fixed.

like image 1
savepopulation Avatar answered Oct 18 '22 02:10

savepopulation


Instead of applying plugins like this:

'com.android.application'.

Add them to the already existing function like this:

 plugins { id 'com.android.application' id 'kotlin-android' id 'com.google.gms.google-services' }
like image 1
cbarkinozer Avatar answered Oct 18 '22 04:10

cbarkinozer