Creating Android LIbrary Project Jar Using gradle with dependencies -


i'm trying build .jar file out of android library project (non-executable) using gradle dependencies, i'm getting noclassdeffounderror because accessing 1 of files dependency modules.

so far i've tried fatjar method includes in jar file except dependant libraries.

what should 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() ? : ziptree(it) } }        // archivename = "yourjar.jar"          {              configurations.runtime.collect {                 it.isdirectory() ? : ziptree(it)             }              configurations.compile.collect {                 it.isdirectory() ? : ziptree(it)             }         }         into('release/')         include('classes.jar')         ///give whatever name want give         rename('classes.jar', 'androidplugin.jar')     }      exportjar.dependson(deleteoldjar, build) 

there nice plugin can produce fat jars easy: https://github.com/musketyr/gradle-fatjar-plugin . works java plugin conflicts com.android.library btw.

so, have found little workaround. every jar file zip archive actually. means can unzip , add content new archive.

there snippet of code produces fat jar , pushes defined local/remote maven repository:

...  apply plugin: 'maven-publisher'  publishing {     publications {         maven(mavenpublication) {             artifact bundlerelease         }          mavenjava(mavenpublication) {             artifact fatjar         }     } }  task fatjar(type: jar) {     (ziptree('libs/library-one.jar'))     (ziptree('libs/library-two.jar'))     (ziptree('libs/library-three.jar'))     ('build/intermediates/classes/release/') {         exclude '**/buildconfig.class'         exclude '**/r$*.class'         exclude '**/r.class'     } }  ... 

than need run:

$ ./gradlew clean build publishtomavenlocal 

p.s. can iterate through libs (including *.jar) folder if not want write every lib separately.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -