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')
Related
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 {
//.....
}
I am trying to install Picasso (http://square.github.io/picasso/) for use in Android Studio. One of the steps is to add this line: compile 'com.squareup.picasso:picasso:2.5.2' in build.gradle under dependencies. However, there is a message in gradle that tells me not to insert individual dependencies in the dependencies folder. What should I do?
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// 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
}
You need to add it to the gradle.build file that is located in the "app" directory, not the one in your project directory. find the gradle.build file that sits within the "app" directory of your project.
Here is mine as an example:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.your.packagename"
minSdkVersion 15
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories { mavenCentral() }
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
}
And a link to some supporting documentation:
http://developer.android.com/tools/building/configuring-gradle.html
Screenshot of the build.gradle(Module:app file)
Take a look at the image.
Do you see that there are actually 2 build.gradle files?
what you need is the (Module:app) gradle build file select that and paste the link in the dependencies part in the bottom of that file just like what i have done , then Android Studio will ask you to sync the file.
Do it.
It will download the dependency from your link provided and integrate with the project
Hope this helps..
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.
I had a project in Android studio and I needed to delete .idea directory. So I importet it again, but after this, all modules in libs/ can't resolve anything from android (but app module can).
Is there any setting which connects module with android?
Thanks very much
This is screen from stickyListHeaders library:
biuld.gradle from stickyList:
apply plugin: 'android-library'
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
And project's settings.gradle
include ':libs/bakuDroidLibrary'
include ':libs/photoView'
include ':libs/pullToRefresh'
include ':libs/slidingMenu'
include ':libs/spinnerWheel'
include ':libs/stickyListHeaders_lib'
include ':##PROJECTNAME##'
Some other screenns which may help:
Top level build.gradle:
// 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.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
First Check whether File » Project Structure » Android SDK is pointing to right SDK.
Than make sure below lines are added before apply plugin: 'android-library'inside build.gradle file of your stickyheader library or inside Project root's build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
My suggestion is to avoid downloading and adding libraries in to your project, use maven dependency instead.
For stickyheader which you have used can be used just by adding dependency like this in your module's build.gradle file
dependencies {
compile 'se.emilsjolander:stickylistheaders:2.1.3'
}
Nothing else needs to be done.
In Android Studio I'm trying to compile an Android application module which uses an Android library.
The library includes a jar file for Bugsense (included automatically by gradle).
Although the library module compiles correctly, the application module fails because it is looking for the Bugsense jar file that is used within the library module.
I do have a workaround which allows the project to compile. By also including the Bugsense dependency in the project everything works.
My question is: How do I make the project compile without duplicating the Bugsense dependency?
Here is my build.gradle file for the library project.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
maven { url 'http://www.bugsense.com/gradle/' }
}
android {
compileSdkVersion 15
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
}
dependencies {
compile 'com.bugsense.trace:bugsense:3.6'
}
The library project is called "util"
Following is the android section of the build.gradle for the application
android {
compileSdkVersion 15
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
dependencies {
compile project(':util')
}
}
When I compile this I get the following error:
* What went wrong:
A problem occurred configuring project ':br'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':br:_DebugCompile'.
> Could not find com.bugsense.trace:bugsense:3.6.
Required by:
dss:br:unspecified > dss:util:unspecified
I can make the compile work by adding Bugsense to the repositories section of the build.gradle file for the application. Following is the code I added to the build.gradle file for the application project.
repositories {
mavenCentral()
maven { url 'http://www.bugsense.com/gradle/' }
}
Remember, the above code is in the build.gradle for the application project AND the library.
How do I avoid adding the Bugsense dependency to both the application and library projects?
UPDATES:
I'm using Gradle 1.8
I'm compiling from the command line with "gradle clean assembleDebug"
The following is the complete build.gradle file for the application project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
//maven { url 'http://www.bugsense.com/gradle/' }
}
android {
compileSdkVersion 15
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
testPackageName "com.myapp.test"
}
dependencies {
compile project(':common')
compile project(':util')
}
}
dependencies {
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'com.squareup.spoon:spoon-client:1.0.+'
instrumentTestCompile 'com.google.guava:guava:15.0'
}
configurations { spoon }
dependencies { spoon 'com.squareup.spoon:spoon-runner:1.0.5' }
It's the expected behavior. Only the repository declarations for the project whose configuration is currently resolved are taken into account, even when transitive dependencies are involved. Typically, repositories are declared inside the root project's allprojects { .. } or subprojects { ... } block, in which case this problem can never occur.
PS: dependencies { .. } needs to go outside the android { ... } block.