How to add maven/repo libraries to old project without gradle? - android

Where can I include online (maven etc) libraries/repo in Android Studio 2.0 without build.gradle?
Before it was somethere in add library dialogs, but now i can add local jars only. But how to add online repositories to old projects without gradle?
Note, i do not want to include all library project/source, import module etc. Just want to link online libs as before.

Related

Migrating from Eclipse to Android Studio and library issues

I have decided to migrate my projects from Eclipse to Android Studio and I am finding a lot of difficulties in doing so. The biggest problem I have is the following:
I have several applications that are using some common projects (libraries). When importing an application into Android Studio, it detects the referenced libraries and adds them to the application (copies the folders of the libraries under the application folder). This is something I do not want to do because the libraries are common for more that 1 applications so I want them to be at the same directory level as the application folder and just reference them from the application. How is this done in Android Studio? In Eclipse, you would just add a reference from the project properties. Furthermore, how do I import a library project in Android Studio? I would like to import each of the libraries as separate projects and build them individually.
Is there any good tutorial about this? I have a lot of experience with Eclipse but I am completely new to Gradle.
Here is an example of what I mean:
I have two projects, ProjectA and ProjectB. They both use some library projects developed by me, LibA and LibB. All 4 projects are under the same folder called Applications - the two libraries are therefore common and if I change one of them I only need to recompile both projects. After importing ProjectA into Android Studio (having the latest version), the import process created the following structure. Under the base folder, Studio Applications, I have a folder for the project named ProjectA. Under folder ProjectA, I have another folder, ProjectA (where the main project files are) and two more folders, LibA and LibB. What I would like to have is have the two library projects imported separately (as library projects in Android Studio) and under the main application folder have only the ProjectA folder (and the rest of the standard gradle folders, ie, .gradle, .idea, build etc).
How can this be done? I need two things: First, import a library project from Eclipse into Android Studio and then import a project but instead of having the libraries copied under the project path, reference them.
Just import your apps with no project libs (I'm assuming the libs are available in maven)
After that you just need to add the dependencies in gradle file
// your gradle file inside your app folder
dependencies {
compile 'com.squareup.okhttp:okhttp:2.3.0' // example of importing okhttp
compile 'com.facebook.android:facebook-android-sdk:4.1.1' // example importing facebook sdk
compile project(':name_of_local_project') // local project
}
and if you want to include a project of another folder (different project)
add this to settings.gradle
project(':module1').projectDir = new File(settingsDir, '../another_path')
It's a simpler approach, and you get the ability to update the lib without much work
The problem was that I had proguard enabled for the library modules as well. Proguard was obfuscating class and function names in the library modules and they were not found in the app that was referencing them. Moving/merging the proguard files in the app was the solution.

Modify files from maven library

I'm developing my project using Android Studio and I have a library imported as module into my project with some xml files modified to fit my needs. My question is if there is a way of modifying those resource files if I add the library as a maven dependency or it can be done only by adding it as a module.
Thanks!
If you add a library as a Maven dependency, e.g.
dependencies {
compile 'com.foo:1.0.0'
}
it's going to download that dependency from the Maven repository in whatever format is specified in the artifact, typically JAR or AAR. If it's downloading a prebuilt library like that, you can't make any local changes to it.
If you need to make changes, your best bet is to include it as a module instead of a Maven-style dependency like that. However, if this is a common library that will be shared among multiple projects, you have a number of options to make that sharing easier. You could build it as a library and include it in your projects via that Maven-style include (perhaps deploying the library to a local or organization-wide repository), or if it suits you better, you could put the library in a common place on local disk and reference it in-place via your settings.gradle file.

How to keep a global copy of jar so that all projects can use the code. Android

I have 3 apps which rely on a single lib (jar). Now when I create 3 apk there would be 3 copies of jar.
Is it possible in android to keep the single copy of jar on device and update it once and all apps get the latest lib.
If you are using eclipse, an easy way to do this is to create a new project, and move the jar into the libs folder of the new project. Then go to project properties -> android and tick "Is Library". Now you can remove the jar from the other projects and add the new library project as a library dependency to all 3 projects and you will only have one place to maintain the jar.
A better approach would be to read up on some dependency management tools like Maven which will allow to add too and run a local dependency management server and that you can use to compile dependencies into your projects. This will let you use different versions of the same jar for different projects among many other powerful features.

Project libraries which include jars (such as support v7 and play services) aren't working correctly

I switched over to Android Studio a few months ago, but only until recently did I ever add or remove library modules from my project. I've run into a problem where simply including the library module (such as google play services) is insufficient in getting my app to compile.
I made sure the library module uses its own jar as a dependency. The references jar can be seen here:
But unless I include both the library project AND this jar library onto my main app module as a dependency, the app will not compile. I was under the impression that just including the library itself ought to be enough, because it includes all the res/ files AND the jar itself which contains the java files.
I get it to work by doing the following:
But shouldn't just the 1 project library/module be enough? If you look you can see I need to do the same with Android v7's appcompat library.
You don't need to add the the compiled module (the .jar file) in the dependencies of itself module.
In other words, once you import your module to your project, the only other thing you should have to do is to add it as a module dependency to your project.
When you add the module library, Android Studio will automatically generate/add the .jar file to libraries and then to your project's dependencies.
Module Dependencies
Google Play Services Library
Main Project Module Dependencies

Is it possible to share library projects between projects when using Android Studio and gradle?

I'm struggling to figure out how to import library projects into Android Studio in a fashion that makes them available to multiple projects. The documentation for the new build system implies that you need to import library projects into the root of the project you are working on:
Gradle projects can also depend on other gradle projects by using a multi-project setup. A multi-project setup usually works by having all the projects as sub folders of a given root project
(http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup)
This is problematic since, as I mentioned above, I would like to keep frequently-used libraries accessible to all current and future projects. For example, I am currently trying to integrate Volley into a new project to evaluate it, with the assumption that I will want to use it in multiple other projects in the future. I cloned it to my "${PROJECT_ROOT}/" folder, which is the same level at which I created my test project, giving me:
${PROJECT_ROOT}/TestProject/Test
${PROJECT_ROOT}/volley
After trying to set up my project's build.gradle file in a variety of ways, the only way that I've managed to make the app compile is to move Volley into the TestProject 'main' project, giving me:
${PROJECT_ROOT}/TestProject/Test
${PROJECT_ROOT}/TestProject/volley
Not only does this prevent me from using Volley in other projects that are not a part of TestProject without duplicating it or cloning it a second time, but it means that git wants me to add it to the repo I've established at the root of TestProject.
How can I reference library projects in my Android Studio projects without including them in the projects themselves?
Couldn't you use git with submodules? e.g. In your .gitmodules file, you may add this:
[submodule "volley"]
path = volley
url = https://path/to/volley/repository
You can set the url to Volley's official repository, or to your own in-house version of volley. Other projects can be setup the same way and point to the same volley repository.
I think this way, other users can call git clone and all the dependent projects will be downloaded within the main project folder and they don't have to worry about downloading the library projects separately.
For Volley though, I would just compile it into a JAR file and stick it into the /libs folder of the main project. That is, if you don't need to modify its source.
[Update]
For library projects that you don't need to modify its source, you can try using Android Studio to compile them into AAR files for sharing. AAR file is like a JAR file to Android, so you can add them to your /lib source folder, or publish them to your local/intranet maven repository. If you choose the maven route, add your local/intranet repository in build.gradle, and reference the library project that you've published.
Hopefully in the future more Library projects owner will build their projects into AAR file and publish them to Maven Central Repository, so we can just reference them directly from the build.gradle file.

Categories

Resources