0

I have and android project named global flow and I after opening with android studio 2.2.3 on a debian linux I watch this error:

Error:(22, 0) Could not find method android() for arguments [build_5ijv6qsqmd3lnd1fe6nzaworu$_run_closure3@1c8251f] on root project 'GlobalFlow' of type org.gradle.api.Project. Open File

When I try the solution in this forum could not find method android I don't know where to find all the android modules.

I update the build.gradle file in home/alex/GlobalFlow but I am not sure if is this one or the other one in home/alex/GlobalFlow/app. But I understand that the root project's build gradle is in the first path named.

My build.gradel is:

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

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

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

android {
  compileSdkVersion 23
  buildToolsVersion '23.0.1'
}

dependencies {
compile files('app/libs/junit-4-12-JavaDoc.jar')
}

apply plugin: 'maven'

Where are all android modules?

Thanks.

Community
  • 1
  • 1
axmug
  • 476
  • 2
  • 10
  • 26
  • You need to `apply plugin: 'com.android.application'` at the top of `home/alex/GlobalFlow/app/build.gradle`. – Eugen Pechanec Jan 16 '17 at 12:42
  • Thanks for answering. I typed what you told me but as the project is not build completely the android manifest doesn't exiist and now the error is: cannot read packageName from /home/alex/GlobalFlow/src/main/AndroidManifest.xml. How can I fix this error? Thanks – axmug Jan 16 '17 at 12:58
  • Why don't you start a new project using the wizard, study the output structure and modify yours accordingly? – Eugen Pechanec Jan 16 '17 at 15:30
  • Thanks for answers. I fixed the problem reinstalling Android Studio again and following the steps in http://stackoverflow.com/questions/38663495/android-studio-2-1-2-gradle-aapt-syntax-error-unterminated-quoted-string – axmug Jan 17 '17 at 12:16
  • And yet you are no closer to understanding the issue. Good luck applying the same principles in the future. – Eugen Pechanec Jan 17 '17 at 15:38
  • `I tried to build a project on Windows with build-tools version 25 and it works. But the same version in linux doesn't work.` How do you expect to get help if you provide inaccurate info? Why is there `23.0.1` in your question? – Eugen Pechanec Jan 17 '17 at 15:38
  • The issue was not fixed. Then I realized there was two Android Studio installed in my computer. One in root and the other one in /home/alex. Then I decided to delete both and reinstall Android Studio on root. Then I got the error solved in the post mentioned above. – axmug Jan 18 '17 at 16:34
  • Let me be blunt: You build script is still a mess. Follow the advice given even if the problem *appears* to be solved right now. – Eugen Pechanec Jan 18 '17 at 18:27

2 Answers2

0

You can't use the android block in the top level file.

You have to add it in the home/alex/GlobalFlow/app/build.gradle

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
}

dependencies {
    //.....
}
Graham
  • 7,431
  • 18
  • 59
  • 84
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

This is the project/build.gradle:

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'

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

allprojects {
  repositories {
    jcenter()
  }
}

It contains build script instructions. And optionally closures applied to all modules.

The following line allows you to apply com.android.application plugin:

classpath 'com.android.tools.build:gradle:2.2.3'

Also read the NOTE carefully.


This is the project/module/build.gradle:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 23
  buildToolsVersion '23.0.1'
}

dependencies {
  // We're in GlobalFlow/app now, adjust the relative path!
  compile files('libs/junit-4-12-JavaDoc.jar')
}

apply plugin: 'maven'

When you apply plugin: 'com.android.application' you can use the android { ... } closure to setup Android app build process. Notice they're both in the module build.gradle.

If you were building an Adnroid library you'd apply plugin: 'com.android.library' which also provides you with android { ... } closure.


This is the recommended and default structure as of January 2017.

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124