java - How to include JAR dependency into an AAR library -
summary:
i have aar file depends on jar file, when build aar project, doesn't contain jar code.
details:
i have java sdk library project contains code use java web projects , such, library created using gradle
, resides in internal nexus server (as jar).
the goal provide "android configured" version of jar library through aar library multiple android applications can use , minimize effort (and boilerplate code) implement it. aar file uploaded nexus server used android application projects.
my aar project includes gradle dependency java sdk library (the jar) when built, aar doesn't include classes it.
code:
this java sdk project's gradle file:
apply plugin: 'java' //noinspection groovyunusedassignment sourcecompatibility = 1.7 version = '1.1.1' repositories { mavencentral() } jar { { configurations.compile.collect { it.isdirectory() ? : ziptree(it) } } } dependencies { testcompile group: 'junit', name: 'junit', version: '4.11' testcompile 'org.apache.directory.studio:org.apache.commons.io:2.4' compile 'org.springframework:spring-web:3.1.1.release' compile 'com.google.code.gson:gson:2.3' }
this gradle file aar project, note removed maven repository declarations nexus server it. guess shouldn't matter sake of question.
apply plugin: 'com.android.library' android { compilesdkversion 23 buildtoolsversion "23.0.1" defaultconfig { minsdkversion 16 targetsdkversion 23 versioncode 1 versionname "2.2.2" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } lintoptions { abortonerror false } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) testcompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' compile ('com.mycompany:javasdk:1.1.1') }
this gradle file android project, again removed nexus server references:
apply plugin: 'com.android.application' android { compilesdkversion 23 buildtoolsversion "23.0.1" defaultconfig { applicationid "com.mycompany.application1" minsdkversion 16 targetsdkversion 23 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) testcompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' compile ('com.mycompany:androidsdk:2.2.2@aar') }
note: solved issue adding jar in lib directory of aar project, undesired. makes having nexus server useless. can bump jar's version number in aar project's gradle file , update happens automatically @ compile time.
note2: tried adding transitive=true
aar dependency in android project didn't solved anything, real issue when building aar project, jar project code doesn't bundled.
thank time.
you can add task:
task copylibs(type: copy) { configurations.compile 'libs' }
dependencies downloaded nexus, when need package library, execute task first , jar
files copied , included inside final aar
.
Comments
Post a Comment