Android Studio. Top-level build.gradle - android

I downloaded Android Studio project. At the root of the project only one build.gradle with next structure:
apply plugin: 'com.android.library'
android {
}
dependencies {
}
When I run build.gradle script I get the error:
Plugin with id 'com.android.library' not found.
I know that there must be another Top-level gradle file like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
But it is not present.
How can i add this build file? Or maybe another way to fix this problem?
The project was created in the old version of android studio. Perhaps he had worked for another way in old version? I am waiting for help. Thank you.

You have downloaded a single module (library).
You can use it in an Android Studio project building a structure like this.
Just create an empty new project and add your module.
root
|--build.gradle //top level
|--settings.gradle
|--mymodule //your module downloaded
|----build.gradle
In settings.gradle
include ':mymodule'

Just add the top level build.gradle content to the top of the downloaded projects' build.gradle.
The project you downloaded is most likely being imported into another project, and thus does not need a top level build.gradle file as it will inherit it from the project it is imported into.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
}
dependencies {
}

Related

Gradle DSL method not found: 'android()' opening project in android studio 1.4

I used Eclipse for programming android application,now i want to use android studio. now I'm new in android studio and i do not khow so much thing about gradle. i open and project which is created with android studio .but when i run it ,this give me following errors:
Error:(17, 0) Gradle DSL method not found: 'android()' Possible
causes:The project 'sheidaamin-AndSt' 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
my build.gradle is :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
} } allprojects {
repositories {
jcenter()
} }
android {
compileSdkVersion 23
buildToolsVersion '23.0.2' } dependencies { }
do anyone khow what's wrong with my project setting?
You are using the wrong build.gradle file.
In Android Studio you have a structure like this:
root
|--app
|----build.gradle
|--build.gradle //top level
|--settings.gradle
In the top level file you can't use the android block.
In the top-level file, just use somenthing like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
allprojects {
repositories {
jcenter()
}
}
You have to move the android block inside the app/build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion XX
buildToolsVersion "XX"
defaultConfig {
//
}
}
dependencies {
//
}

com.android.library not find

I use gradle build my android code ,here is my build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
}
}
so I can apply
plugin:com.android.model.application ,but when I want to depend a module , I got a error:
error:plugin with com.android.library not find
which is my
android library module's build.gradle begin with
apply plugin: 'com.android.library
if I write build.gradle like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
I cannnot find
plugin: 'com.android.model.application' my question is what should I do to depend my library successfully
Hey you have to update the plugin to match the plugins available in the experimental build:
IE. change "com.android.library" to "com.android.model.library"
You can read more about it here on the experimental gradle build documentation.
Search for "com.android.model.library" and you'll go right to it.
Be sure to read the other stuff in the doc; there are other differences you will have to add to your old library-model build.gradle file also. (eg. "targetSdkVersion 23" changes to "targetSdkVersion.apiLevel 23"

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".

Missing main module in Android studio

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.+'
}
}

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