Multi-project setup with Gradle for Android - android

I am having a problem to make my Android application build.
I have one Main application module, and another one that is needed for the google-play-services_lib.
My folder structure is as follows:
ParkingApp
|
|-----> google-play-services_lib (Library Project)
|-----> ParkingApp
|-----> settings.gradle
My settings.gradle file is as follows:
include ':ParkingApp', ':google-play-services_lib'
My ParkingApp has the following build.gradle.
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':google-play-services_lib')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
}
}
And the google-play-services_lib has the following build.gradle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/google-play-services.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Any help is appreciated!

With the new updates in Android Studio and Gradle, I think a better solution for adding support package and google play services jars is to use the maven repositories instead of adding the library it self, here is how you can add both to any .gradle file, using this way you will no have more problems adding both to dependent projects.
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.android.support:support-v4:13.0.+'
}
Note: In the new version of Android Studio 0.2.0, you will need also to update the gradle verison to:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}

Put google-play-services.jar in MyParkingApp/libs and reference it as a dependency from MyParkingApp/build.gradle.

Related

Error:(10, 0) gradle method not found classpath()

Hello i'm newbie with Android studio , i imported facebook as, and first i got this error Error:(111) Cannot call getBootClasspath() before setTargetInfo() is called. and i followed the right answer here. i.e i changed my depencies from
dependencies {
compile 'com.android.support:support-v4:[21,22)'
compile 'com.parse.bolts:bolts-android:1.1.4'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
and now i'm getting this error
Error:(10, 0) Gradle DSL method not found: 'classpath()'
Possible causes:The project 'FiberTeccpcp' may be using a version of Gradle that does not contain the method.
Gradle settings
The build file may be missing a Gradle plugin.
Apply Gradle plugin
finally this is my build.gradle file
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
project.group = 'com.facebook.android'
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
apply plugin: 'maven'
apply plugin: 'signing'
......
How can i correct this?
You have to include this part in the buildscript block
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
Should be:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
}

Android Studio won't compile

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.

Different gradle versions for library and application

I'm currently trying to add a library relying on froger_mcs' answer in this post.
Unfortunately, I didn't manage to find build.gradle in library's source files to complete last step:
At the end you have to create another build.gradle file in /libriaries/actionbarsherlock/ directory.
So I added one found in gipi's answer here.
I ended up facing the following problem:
When I run ./gradlew clean it says that gradle version 1.9 is required for the library I'm trying to add. When I change version in gradle-wrapper.properties to 1.9 and run the same task again, it says that gradle version 1.8 is required for my application.
What am I missing?
MyProject/external/TheLibrary/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
MyProject/MyApp/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile project(':external:TheLibrary')
/* other dependencies */
}
MyProject/settings.gradle:
include ':external:TheLibrary', ':MyApp'
Try adding latest version of gradle that is avaliable.
Put in your build.gradle located on root (MyProject in ur case)
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
Plus you don't need to specify gradle for each project. You can put it in your main build.gradle and other libs will read from it. Mine build.gradle looks like that in listing below. And for your case build.gradle will be in root directory MyProject. So you want to edit global build.gradle not the ones that are inside modules (MyApp and TheLibrary). You can delate your claspath to gradles in those modules - make only one globaly.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Put in your gradle wrapper:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
And I think that build tools might be a main problem here. Make every of your lib projects to have the same build tool variant as your main project so, swtich from:
compileSdkVersion 17
buildToolsVersion "17.0.0"
to:
compileSdkVersion 19
buildToolsVersion "19.0.0"
And btw. there is 19.0.3 avaliable.

Adding ActonBarSherlock in Android Studio

I am trying to add ActionBarSherlock to my existing app. This is not as easy as I thought. I have been doing this for two days now. I have tried every tutorial for 2 pages of Google results. Here is what I have after following this tutorial.
My project Structure
ActionBarSherlock/actionbarsherlock/ build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/Parse-1.3.1.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
ClashMMAProject/ClashMMA/ build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/Parse-1.3.1.jar')
compile project(':libraries:ActionBarSherlock:actionbarsherlock')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
setting.gradle
include ':ClashMMA', ':libraries:ActionBarSherlock:actionbarsherlock'
Dependancies
My Error
I have done a lot of research and I can't get anything to work. I get an error every time, so there is something I don't understand correctly. Please help. Thanks for your time.
Update
Ok after the suggestions, this is what I have in ClashMMAProject/ClashMMA/ build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
compile files('libs/Parse-1.3.1.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
This is producing an error:
Gradle: Execution failed for task ':ClashMMA:processDebugManifest'.
> Manifest merging failed. See console for more info.
I also struggled with this, as it seemed every tutorial or answer I followed left some small detail out that a beginner doesn't know as something to automatically do. Here is how I eventually got ABS added to my project:
1.Don't download ABS at all. You can completely add it by modifying your existing build.gradle file. Not your project's build.gradle, but your inner folder that is the parent folder of your src directory.
2.Open SDK Manager and make sure you have Android SDK Build-tools 18.0.1 (later versions might also work).
3.Model your build.gradle file after mine. This is the exact build.gradle file I am using that works. Make sure your minSdk and targetSdk match what is in your manifest:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
}
4.Make sure you are using gradle 1.8 in gradle-wrapper.properties:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
5.Sync project with gradle files by pressing the button:
The ActionBarSherlock author has provided a .aar file, so you will no longer need to build the library that you have in your libraries folder. You can change your build.gradle to be something like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/Parse-1.3.1.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Note the actionbarsherlock aar file in dependencies, and the removal of the library dependency. (I also see that your gradle is at 0.5.+ and your buildToolsVersion is at "17.0.0", the most recent versions are 0.6.+ and "18.1.1", but you can work on those once ABS is working for you).
Now you can safely remove your libraries/ActionBarSherlock, which you will no longer need, and change your settings.gradle file to:
include ':ClashMMA'
Hope this helps.

Android Studio gradle and libraries import

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.

Categories

Resources