Android Studio Libraries and aar - java

I'm currently building an Android library. The library is divided into two parts:
Core features and functionality
Utility classes such as extended Activities, FragmentActivities etc.
Now when I tried building the library's structure as such, including ActionBarSherlock and AppCompat V7 created a conflict for Gradle. The two libraries are mutually exclusive. My solution was to build a core library and 2 wrapper libraries (one for ABS and another for AppCompat V7) then provide the user with both options. So I did the following:
For the core library project "core" I ran the gradlew assemble command. This in turn generated an aar file for my library "core.aar".
I created another library project "support" and added the core.aar as a dependency in my local maven for that project. (More info on that here)
I ran ./gradlew assemble for the support library which in turn created support.aar.
I finally added the support.aar file as a dependency for my application (just like step 2)
When I finish all that, I get a compilation error for my app saying that certain resources cannot be found in my library files in the exploded-aar folder. To be more precise, in my library I have certain drawables that are used in certain layout files, both in the library. These are not found anywhere.
Any idea what could be causing the problem?

Related

intelij multi module maven capabilities

I've recently moved from c# .Net / Visual Studio, to Java / Maven InteliJ Idea Community.
Some things that I expect my IDE to do for me seems missing:
Generating a dependency graph between my modules to see which module references what dependent modules. I expected some kind of GUI or plugin for visualising these connections - but find myself going through multiple pom files manually.
Viewing which external dependencies are used by my app across modules and compare their versions. Being able to add an external library that is already referenced by some of my modules, to a newly created module, without the need to copy paste pom xml.
NUGET was used for discovery of new libraries and updates in .Net, is there an equivalent tool for that in InteliJ+Maven ?
Thanks
IntelliJ has similar features :
1) The IntelliJ built-in maven plugin has a feature a show dependencies icon
2) You can enable the maven auto-import for your project, IntelliJ will check unresolved dependencies for you

Custom Maven plugins and libraries

Currently, I have a few custom maven plugins which use the same libraries (JARs) as my application which uses it.
It is pertinent to mention that the libraries are also custom libraries developed by us and not 3rd party.
I want to let go of these libraries and integrate all of them directly inside my application source code - just have one problem - what do I do with
the maven plugins which use them.
Is there a way I can use the application source code (after integrating the libraries) while compiling / running the maven plugins?
Personally I wouldn't go on this path because of dependency hell etc, but if you really need to you could create a jar containing the source files (see https://maven.apache.org/plugin-developers/cookbook/attach-source-javadoc-artifacts.html) and then in the project you need to source unpack it like this https://maven.apache.org/plugins/maven-dependency-plugin/examples/using-dependencies-sources.html.
ps: what is the reason to drop the libraries and instead use the source code?

How to combine one android studio project into another android studio project

I have two separate android app projects that were made in android studio I am trying to combine project 1 into project 2 to make it all one app how would I go about doing this? I know how to do it in eclipse but not in android studio.
Please note they are both of these projects are android applications none of them are android libraries.
Any help would be amazing!
When I import project 1 into project module I get this error on grade build:
Warning:Dependency School Tools Calc lib.gz:SchoolTools:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: /Users/chrisdebrodie/Documents/School Tools Calc lib.gz/SchoolTools/build/outputs/apk/SchoolTools-release-unsigned.apk
You cannot have two "projects" as a single project in Android Studio.
Convert one (or both) project into libraries. Then create a "shell" project to build each app. The shell project is basically empty, or it may have build specific value overrides. The advantage here is that you can modify the library and changes will be immediately reflected in both/all versions. The drawback is that you will have to fix any issues in all projects that result from any change to any library. But you can then create the "combined" project in a similar manner.
After you convert one or both to a library you can create an aar file. This gives you the option to then include that aar as a gradle dependency. Be careful to remember that you will need to re-build the aar every time you modify that project - so if you have an indication as to which is the more stable codebase, go with that for the aar. This gives you the ability to "version control" the main project dependency so that you can make changes to one project without impacting the stability of the other.
Additionally, you can write scripts and use tools like Bamboo or Jenkins to do real-time updates to the aar - but that is like using a "snapshot" dependency. When you change the aar it may compile, but it may break the build of the second project without you knowing it until you do a build on that project. (And yes, you can include a build on that project as a part of the Bamboo or Jenkins script, but it isn't easy.)
There may be other alternatives, but these seem to offer enough options to produce a wide variety of build options.
I write a repo to handle this staff safely and easily: Jacksgong/android-project-combine.
Characteristics:
Just a developing env wrapper, it can't modify projects, safe to use.
Different Android projects develop together at the one Android Studio window.
Find References and Jump into source code rather than .class file on jar package.
Jump out of the each projects compile system and using the official compile system.
Very light, very fast for each time you want to refresh combine project.
Add one project as a module of the another's. This answer explains how to do it. Note that this answer is in response to adding a library dependency, but it will work for your situation as well.

Adding external dependency to Gradle task

I am on a project witch develops an adapter utility for a legacy closed-source library which is treated as black box and due to licence agreements cannot be shipped along with the adapter utility.
In order to build the project the library needs to be in the class path which is no problem as long as I am using an IDE (IDEA in my case) but how can I tell Gradle having this dependency during building without adding it directly to build.gradle?

Importing library into an Android project?

I have multiple projects, an Android project and a couple of "Java Library" projects that I need to import into my main Android project.
My library uses springFramework.jar, when I include this library into my Android I get the following exception.
10-01 11:35:04.101: E/dalvikvm(1144): Could not find class 'org.springframework.web.client.RestTemplate', referenced from method com.nuvasive.shared.atlasmobile.service.ServiceClient.
If I include the jar files into my main project as well as the library everything works fine, but I rather not do that.
So there are two problems here:
Seems like jar file in my library is not being added to my main project
My main project can't access classes in my library project
What am I doing wrong here?
According to me if you have added jar files to build path(check in libraries tab) then remove them from that tab and as i can see you have not marked jars you are using in order and export please nark all jars you are using. You will see those under private libraries in libraries tab.
Try it.
I'm not entirely sure what you're trying do without knowing what 'springFramework.jar' is, what libraries you have linked in all your projects, what your code is doing, etc., but my guess is that this is some kind of dependency issue.
Check out http://mvnrepository.com/search.html?query=spring+framework+. Although this site is designed for maven dependencies, I believe you can download any of the jars directly.
'springframework.jar' is probably an older build of Spring that combined multiple components that are now broken up into different modules (spring-core, spring-jdbc, spring-web, etc.) Perhaps your main project has another needed dependency that your Android project does not?

Categories

Resources