I am trying to create a .Jar file from an Android library project (non-executable) using gradle with dependencies, but I get a NoClassDefFoundError because it accesses one of the files from the dependency modules.
So far I have tried the FatJar method, but it includes everything in the Jar file, except for the Dependent libraries.
What should I do?
UPDATE
My Gradle.build file
apply plugin: 'android'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.myapplication"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/../lib'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.code.gson:gson:2.2.4'
}
task deleteOldJar(type: Delete) {
delete 'build/libs/AndroidPlugin.jar'
}
task exportJar(type: org.gradle.api.tasks.bundling.Jar) {
//from('build/intermediates/bundles/release/')
//from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
// archiveName = "yourjar.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
into('release/')
include('classes.jar')
///Give whatever name you want to give
rename('classes.jar', 'AndroidPlugin.jar')
}
exportJar.dependsOn(deleteOldJar, build)
source
share