I am trying to test to reference without copying a library Project. So I created two projects one is ProjectA and one is LibraryA. Both projects are located inside the \StudioProjects folder. I am trying to reference LibraryA from ProjectA and I get the error at the title.
Here is settings.gradle from ProjectA
include ':app'
include ':LibraryA'
project(':LibraryA').projectDir = new File('../LibraryA')
Here is dependincies from app build.gradle of ProjectA
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(':LibraryA')
}
I am using Android Studio 1.5.1
If I remove compile project(':LibraryA') from dependencies it builds normally, however then I can't referance classes from LibraryA inside ProjectA.
In your settings.gradle (ProjectA) you are referring the wrong folder.
include ':LibraryA'
project(':LibraryA').projectDir = new File('../LibraryA')
Checking your image, the LibraryA folder is a root folder.
Gradle is searching for a "module" build.gradle while in this folder there is a top-level file configuration.
You have to refer to the module inside the LibraryA
project(':LibraryA').projectDir = new File('../LibraryA/app')
Of course you have to pay attention if some tasks or variable are defined in the top-level file (LibraryA). In this case you have to clone them inside your top-level file (ProjectA)
One of your projects does not have a valid gradle file. If your library is not a gradle project convert it to gradle project.
If you add your library as a module and select "gradle" when you are importing i think you'll solve your problem.
I just do not understand what you want to do. But try changing the following line:
project(':LibraryA').projectDir = new File('../ProjectA')
Related
I want to convert this Android Studio project into an Eclipse project.
The way to do it is to copy everything in all src packages and res directory from AS project to Eclipse project, and change the Eclipse project's Manifest file by adding all the additional elements from AS project.
The catch is that I have to do this for all the third party dependencies (declared in build.gradle) on which the AS project depends and then add those library projects to this newly created Eclipse project.
Normally I would do it for each library listed in the dependencies section of build.gradle file of AS project. But for this library project, I don't understand what are the dependencies:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
}
I don't understand the first and third line. Please tell me which libraries are declared in first and third line, so that I can copy those projects in Eclipse?
EDIT:
Here is the output of gradlew.bat -q dependencies command:
EDIT 1:
EDIT 2:
For each project module, do the following from the command line:
./gradlew -q dependencies
This will print out a graph of all dependencies the module has.
I want to import the library https://github.com/jpardogo/FlabbyListView
First, I download the Zip file, then I extract it then I copy it to the lib folder of my project, then I turn on my project in Android Stduio. I add this line in the build.gradle compile 'com.jpardogo.flabbylistview:library:(latest version)'. But the Android Studio show:
How can I fix it?
You are mixing two concepts. If you use the compile dependency you don't have to put the jar in libs, and if you put the jar, don't put the managed dependency.
What the line compile library:artifact:version does is putting in your classpath in compile time the corresponding library, downloading it for you from a maven repository.
That said, I suggest you to remove the .jar and change your line of compile to:
compile 'com.jpardogo.flabbylistview:library:1.0.0
if you are manually adding the library to android. then you will add it to you project also.
In you settings.gradle file for the project add
include ':nameoflibrary'
or
include 'lib:nameoflibrary'
Where lib is the name of the folder you added the library and nameoflibrary is the actual name of the library.
then in you actual module usually the app-module gradle file add
dependencies {
compile project(':nameoflibrary')
}
or
dependencies {
compile project('lib:nameoflibrary')
}
same analogy too.
But if you are adding it from the repository you only need to add this line of code in your app-module gradle
dependencies {
compile 'com.jpardogo.flabbylistview:library:(latest version)'
}
I am facing problem to use external library project's in android studio version 1.2.2 .
steps i did to add external library projects are:-
I created a new project exPagerSliding.
I Add a new directory(libs) in root directory of the app. and paste the library there.
I open my apps setting.gradle. and add following lines of code
include ':app' ':PagerSlidingTabStrip'
project(':PagerSlidingTabStrip').projectDir=new File('libs/PagerSlidingTabStrip')
then I open my build.gradle file
add following lines of code
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(":PagerSlidingTabStrip")
}
5.Next i go to gradle.properties and write following lines of code.
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.3
ANDROID_BUILD_SDK_VERSION=21
and last in build.gradle i add
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
}
I am getting a message "Error:Cannot get property ':PagerSlidingTabStrip' on null object"
When i open my build.gradle file from library . their i am getting this message
you must use a newer version of android gradle plugin.current version is 1.0 and recomended version is 1.2.3
well now problem is solved,
so i am writing for those who was still facing this mess.
step's to use external library project in android studio are:-
go to file-new -import module.
select your library project folder.
after importing module.
go to file->project structure->select app ->select dependency-> click on + sign in right side->module dependencies-> select your module name and press ok.
4th step was the final step , but you can get two type of error. Ex. no such property GROUP... for handle this go to select build.gradle of your library , and remove line like this apply from: 'https://raw.github.com/twotoasters/gradle-mvn-push/master/gradle-mvn-push.gradle'
This is my way for adding external libraries to Android studio project.
Open your project where you want to add external library.
Then in File> New> choose Import new Module, navigate to library project which you want to add to your project, select to add 'library' module in your project. You will get in your project settings.gradle beside app, included library, something like this:
include ':app', ':library'
Add in build.gradle(module :app) in dependencies section:
compile project(':library')
Rebuild project and that's it.
*You can add as many libraries (modules) as you want. In that case in settings.gradle you will have:
include ':app', ':lib1', ':lib2', ...
And in build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//some your dependencies...
compile project(':lib1')
compile project(':lib2')
...
}
You just need to create a module and add the external library project to this module. Then add module dependency in project structure. That's all. Android Studio will automatically add everything to Gradle file. You don't need to do these manually.
I have a problem when adding Caldroid library on Android Studio. I try many different ways to add but it won't work. I use Android Studio 0.8.2.
First off, I created a root folder called libraries.
I created a new folder caldroid in /libraries.
Then, I pasted the downloaded files in /libraries folder.
Then, I changed the following files.
settings.gradle
include ':app'
include 'libraries:caldroid:library'
build.gradle
dependencies {
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:4.0.30'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libraries:caldroid:library')
}
But I get this error:
Error:Configuration with name 'default' not found.
How to fix this?
I'm late but I faced a similar issue so I thought I'll share how I solved it.
To import an external library to Android Studio, I follow this convention:
Create libs folder inside the app directory. Then copy the required library files to the libs folder. For example, my folder contains actionbarsherlock and caldroid folders.
Caldroid has a library dependency that can be downloaded here, you can see this in the build.gradle file (Also, make sure the gradle files have the correct SDK versions). Download the hirondelle-date4j-1.5.1-sources.jar.
Create libs folder in app/libs/caldroid/. Copy the hirondelle-date4j-1.5.1-sources.jar to app/libs/caldroid/libs/. You may also have to copy android-support-v4.jar from -User_Home-/Android/Sdk/extras/android/support/v4/ to app/libs/caldroid/libs/.
Open app/libs/caldroid/build.gradle and replace compile 'com.darwinsys:hirondelle-date4j:1.5.1' with compile files('libs/hirondelle-date4j-1.5.1-sources.jar').
In Android Studio, open settings.gradle and add this line include ':app:libs:caldroid'. Next, open "build.gradle (Module: app)" and add this line compile project(':app:libs:caldroid') in dependencies.
And that's it, now allow the gradle to "sync" or clean and build your project.
Add this line in your dependencies in build.gradle
compile 'com.roomorama:caldroid:3.0.1'
I have an android gradle project it's now not compiling because it's looking for license classes so i tried to include them as following in my build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
**compile project(':lvl-licensing').projectDir = new File(projectDir, '../lvl-licensing/library'**)
}
problem is that for some reason i still get this:
A problem occurred evaluating project ':myproject'.
> Project with path ':lvl-licensing' could not be found in project ':myproject'.
how can i include the lvl-license/library project in my project using gradle? why is it complaining? I do have the project in that folder with build.gradle and I can compile that lvl-license/library project separately.
thanks
You have to add the lvl-licensing file to your settings.gradle file as well. Also, that library can't be outside the root directory of your project; it looks like you're trying to place the library in a sibling directory to your project.
If you put the library under your project root, you don't need to do the gymnastics with the path in your compile project statement.