Missing main module in Android studio - android

I am trying to migrate my android app from eclipse to Android studio. (0.5.4)
The project has several dependencies. (Sherlock etc)
I exported the app to Gradle and imported it in Android studio and managed to get the project to build successfully.
It appears however that only the dependencies are built.
Adding erronous lines in the app code does not trigger compile errors.
When I view project | packages, the package for my app does not show, Only the external libraries are shown.
My root level build.gradle only contains repositories and dependencies:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
}
I tried manually adding an android section with the intent to make gradle look at the source files but I had problems adding the section:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
}
android {
compileSdkVersion 17
buildToolsVersion "19.0.2"
}
As i now get the following error
Could not find method android() for arguments xxx on root project 'zzz'.
If proceeded to add
apply plugin: 'android'
Just before the android section, but now I get
A problem occurred evaluating root project 'zzz'.
Plugin with id 'android' not found.
Can anyone shed some light as to why i cannot have an Android section at the root level.
If the problem lies somewhere else any help would also be much appreciated.
In case it is needed, here is my settings.gradle
include ':external:PullToRefresh:SmoothProgressBarLib'
include ':external:ActionBarSherlock'
include ':'
include ':external:pulltorefresh-abs'
include ':external:MyAwesomeLibrary'
include ':external:PullToRefresh:pulltorefresh'
include ':external:SherlockNavigationDrawer'
include ':external:sdk:MyAwesomeSDK'

You've included an android block inside a buildscript block in your top-level build file, but this is incorrect. Instead it should be structured like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "19.0.2"
}
dependencies {
//Your app dependencies go here
}
All this is assuming that you truly have an Android application module at your project root (meaning that at your project root directory there's a src directory that has Android sources in it). It seems to be that you're trying to set it up this way because you also have this in your settings.gradle file:
include ':'
If that's the case, then rearranging your top-level build file as indicated above should fix it.
If you don't have a module at the project root, then you should restore the top-level build file to its original condition (take out apply plugin and android), take out that include ':' line from settings.gradle, and add an include statement that points to your application module.

In your settings.gradle file, I don't see where you included your main module. You should add:
include ':mainmodule-directory'
Your project should, ideally, have two build.gradle files. One at the root level, one at the module level. In your main module, you specify that the module is an Android module by adding apply plugin: android in the module's build.gradle file. Then you specify that the entire project would need the Android plugin by using the following in the root build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}

Related

Could not find method android() for arguments

I've been trying to import a project to Android Studio and this is where I am stuck, there is a similar question on Stack Overflow but it did not provide a solution to my particular error.
This is my error log:
C:\<some location>\build.gradle
Error:(24, 1) A problem occurred evaluating root project '<project name>'.
> Could not find method android() for arguments [build_4fli1jm76ubcnxesnhqnhie47$_run_closure3#6e71db85] on root project '<project name>'.
Information:BUILD FAILED
The Gradle sync messages are:
Error:(24, 0) Gradle DSL method not found: 'android()' Possible
causes:The project 'PoojaPeople' may be using a version of
Gradle that does not contain the method. Gradle settingsThe build file
may be missing a Gradle plugin. Apply
Gradle plugin
I'm not too sure where exactly this method android() is located. If it is the one located in Application's build.gradle file, I still don't exactly know where to go from here. Any help is appreciated.
My build.gradle is
buildscript {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android {
compileSdkVersion 17
buildToolsVersion '23.0.0'
}
dependencies {
compile files('app/libs/junit-4.12-JavaDoc.jar')
}
apply plugin: 'maven'
You are using the wrong build.gradle file.
In your top-level file you can't define an android block.
Just move this part inside the module/build.gradle file.
android {
compileSdkVersion 17
buildToolsVersion '23.0.0'
}
dependencies {
compile files('app/libs/junit-4.12-JavaDoc.jar')
}
apply plugin: 'maven'
My issue was inside of my app.gradle. I ran into this issue when I moved
apply plugin: "com.android.application"
from the top line to below a line with
apply from:
I switched the plugin back to the top and violá
My exact error was
Could not find method android() for arguments [dotenv_wke4apph61tdae6bfodqe7sj$_run_closure1#5d9d91a5] on project ':app' of type org.gradle.api.Project.
The top of my app.gradle now looks like this
project.ext.envConfigFiles = [
debug: ".env",
release: ".env",
anothercustombuild: ".env",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
apply plugin: "com.android.application"
guys. I had the same problem before when I'm trying import a .aar package into my project, and unfortunately before make the .aar package as a module-dependence of my project, I had two modules (one about ROS-ANDROID-CV-BRIDGE, one is OPENCV-FOR-ANDROID) already. So, I got this error as you guys meet:
Error:Could not find method android() for arguments [org.ros.gradle_plugins.RosAndroidPlugin$_apply_closure2_closure4#7e550e0e] on project ‘:xxx’ of type org.gradle.api.Project.
So, it's the painful gradle-structure caused this problem when you have several modules in your project, and worse, they're imported in different way or have different types (.jar/.aar packages or just a project of Java library). And it's really a headache matter to make the configuration like compile-version, library dependencies etc. in each subproject compatible with the main-project.
I solved my problem just follow this steps:
① Copy .aar package in app/libs.
② Add this in app/build.gradle file:
repositories {
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
③ Add this in your add build.gradle file of the module which you want to apply the .aar dependence (in my situation, just add this in my app/build.gradle file):
dependencies {
compile(name:'package_name', ext:'aar')
}
So, if it's possible, just try export your module-dependence as a .aar package, and then follow this way import it to your main-project. Anyway, I hope this can be a good suggestion and would solve your problem if you have the same situation with me.
This error appear because the compiler could not found "my-upload-key.keystore" file in your project
After you have generated the file you need to paste it into project's andorid/app folder
this worked for me!

Error:Plugin with id 'com.github.dcendents.android-maven' not found

I'm using this library in my Android app. (https://github.com/yazeed44/MultiImagePicker)
Before now, I was adding it to my project this way:
compile 'net.yazeed44.imagepicker:imagepicker:1.3.0'
The problem with importing it that way is, as far as I know, that I can't override any code because I'll lose all the changes after building the project again. (I need to change some code)
For that reason, I have downloaded the source code and I've imported the project as a module with this name: 'imagepicker'
After that, I added this line to my app build.gradle:
compile project(':imagepicker')
and this to my settings.gradle (Android Studio did it)
include ':app', ':imagepicker'
After doing that, I try to run the project and Android studio shows this error:
Gradle 'Project' project refresh failed
Error:Plugin with id 'com.github.dcendents.android-maven' not found.
Since you are using the module locally you have to add in your top-level build.gradle or in the imagepicker/build.gradle same config added in the imagepicker build.gradle project.
buildscript {
repositories {
jcenter()
}
dependencies {
//ADD THESE DEPENDENCIES
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
An alternative can be modify the imagepicker/build.gradle removing the last 2 lines. But you have to test this way.
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
If you check these files you will find the
apply plugin: 'com.github.dcendents.android-maven'
In your case you don't need these files because they are useful only to uplaod in a maven repo the aar file.
I added below code in Project:gradle.build file and its resolved the problem :
allprojects {
repositories {
jcenter()
maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
}
}
}
EDIT
If you still facing after adding above maven dependencies
Change url "https://repo.commonsware.com.s3.amazonaws.com" to url "https://s3.amazonaws.com/repo.commonsware.com".

Where to place the apply Crashlytics plugin directive in Gradle build files

Recently I have migrated my android project from Eclipse to Android Studio.
Currently my project has the following Gradle script structure:
Top-level gradle build file
Main module (my app) gradle build file
module A (my app) gradle build file
module B (my app) gradle build file
module C (my app) gradle build file
The Content of my main gradle build file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.1'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
}
I would like to make sure crashlytics would be present for the whole project.
I initially tried to add
apply plugin: 'crashlytics'
to the main project gradle file, but I encountered the following error:
Error:(2, 0) Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
I then moved the apply plugin: 'crashlytics' to the main module (my app) gradle build file and the build was successful.
Since I am new to Gradle & Android Studio, I was not sure if I need to it also to the submodules A, B, C to allow crashlytics to capture exceptions generating from those modules. Also I wonder why can't I (or how can I) add the " apply plugin: 'crashlytics' " to the main project gradle file.
Could anyone clarify it for me?

How do you include romainguy's ViewServer in Android Studio with Gradle?

I'm trying to use RomainGuy's ViewServer (https://github.com/romainguy/ViewServer) with my Android Studio project using Gradle, and I can't get it to work.
My understanding is to add a folder in project root ('libraries'), drop the ViewServer directory into it (not the full ViewServer directory but the actual library viewserver folder within ViewServer, and reference it in settings.gradle
include ':VendorSearch'
include ':libraries:ViewServer'
and also in my build.gradle file
compile project(":libraries:ViewServer")
When I do this I get a message that says
Could not find any version that matches com.android.tools.build.gradle:0.5.+
I tried then manually updating build.gradle in ViewServer to use the latest build tools (0.7.+ at the time of posting), but I get the same error with the new gradle version.
Any help and general clarification of how to include non-jar third party libraries would be appreciated!
You probably need to add the repository. Change the gradle.build from:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}
to
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}

Android Gradle module dependancies

I have a problem while building a project on Android using Gradle.
I have a project structure as following:
root
settings.gradle
build.gradle
- Project 1 (android studio "module")
build.gradle
- Project 2 (android studio "module")
build.gradle
If I select the project 1 and compile, it works
If I select the project 2 and compile, it works as well
Now, I would like to have a dependancy from the project 2 on the project 1 to reuse some of my application logic.
Following the doc I try to add in the project 2 build.gradle
dependencies {
compile project(':Project1')
}
but it doesn't work.
My settings.gradle contains:
include ':Project1', ':Project2'
You should apply the plugin android-library in your library project (project1) :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 17
}
Link to the Gradle documentation about making library projects.
If you want to reuse some logic from Project1 you should create a library project, Project3-lib. Move your reusable code to this new project and let Project1 and Project2 depend on it.
This is how you can do it:
settings.gradle
include ':Project3-lib', ':Project1', ':Project2'
In your Project1 and Project2 you add your new lib project
dependencies {
compile project(':Project3-lib')
}
In your top-level gradle.build file (so that you dont need it in all of your project build files)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
In your new Project3-lib project you have to apply the android-library plugin and not the android plugin
apply plugin: 'android-library'

Categories

Resources