I am using Android Studio 1.3.1 and trying to add library module to an existing android application. The library module is available in a git repository. I am able to import the module, but it creates a copy inside the existing app. Hence I am not able to pull the updates in the module.
I am sure there is a way to import external libraries from an existing Android project in studio.
I found the below stackoverflow posts related to my doubt -
How to import a Module on Android Studio 0.5.1?
Android Studio 0.8.1 Creating Modules without copying files?
Both seem not to work for me. I also found couple of comments from other users saying it is also not working for them in the latest version of studio.
Here are the things that I tried
// in settings.gradle
include ':libraryName'
project(':libraryName').projectDir=new File('/path/to/library')
// in build.gradle
compile project(':libraryName')
Also I tried using this this url
Any help is appreciated. Thanks
You were on the right track. Just make sure your library is inside one folder then you can direct the library path like this..
Inside settings.gradle
include ':libraryName'
project (":libraryName").projectDir = new File("../FolderName/libraryName")
if your library is inside 2 folders then direct the path like this...
include ':libraryName'
project (":libraryName").projectDir = new File("../../FolderName/libraryName")
This allowed me to use the library without making a duplicate.
Is your path relative or absolute there?
Try this if you want to reference the other module relative to the current project:
include ':libraryName'
project(':libraryName').projectDir = new File(rootProject.projectDir, '../path/to/library')
Set the projectDir and by setting the rootProject.name it will also show up in your IDEs Project pane:
// in settings.gradle
include ':app'
rootProject.name = "Project name"
include ':libraryName'
project (":libraryName").projectDir = new File("../path/to/library")
// in build.gradle
compile project(':libraryName')
Have you tried creating a folder 'libs' under your project and copying the .jar file to that folder and try compile the libs folder? That seems to normally work for me. I think it was the first solution on this question
How to import a Module on Android Studio 0.5.1?
Related
screenshot of my problem
Hi guys!
There has been a recent problem regarding the ability to import the ParseImageView class in Android Studio and there is currently only one solution: Unable to import ParseImageView - Android.
When trying this solution, it asks to download a ParseUI-Widget file from github and then import that project into my current project and then finally add a dependency for the ParseUI in the build.gradle. When attempting to sync the gradle, the error in the screenshot keeps on popping up no matter where I place the ParseUI-Widget file in the project file directory.
Please Help!
Thanks
Few things to check.
Make sure that this is the content you have inside your ParseUI-Widget.
Move your ParseUI-Widget up one directory. This way it is the same level as app
You also need to edit your settings.gradle. Your settings gradle likely looks like this:
include ':app'
Edit it to look like this:
include ':app', ':ParseUI-Widget'
You have two options:
You currently have ParseUI-Widget within the app/ directory. So you should be including it in your top-level settings.gradle file as :app:ParseUI-Widget, and within your build.gradle as compile project(':app:ParseUI-Widget')
You can also move the entire app/ParseUI-Widget directory one directory up, so that it's in the same directory, side by side with your app/ directory.
From your screenshot, it seems you haven't imported the ParseUI-Widget module. Rather you just cloned the project from github and pasted it in your project directory structure.
What you have to do is,
go in your android studio project structure view,
right click and under new,
click on new module and then
import the ParseUI-Widget as module.
Then those dependencies are in build. gradle will work fine.
I am in the process of migrating from Eclipse to Studio.
I have one Eclipse project which is a personal library of various bits and pieces that I use in other projects. I have successfully imported that library project into Studio.
When I import a project that uses that library, the importer seems to copy the whole library project into the app project, source and all.
This, obviously, is not what is required. I've tried many things and wasted a LOT of time trying to overcome this. So...
Q: Within Studio / Gradle, how do I replicate the Eclipse functionality Project / Properties / Android / Add... to just reference the library project and not produce a stand-alone copy?
You can specify in your settings.gradle a relative path using the project().projectDir property, something like this:
include ':lib'
project(':lib').projectDir = new File('xxxxxx') // Relative file path from your settings.gradle
In this way you can use the lib module inside a project without cloning the code.
Example:
Project0
|--library
|----build.gradle
|build.gradle
|settings.gradle
Project1
|--app
|----build.gradle
|build.gradle
|settings.gradle
in Project1/settings.gradle
include ':library'
project(':library').projectDir = new File(settingsDir, '../Project0/library')
in Project1/app/build.gradle
dependencies {
compile project(':library')
}
While I develop an Android App, I have a library which I have created as separate Android Studio project and can use it by inserting it into new projects. I insert the library by choosing 'File|New|Import Module...' option.
The thing is that after the import, Gradle creates a hard copy of my library. If I change the library code in main external project, the code inside the project which is using the library won't get updated.
How can I have a library and share it among many project? I need to change the library in one single place and then all other projects which are using it get the update.
I found this post also which has no answer:
How to update imported modules with code modification from the their external library project in Gradle/Android Studio
OK I found the answer by myself:
You must not add the external library as an existing module. It will make a copy of it under your project folder.
What you have to do is:
Delete the library folder in your current project. (You can also delete the ./idea/modules/[module_name] folder.)
Open the setting.gradle file and add these:
include ':your_external_library_module_name'
project (':your_external_library_module_name').projectDir = new File('../path/to/your/external/library')
include ':perhaps_second_external_library'
project (':perhaps_second_external_library').projectDir = new File('../path/to/your/second/external/library')
In your build.gradle (:app) file add dependency as:
dependencies {
implementation project(':your_external_library_module_name')
implementation project(':perhaps_second_external_library')
}
Sync the project and you are done.
I have a custom library that needs to be referenced in about 10 projects. Everything works fine in Eclipse but I want to migrate them to Android Studio in order to take advantage of the build system. I've already check
Android studio add external project to build.gradle
How to share a single library source across multiple projects
and some other links and docs in Gradleware but I don't get to make my projects compile.
My file structure is like:
+projects
|+libraryProject
|+---workspace
|+------projectSrc
|
|+project0
|+---workspace
|+------projectSrc0
|
|+project1
|+---workspace
|+------projectSrc1
.
.
|+projectN
|+---workspace
|+------projectSrcN
Each project contains docs, design files, etc... and therefore is no convenient to have the src in the same root folder.
In my "project1", settings.gradle file I've used:
include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')
In my build.gradle file, dependencies section I add:
dependencies {
compile project(':..:..:..:libraryProject:workspace:projectSrc')
....
}
But I get an error saying that the project wasn't found.
I've also used the following approach:
def customLib = file('../../../libraryProject/workspace/projectSrc')
settings.createProjectDescriptor(rootProjectDescriptor, 'module-custom-lib', customLib)
include ':module-custom-lib'
Then in the build.gradle
dependencies {
compile project(':module-custom-lib')
....
}
Please help. Thanks for your time.
EDIT: I've managed to get it working by adding the module app as a suffix in the project dir.:
include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc/app')
Now the library members resolve perfectly, but the project's 'R' resource class can not be resolved. So if I do:
setContentView(R.layout.main);
it fails to find that resource. Cleaning and rebuilding the project doesn't fixes the issue.
EDIT 2: Apparently, there was a problem with the manifest merging 'cause the problem was fixed once I adjusted the minSdk and targetSdk of both projects. The previous solution work perfectly.
Your first attempt has a simpler syntax, and should work. Your settings.gradle file looks okay:
include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')
though you should be cautious about including a relative path there -- Android Studio may not use the same working directory as a build you do from the command line, so referencing things relative to rootDir may help alleviate problems.
In the dependencies block of a module's build file, you need to reference a module the same way you do in settings.gradle, so you'd use something like this:
dependencies {
compile project(':module-custom-lib')
}
In dependencies blocks, you're linking to projects using Gradle's project namespace, and since you've already explicitly set up the root directory of the library module, you don't need to try to locate it in the filesystem here. That :..:..:.. syntax wouldn't work anyway to reference a module that's outside of your project's root directory, as this one is.
You should consider bundling "releases" of your library to a Maven repository (possibly your local Maven repo). This way you can reference your library from any other project that needs to use it just like you do with 3rd party libraries.
I'm a little newbie on Android programming and the Eclipse IDE.
And I'm having some difficulties to import this lib/project (how do I call it?) into my currently project.
The link to the GitHub repo:
https://github.com/timroes/EnhancedListView/wiki
There the author wrote a "How to include", but I tried the last one (by my one), since I use Eclipse.
"How to include
You need to include the library into your project, by one of the
following ways:
Include it from Maven Central (recommended)
Just enter the following line to your build.gradle file in the dependencies section:
compile 'de.timroes.android:EnhancedListView:X.Z.Y#aar'
Where X.Y.Z is a valid release. You can find all releases on the release page or directly in Maven Central.
If you use Maven to build, just use the above coordinates in your pom.xml.
Download the aar file from the release page and reference it in the dependencies section of your build.gradle:
compile files('libs/EnhancedListView-X.Y.Z.aar')
If you are using Eclipse or Ant, you are on your own. You most likely want to download the sources and import them in your build system."
I tried to include it to the build path, but didn't work. Nothing found on internet. Do I have to include something besides adding project into build path? Do I import it like a lib or project?
Do any of the others options to include would work for me? How do I do it?
Thank you very much!
There is no one click method for Eclipse users. You have to copy the EnhancedListView.java into one of your src packages, the content of the resource directories into your project's resource directories and the annotations.jar from the libs directory to your libs directory.