Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio Gradle Could not find method compile()

The past two days i have tried to find a solution to this problem but with no luck.

I am trying to include GSON lib. Into my android project.

Here is a picture of my folder structure:

Folder

Now in my build.gradle i have the following:

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

dependencies {
    compile files('libs/gson-2.2.4.jar')
}

i have also right clicked gson-2.2.4.jar and added it as a lib.

When i compile i get the following error:

    Gradle: A problem occurred evaluating root project 'notebox-android'.
> Could not find method compile() for arguments [directory 'libs'] on root project 'notebox-android'.

Can anyone help me with this?

please tell me if you need more information!

like image 1000
Marc Rasmussen Avatar asked Dec 01 '13 11:12

Marc Rasmussen


People also ask

Could not find method compile () for arguments react native?

You can fix this issue by replacing compile with implementation in node_modules/react-native-geocoder/android/build. gradle.

What is compile only gradle?

compileOnly: when we don't need any dependency at runtime, since compileOnly dependency won't become the part of the final build. we will get a smaller build size. runtimeOnly: when we want to change or swap the behaviour of the library at runtime (in final build).

Can't resolve all dependencies for configuration gradle?

This is because of slow internet connection or you haven't configure proxy settings correctly. Gradle needs to download some dependencies , if it cant access the repository it fires this error. All you have to do is check your internet connection and make sure gradle can access the maven repository.

Is compileOnly deprecated?

CompileOnly ( deprecated version — provided) This is useful when you're creating an Android module and you need the dependency during compilation, but it's optional to have it present at runtime.


1 Answers

The answer to this question might help you to import your gson library correctly and avoid any compile/link issues: Android Studio - Importing external Library/Jar. Another related link: Android Studio: Add jar as library? with accepted answer. Both answers say the same thing. gradlew clean after you add/import the jar file and edit the build.gradle file.

HTH.

Edit: There are two build.gradle files. You should be editing the build.gradle that's under your project folder and not the one under your project-root folder.

like image 193
VJ Vélan Solutions Avatar answered Sep 16 '22 13:09

VJ Vélan Solutions