Gradle Multiproject - android

I am trying to configure gradle for a multiproject environment.
My project structure is as follows:
MainProject
--external
--A
--B
--C
I have been able to configure the build.gradle and the settings.gradle file for the MainProject.
The problem that I have is that both subprojects A & B depend on C
In project A 's build.gradle
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project('../C')
}
Gradle says unable to find project with path ../C. What path should I put in there?

Try with:
compile project(':external:C')
For more details about project paths see section 56.5 in the Gradle user guide.

Related

adding json dependency to a library module in android studio

I created a new library module to my project in Android Studio. A class in this new module accesses org.json.JSONObject.
I'm getting the error:
failed to resolve org.json:json:20141113
when trying to build the project.
Here's how my build.gradle file looks:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':app')
compile files('libs/volley.jar')
compile 'org.json:json:20141113'
}
Please let me know if I'm missing anything.
Thanks.
Try adding a repository to your configuration maybe that helps.
repositories {
mavenCentral()
}
For more information see here:
User-guide: Dependency Management Basics
Test This one , Worked for me
dependencies {
implementation 'com.cedarsoftware:json-io:4.10.1'
}

How to use Library from GitHub in android App

I downloaded this library to use in my app, however, I can't get Android Studio to do the gradle build now. Anytime I try, I get "error:configuration with name 'default' not found". I've tried several other StackOverflow answers, but I still can't compile.
My dependencies (from build.gradle Module: app)
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'
compile project(":aFileDialog")
}
My settings.gradle:
include ':app'
include ':aFileDialog'
I have the library file in the root under "aFileDialog"
How can I get this to build with the library?
You have add path to your aFileDialog library in your settings.gradle
Make sure that folder you point to includes build.gradle file
include ':app'
include ':aFileDialog'
project(':aFileDialog').projectDir = new File(settingsDir, 'aFileDialog')
or (judging from the library folder structure on GitHub)
project(':aFileDialog').projectDir = new File(settingsDir, 'aFileDialog/library')
I found a tutorial that worked: http://www.theappguruz.com/tutorial/library-project-module-as-dependency-in-android-studio/
In addition to the instructions given, I had to add the following line to my Manifest:
tools:replace = "icon, label"

gradle project sync failed android studio

I'm trying to setup nhaarman/ListViewAnimations inside of Android Studio 1.1.0.
From Setup:
Add the following to your build.gradle:
repositories {
mavenCentral()
}
dependencies {
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0#aar'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0#aar'
compile 'com.nhaarman.listviewanimations:lib-core-slh:3.1.0#aar'
}
yet Android Studio says:
Gradle project sync failed. Basic functionality (e.g. editing,
debugging) will not work properly.
Error:(26, 0) Gradle DSL method not found: 'compile()'
Possible causes:<ul><li>The project 'X' may be using a version of Gradle that does not contain the method.
Gradle settings</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
You are adding these dependencies in the top level build.gradle file.
You have to add these lines in the module build.gradle file.
root
build.gradle //top level
app
build.gradle //module level
After adding those lines to:
build.gradle (Module: app)
instead of
build.gradle (Project: app)
the error is gone.
Try this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0'
}
Try removing #arr. worked for me.
//ListView Animations
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0'

Error:Configuration with name 'default' not found when trying to import project as library into Android Studio

I checked all the other threads about this topic but couldn't find an answer.
I am trying to import the Twoway View Project as a library into Android Studio.
Both projects run fine on their own but I always get the same Gradle Error: Error:Configuration with name 'default' not found when trying to import.
I have the project copied into a "libraries" directory in the root folder of my project and the following gradle structure:
settings.gradle of my project:
include ':libraries:twoway-view-master',':app'
build.gradle of "app":
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "app.com.jeldrik.teacherslittlehelper"
minSdkVersion 13
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':libraries:twoway-view-master')
and in twoway-view-master build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
That twowayview-master build.gradle file isn't a buildscript for a standalone module; it lacks any sort of apply plugin statement that would tell Gradle how it should compile something. This looks like the top-level build file of a multimodule-structured project. In your settings.gradle file, you should point at the module in the project you're trying to include, not the build file at the top level.
Did you try it out using File -> New Module?
Or try setting the dependencies from here as well : File -> Project Structure -> Dependencies
I have recently got into same issue. As Scott said we have to include individual modules in our project's build.gradle file. This TwoWayView library has 3 different modules
core
layouts
sample
Say if you want to add core and layouts, add the below lines in your project's build.gradle file (Assuming you have twoway-view-master folder inside libraries folder which is inside your app folder).
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':your-app-folder:libraries:twoway-view-master:core')
compile project(':your-app-folder:libraries:twoway-view-master:layouts')
}
Then add the same path to your project's settings.gradle file
include ':your-app-folder:libraries:twoway-view-master:core'
include ':your-app-folder:libraries:twoway-view-master:layouts'
NOTE: The build.gradle files inside core and layouts have wrong path to gradle-mvn-push.gradle file. So change the path from
apply from: "${rootDir}/gradle/scripts/gradle-mvn-push.gradle"
to
apply from: "${rootDir}/your-app-folder/libraries/twoway-view-master/gradle/scripts/gradle-mvn-push.gradle"
If you still get error in layouts' build.gradle file, change this line
compile project(':core')
to
compile project(':your-app-folder:libraries:twoway-view-master:core')
Do the same change if you're also using sample's build.gradle file in your project.

Can't add External Library in Android Studio?

I Added a External Library to my project by following
this method. and tried this method too this method too.
Gradle build got Finished and i got this line added to my build.gradle
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.1'
Now i am trying to import this library in my class. But i can't do this. I took a look at the files and they are located in the build directory under the exploded-aar. so i added #aar to the compile line. Still there are no changes.
How can i import this library to my class or where i am going wrong?
Thanks in Advance
Well, you don't need to download anything or point your dependency to a file.
This dependency, as most of the dependencies you use, can automatically fetched from JCenter, biggest repository for Java and Android components.
All you need to do is:
Add JCenter as your dependencies repository.
Declare that you need the library-circular dependency. This can be found and copy/pasted from the file icon in particular package/version in JCenter.
Resync your Android Studio project with your Gradle build file. This is the 'sync' button in Gradle pane in Android Studio.
Here's what your build.gradle should include:
repositories {
jcenter()
}
dependencies {
compile(group: 'com.github.castorflex.smoothprogressbar', name: 'library-circular', version: '1.0.1', ext: 'aar')
}
in build. gradle put following code
dependencies {
compile fileTree (dir: 'libs', include: ['*.jar'])
}
Did you add the dependencies?
You can do so in the following way -
dependencies {
compile files('insert ParentFolder/external_library_name with the extension here')
}
Add it to build.gradle based in the app folder
1.Put the jar file into the libs folder.
2.Right click it and hit 'Add as library'.
3.Ensure that compile files('libs/abcdef.jar') is in your build.gradle file and Finally add the dependencies.
Eg.
dependencies {
compile fileTree(dir: '../jar', include: '*.jar')
compile project(':pull-to-refresh')
compile files('libraries/abcdef.jar')
}
Hope this helps :)

Categories

Resources