0

I just tried importing a library into my android project and ended up with this Plugin with id 'com.android.application' not found. error. I was supposed to import "Filters.jar" file from jhlabs but accidentally imported "gradle-wrapper.jar" of another project . I am stuck here and nothing seems to work. I also accidentally deleted my project level build.gradle file, Which contained the following code :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.2'


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

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

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

I was trying to import the library following this answer,

https://stackoverflow.com/a/35369267/9504498

I messed up apparently I have tried many solutions but nothing is working. Please, help me fix this error I am stuck here.

How can I get the project level build.gradle file back? and how can I fix this Plugin with id 'com.android.application' not found.?

Any help will be appreciated, Thanks.

VoidMain
  • 957
  • 1
  • 8
  • 12
  • This is really the best way to do it: https://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-new-gradle-android-build-syst – Daniel Nugent Nov 06 '18 at 01:30

2 Answers2

0

You need to re-add your build.gradle to your project by following the structure of sample project which you can create from Android Studio.

Usually, the project structure is like the following:

app              -> (your app module)   
gradle  
build.gradle     ->  (project build.gradle)   
gradlew  
gradlew.bat  
local.properties   
settings.gradle

The following error:

Plugin with id 'com.android.application' not found.

is because gradle can't found the plugin from your project build.gradle, so add the following code to your project build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'


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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

For adding a jar library, as @daniel-nugent says, try:

How to manually include external aar package using new Gradle Android Build System

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • Can you please explain the process of re adding the build.gradle step by step, because I need to do it the correct way, I have already messed things up. I dont want to cause more harm. Thanks – VoidMain Nov 06 '18 at 09:33
0

Tried many options but nothing really worked and finally, created a new project with exact name as the previous one and the exact package name, then copied the "main" from the previous project to the new project and edited the app level build.gradle by copying from the previous project and things are back to normal now. Will try importing the .jar library by following @daniel-nugent method.

VoidMain
  • 957
  • 1
  • 8
  • 12