I am using Android Studio and have a several apps that rely on the same code. I moved shared code to a separate library in order to include it in my apps.
The library project (MyLib) that I created for this purpose requires a jar-file to compile, so I added it to project's libs directory.
My build.gradle
of MyLib main module looks like this:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.android"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
}
}
}
dependencies {
compile files('./libs/external-java-lib.jar')
}
When I build the project, gradle generates a jar-file that contains external-java-lib.jar
.
I want my Android application projects to provide "external-java-lib.jar", not the MyLib. Because in my apps I may use different versions of external-java-lib.jar
.
How do I configure Gradle to exclude external-java-lib.jar
from the build of my library project?
I couldn't find the answer to my question on the net, so I have a feeling that the thing I want is a piece of bad design. What else can I do?
Thank you in advance.
I finally solved my problem.
In my library project I added another empty libraries module and moved
external-java-lib.jar
to itslibs
folder.In the
build.gradle
of the main module, I added dependency:My directory structure is now:
After I build the library, the output aar-package had no
external-java-lib.jar
in it. So, this is exactly what I want.i don not know about android studio but its easy in eclipse, in eclipse right click on the project-> properties->java build path there you have libraries and java build path. There you can exclude or include files.
If you are not using proguard then you simply use provided tag