How to use jar library from another module in Android Studio - android-studio

For the past few hours I've been trying to import a rather large eclipse ADT workspace (8 projects, 1 app) into Android Studio. I've managed to fix or bypass most of the errors which have popped up so far, but now a problem's arisen which I do not know how to fix.
I have a Java Library module (Toolkit), which has a JAR library dependency (commons-io-3.3.jar, as file dependency). Alongside this module I have an Android module which requires this JAR file (located as dependency within the Java Library Module), but I get an error: Error:(31, 29) package org.apache.commons.io does not exist. However, the module dependencies from the Android module show Toolkit as a module dependency.
So my question, in short, is this: In Android Studio, how can I use a JAR library in a Java module within an Android module? Or is there something else which I am doing wrong?
Edit:
build.gradle from Toolkit
apply plugin: 'java'
dependencies {
compile files('libs/commons-io-2.4.jar')
}
build.gradle from AndroidToolkit
apply plugin: 'com.android.library'
android {
// ...Android config stuff
}
dependencies {
compile project(':toolkit')
compile 'com.android.support:support-v4:18.0.0'
}

Related

Gradle - Sync does not work if module declared without path and configuration

We have several in-house libs that we want to import a local dependency. However if we do:
implementation project(':moduleA')
Android Studio will not sync the project:
CONFIGURE SUCCESSFUL in 5s
ERROR: Unable to resolve dependency for ':app#develop/compileClasspath': Could not resolve project moduleA
However strangely enough compilation does work (through Android Studio and on the console).
To make it sync in Android Studio, it has to be declared like this:
implementation project(path: ':moduleA', configuration: 'default')
But the problem with the above is that it will no longer import the dependencies for moduleA.
How to declare the module so that it will both sync and import the dependencies?

How can I configure the Buildship plugin to download the Maven API Javadoc in Eclipse?

I am building a gradle plugin in Groovy using Eclipse Neon 3. I have linked the internal dependencies as below, and have generated an Eclipse configuration using the Eclipse gradle plugin.
dependencies {
compile gradleApi()
compile localGroovy()}
I have specified that I would like to download and receive source code and Javadoc for dependencies:
eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
}}
For all dependencies but the internal ones, this works. I am not receiving source code or javadoc api for the following:
gradle-api-3.5.jar
groovy-all-2.4.10.jar
gradle-installation-beacon-3.5.jar
gradle-test-kit-3.5.jar
Given that these are very important to understand the framework,
my question is:
How do I configure a groovy-based gradle plugin project in Eclipse, such that the above four libraries have JavaDoc and Source navigation available?

Android Studio: How to see class hierarchy for gradle dependencies

I have included various dependencies in my build.gradle file. For example:
dependencies {
compile 'io.reactivex:rxandroid:1.0.1'
}
Is there any way to see the class hierarchy that this provides in Android Studio? e.g. the list of packages and classes.
If I include a .jar dependency in my libs folder, I can 'open it up' in the Project view to see what's in there.
Any similar functionality with gradle dependencies?
Yes you can. It's in this directory:
{yourModuleName}/build/intermediates/exploded-aar/io.reactivex/rxandroid/1.0.1/jars/
You can see it easily if you have the Project view open (AS defaults to Android view)

Gradle dependency error

I am using Gradle 2.4 and Android Studio 1.3. I have tried to use AppWarp's JAR file as a dependency in a libGDX project. I have got following error during Gradle sync:
Gradle DSL method not found 'compile()'
I put code below in allprojects section.
dependencies {
compile files('libs/App42MultiPlayerGamingSDK.jar')
}
You can't put "compile" in the allprojects section because that section does not have the java plugin applied, and therefore can only accept classpath dependencies. You could put apply plugin: "java" at the top of the allprojects block, but that will only lead you to the next problem...
Isn't that jar an Android-based library anyway? It will cause your other modules to fail to compile if you put it in allprojects. It needs to go in the android section's dependencies.
AppWarpMultiPlayerGamingSDK should be added to Android Studio as a module in the core project, by right click on project.
Select Module Setting
And SDK as a module library.
Thanks to AppWarp Support Team!

Why do we set Gradle classpath reference in both project's and module's build.gradle?

When we create an empty Android Gradle project using Android Studio 1.1.0 (and all older versions of Android Studio), there are two references to the Gradle plugin. One reference is in the Project's build.gradle and another reference is in the module's build.gradle. And the both look exactly the same
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.x.x'
}
}
As I experienced, the version of Gradle from project's file is more important because I can set the latest Gradle in it (v 1.1.3. for Android Studio 1.1.0) while I can leave(!) older version of Gradle in the module's build.gradle. The project will compile without any errors.
So why is the module's reference there on the first place?
Let's say that the reason is so that we can use other Gradle version in some modules. Does it mean that I can remove these lines of code from module's build.gradle if I plan to use the same Gradle version through out the project? This way I have to update the same line in all modules.
We do NOT have to! It seems that this habit was present in the previous versions of Android Studio (probably before the official release).
In Android Studio v1.1.0 there is only one reference - in projet's build.gradle.
Note: this project was created on the older version of Android Studio (not sure which one) and inherited its code.

Resources