I am trying to get Google Maps into my application from within Android Studio. I found a tutorial which suggested openning up my .grade file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
and add this line to dependencies:
compile 'com.google.android.gms:play-services:3.2.25'
I added this line and my .grade file looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
compile 'com.google.android.gms:play-services:3.2.25'
}
}
apply plugin: 'android'
dependencies {
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
When I added this line, and tried to rebuild my project I get this error:
Gradle: A problem occurred evaluating root project 'BeerPortfolioPro'.
> No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [com.google.android.gms:play-services:3.2.25]
Possible solutions: module(java.lang.Object)
Update:
I tried changing my .grade from one of the answers below to this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
and now I get this error:
Gradle: A problem occurred configuring root project 'BeerPortfolioPro'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not find com.google.android.gms:play-services:4.0.30.
Required by:
:BeerPortfolioPro:unspecified
Open your SDK Manager and install/update the Android Support Repository, Android Support Library v19, Google Repository and Google Play Service v13.
I had a similar "No signature of method" error, and realised that I'd added the dependency to the wrong file. When creating my project, Android Studio created 2 build.gradle files, one in the project root directory (alongside local.properties and gradle.properties), and one in a subdirectory named after my app (alongside the src and build directories). The play-services dependency needs to be added to the latter of these files, not the former.
The dependencies block in your buildscript section is for including files required for the gradle build script. Google Play Services should be in the "app" `dependencies' section.
Here's a suggestion buildscript solution.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
}
Extra Notes
classpath 'com.android.tools.build:gradle:0.6.+'
This will make sure you have the latest gradle 6 build tools.
Also the following block will make sure you're using the latest SDK version and build tools, while still including SDK 11 as the minimum supported version. Build Tools v19.0.0 has improvements over previous versions, but also plays nicely with Java 7.
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
If you cannot reference play-service 4 then a temporary solution could be to reference play-services:3.2.25 as specified in the documentation. A better solution would be to upload the library to your own maven repository (like Sonatype Nexus) and pull the dependency from there.
It's the minSdkVersion problem. Change it to 14, for Android 4.0.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:appcompat-v7:+'
}
Related
I have a dummy project, which I succeed to compile through buildship plugin in eclipse IDE.
This is my local.properties file:
sdk.dir=C:/Asta/altro/adt-bundle/sdk
This is settings.gradle file
rootProject.name = 'testgradle'
This is my build.gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.testgradle"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.android.support:appcompat-v7:23.4.0'
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.10'
}
Despite I got the apk fully compiled, eclipse is not integrated: still seeing missing libraries and giving more than a 100 errors! All the libs are perfectly managed by gradle in \build\intermediates\ and assembled into apk, but the eclipse IDE is not "live". I would like to use gradle to download and explode the libraries and then to inform eclipse and let it to make the apk with its own builder.
Buildship can be used only to run Android tasks (assembleDebug).
During the build process it will load dependencies and tell if there're some errors.
To load dependencies into Java classpath, to see errors in Eclipse and resolve imports you can either manually add .jar files to your Java Build Path or use this Gradle plugin: https://github.com/greensopinion/gradle-android-eclipse.
It generates classpath for Eclipse project and you just import it into the IDE.
To run Gradle tasks you can create a Run configuration (named "Gradle Project") and put there your task and Working directory.
I'm having a problem building APKs in IntelliJ using gradle.Because I import the appcompat library and use the android-library to build it by myself.There are no build errors and output the apk successful.But when you install the apk to phone which has Android 2.3,the action bar is fullscreen.But api >= 14 is totally normal.like this
wrong link:
right link:
But if I use the appcompat library by importing dependency,the apk is normorl.So my problem is why I can’t build appcompat by hand?
Here is my project structure
picture link:
the root project’s build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
}
}
apply plugin: 'com.android.application'
dependencies {
// compile "com.android.support:appcompat-v7:19.1.0"
compile project(":appcompat")
}
ext {
compileSdkVersion = 21
buildToolsVersion = "21.1.2"
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion 8
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
appcompat project’s build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
}
}
apply plugin: 'com.android.library'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/android-support-v7-appcompat.jar')
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
java.srcDirs = ['src']
}
}
}
settings.build:
include ':appcompat'
Besides,I use gradle 2.2.1,support-v7 19.1.0.
The whole project can download here:
project
Anyone who know this?
Just add to dependencies:
compile 'com.android.support:appcompat-v7:21.0.3'
You shouldn't include jar's of the libraries that are available via repositories.
Note: Don't forget to update the support libraries in SDK Manager.
I am trying to compile (debug) the "HelloWorld" Chromecast Android app supplied by Google on their GitHub page.
After doing numerous updates to the SDK and Android Studio, I am now totally stuck on getting this to run.
I have not changed any code that was supplied.
The current error I get when clicking "debug" is:
"NoSuchMethodError: com.android.builder.model.ProductFlavor.getMinSdkVersion()I: com.android.builder.model.ProductFlavor.getMinSdkVersion()I"
I cannot find any information on this error.
Build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.android.support:mediarouter-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.2.+'
}
You can try to go in the manifest file and can change the minimum sdk version
Pretty sure you just need to update your Gradle tools version. This line:
classpath 'com.android.tools.build:gradle:0.9.+'
should be:
classpath 'com.android.tools.build:gradle:0.12.+'
Android Studio 0.8+ requires at least 0.12 to properly build your project.
Split your gradle.build:
On the gradle.build of your project leave:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
And on the gradle.build of your module declare:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.android.support:mediarouter-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.2.+'
}
Put the first code on project gradle configuration and the secod part of code on module gradle configuration file.
Before adding a library to my Android project the layout was like this:
MyappProject
Myapp
build.gradle
settings.gradle
build.gradle
The top level build.gradle has always been empty, with the settings.gradle file containing only:
include ':Myapp'
I obtained a library project which I was able to import successfully into Android Studio, so I presume that the gradle files within it were fine. I now have the following structure:
MyappProject
Myapp
build.gradle
libraries
Library
LibrarySubProject1
build.gradle
....
build.gradle
settings.gradle
build.gradle
...and the top level settings gradle now looks like:
include ':Myapp'
include ':libraries:Library'
I've also updated Myapp's build.gradle so it includes the extra last line in dependencies here:
dependencies {
compile 'com.android.support:support-v4:+'
compile files('libs/commons-lang3-3.1.jar')
compile files('libs/jsoup-1.7.3.jar')
compile project(':libraries:Library')
}
Unfortunately, any attempt to do anything with gradle (sync files, build etc.) now gets me the following:
Gradle 'MyappProject' project refresh failed:
Configuration with name 'default' not found.
Gradle settings
Any changes to the settings appear to have no effect, and Android Studio keeps the settings set to "use default gradle wrapper".
From what I understand, that means that there is a problem with the top level build.gradle along the lines of this file not containing sufficient information to build the sub projects. But, perhaps I have misunderstood, as Myapp used to build and Library also seems fine. Removing the compile project(':libraries:Library') allows gradle file syncing again, but I would like to use that library...
Any suggestions as to how to fix this would be welcome.
Edited to add build.gradle from Library. Top level:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
version = VERSION_NAME
group = GROUP
repositories {
mavenCentral()
}
}
From the next level:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
You cannot have project inside a project in Android Studio. You can only have modules so change your project structure as shown below so that it will be compliant for the allowed project - module level structure.
MyappProject
Myapp
build.gradle
libraries
LibrarySubProject1
build.gradle
....
settings.gradle
build.gradle(Root only one)
Now do the following with your build.gradle files
1. Root level build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
If you have something in your library project's root level build.gradle file include that also in this root level build.gradle file because only root is allowed to have which will automatically be included in each of the sub level's build.gradle files while compilation .
2. LibraryProject's build.gradle file
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
3. Your main module's build.gradle file should look like
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
}
dependencies {
//YOUR MODULE DEPENDENCIES
compile project(':libraries:LibrarySubProject1')
}
your settings.gradle file will be like
include ':Myapp'
include ':libraries:LibrarySubProject1'
In my case the problem was solved simply by deleting the line containing
maven_push.gradle
this line was trying to upload the project to maven while I didn't need to.
Your library has a multimodule build file structure:
Library
LibrarySubProject1
build.gradle
....
build.gradle
with the two-level build.gradle file structure like Android Studio-made projects have, but that doesn't work for libraries. MyApp is pulling in the dependency for :libraries:Library but only sees that top-level build file with the buildscript and allprojects tags, and it can't find a default configuration in there to depend on.
Your library can't have a settings.gradle file to lead the way to LibrarySubProject1/build.gradle. What you'll need to move the library one directory level up to Library, and collapse the two build.gradle files down to one:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
I'm not sure what to do about the VERSION and GROUP stuff you're doing in the top-level build.gradle; you'll have to figure that out.
I just commented out line:
apply from: rootProject.file('gradle/maven-push.gradle') in
build.gradle(:library) since I don't want to publish this project at all, but I need it just as a library.
I have successfully imported ActionBarSherlock to my project, and need to import another two libraries: Sliding Layer and Crouton. I know that similar questions have already appeared here before, but I've tried almost everything, each time breaking something in the project in a way that I had to start over.
My project tree looks like:
MyProject/
+ app/
+ libraries/
+ actionbarsherlock/
+ crouton/
+ slidinglayer/
I imported those two libraries as modules (File->Import Module)
My setting.gradle file looks like it should:
include ":libraries:actionbarsherlock", ':Krypto', ':libraries:crouton', ':libraries:slidinglayer'
actionbarsherlock gradle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
app gradle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile project(":libraries:actionbarsherlock")
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
slidinglayer gradle:
apply plugin: 'android-library'
dependencies {
compile "com.android.support:support-v4:18.0.0"
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 4
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
In crouton folder there is no gradle.build file. How it should look like? Theres only java files (no resources).
How to set up correctly dependencies in crouton and slidinglayer libraries?
build.gradle for crouton
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
}
}
}
and in your app build.gradle, change
dependencies {
compile project(":libraries:actionbarsherlock")
}
to
dependencies {
compile project(":libraries:actionbarsherlock")
compile project(":libraries:crouton")
compile project(":libraries:slidinglayer")
}
and import again in Android Studio
I don't know how to solve your problem, but when I faced problem of third party library use in Gradle build, I solved by following way.
Following is my structure of project.
GsonDemoProject
GsonDemo
build
libs
android-support-v4.jar
gson.jar
src
main
build.gradle
build.gradle
settings.gradle
I edited my build.gradle file which resides in src directory.
dependencies {
compile files('libs/android-support-v4.jar','libs/gson.jar')
}
I put reference of 3rd party library in dependencies tag like above. In my project libs is directory where libraries are put.