Android application with Android library project as external module - android

In my Android application project I want to use https://github.com/Bearded-Hen/Android-Bootstrap/tree/master/AndroidBootstrap as a dependency (I use Android Studio 0.8.8).
This is my settings.gradle
include ':gui', ':client', ':Android-Bootstrap'
project(':Android-Bootstrap').projectDir=new File('/abs/path/to/Android-Bootstrap/AndroidBootstrap')
And my gui/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.3'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
...
skipped
...
}
dependencies {
...skipped...
compile 'com.android.support:appcompat-v7:19.1.0'
...skipped...
compile project(':client')
compile project(':AndroidBootstrap')
}
When I gradle sync I get::
Error:(1, 0) Plugin with id 'android-library' not found.
If I remove
project(':Android-Bootstrap').projectDir=new File('/abs/path/to/Android-Bootstrap/AndroidBootstrap')
I get
Error:(44, 0) Project with path ':AndroidBootstrap' could not be found in project ':gui'.
If I change https://github.com/Bearded-Hen/Android-Bootstrap/blob/master/AndroidBootstrap/build.gradle with
apply plugin: 'com.android.library'
I get
Error:(1, 0) Plugin with id 'com.android.library' not found.
If I add to https://github.com/Bearded-Hen/Android-Bootstrap/blob/master/AndroidBootstrap/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.3'
}
}
I get
Error:(44, 0) Project with path ':AndroidBootstrap' could not be found in project ':gui'.
How to fix it? I want this module be external, no import and copying into main project. Why fixing gradle plugin dependency leads to path not found issue?

Fix as follows in settings.gradle:
include ':gui', ':client', ':AndroidBootstrap'
project(':AndroidBootstrap').projectDir=new File('/abs/path/to/Android-Bootstrap/AndroidBootstrap')
Note that Android-Bootstrap is replaced with AndroidBootstrap (not dash)
And in root build.gradle (./build.gradle)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.3'
}
}
It will override (set) buildscript dependencies in AndroidBootstrap.
There is not need to make changes in AndroidBootstrap itself.

Related

android method not found in gradle

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.
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.
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 {
//.....
}

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 {
//
}

How can I create aar file using build.gradle

I created a project as a library and I wrote a class in that. Now I want to have an aar file from that using 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')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
What changes are needed in the above code?
Just make sure that your <modulename>/build.gradle contains the right plugin:
apply plugin: 'com.android.library'
Then you can create with
gradlew aR
your release aar file. Which will land in <modulename>\build\outputs\aar directory with the name modulename-release.aar.
The more tricky part is to include that aar file to your project (if you don't use maven or jcenter).
You need to put this lines to your <projectroot>/build.gradle:
allprojects {
repositories {
mavenCentral()
flatDir { dirs('aars') }
}
}
When you put your aar files in <modulename>/aars, then you can include your aar file in your desired module like this:
compile(name:'<your-aar-file-name>', ext:'aar')

How you build a project using gradle?

My build.gradle is given below.i have found this error.
Error:(15) A problem occurred evaluating root project 'smartwisher'.
> Could not find method android() for arguments [build_3rvo44ss7197kfip29gkh81rb6$_run_closure2#1d7a1869] on root project 'smartwisher'.
This is build.gradle which i have in my android studio.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {}
productFlavors {
}
}
dependencies {
}
You can't use the top level build.gradle to specify android configuration.
You have to move the android block in your module/build.gradle file.
Your folders.
root
module
build.gradle
build.gradle
settings.gradle
In your top-level file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In your module/build.gradle:
apply plugin: 'android'
android {
}
dependencies {
}
Your file is not easy to read here, you should put it in a code block.
For what I saw you are missing at least one line :
apply plugin: 'android'
You need to specify pluging applying in build.gradle:
apply plugin: 'android'

Android Studio first project error

I've successfully installed Android Studio (0.6.1) on OS X (10.9.3). I can't get my first Hello World! project... Please help me solve this issue
This is the error I got:
Error:(19, 0) Build script error, unsupported Gradle DSL method found:
'android()'!
Possible causes could be:
- you are using Gradle version where the method is absent (Fix Gradle settings)
- you didn't apply Gradle plugin which provides the method (Apply Gradle plugin)
- or there is a mistake in a build script (Goto source)
Update: (code, error message)
Script:
buildscript {
repositories {
mavenCentral()
}
dependencies {}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.1'
defaultConfig {}
productFlavors {
}
}
dependencies {
}
Error message:
Error:(8, 0) Plugin with id 'android' not found.
Modify it to next:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {}
productFlavors {
}
}
dependencies { }

Categories

Resources