android - Create single AAR file from multiple modules using Gradle -


like many others, trying generate single aar file multi-modules android project.

according this post, not supported android team because of various limitations (res & dependencies management, manifest merging, ...).

i trying come own solution fits needs. know don't have duplicated resources , external dependencies (like support libraries) provided people using lib.

my structure similar this:

/root |- lib1 |- lib2 |- lib3 

in order achieve goal, created 1 more library module, named distribute, include others modules. can share generated distribute.aar file.

/root |- lib1 |- lib2 |- lib3 |- distribute 

this build.gradle file of distribute module:

apply from: '../common.gradle' // configure properties shared accross modules apply plugin: 'com.android.library'  def allmodules = rootproject.allprojects.collect { it.name } - [rootproject.name, name] def whitelabeldependencies = [         whitelabel1: allmodules - ['lib2'],         whitelabel2: allmodules, ]  android {     def buildtypenames = buildtypes.collect { it.name }     def whitelabeltypes = productflavors.findall { 'type'.equals(it.dimension) }.collect { it.name }      whitelabeldependencies.each { whitelabel ->         def modules = whitelabel.value         def whitelabelname = whitelabel.key          whitelabeltypes.each { whitelabeltype ->             def productflavor = whitelabelname + whitelabeltype.capitalize()              buildtypenames.each { buildtype ->                 def sourceset = productflavor + buildtype.capitalize()                 def folders = ['main', whitelabelname, whitelabeltype, productflavor, whitelabelname + buildtype.capitalize(), sourceset]                  android.sourcesets.maybecreate(sourceset)                 android.sourcesets.getbyname(sourceset) {                     assets.srcdirs = getpathslist(modules, folders, 'assets')                     java.srcdirs = getpathslist(modules, folders, 'java')                     res.srcdirs = getpathslist(modules, folders, 'res')                     resources.srcdirs = getpathslist(modules, folders, 'resources')                 }             }         }     } }  afterevaluate {     whitelabeldependencies.each { whitelabel ->         def assembletask = rootproject.tasks.getbypath(":${name}:assemble${whitelabel.key.capitalize()}")         assembletask.dependson whitelabel.value.collect { ":${it}:assemble${whitelabel.key.capitalize()}" }     } }  dependencies {     whitelabeldependencies.each { whitelabel ->         whitelabel.value.each {             "${whitelabel.key}compile" project(path: ":${it}", configuration: project.whitelabelconfigurationname)         }     } }  def list<file> getpathslist(list<string> modules, list<string> folders, string sourcetype) {     return modules.collect { module ->         folders.collect { folder ->             new file("${rootproject.rootdir}/${module}/src/${folder}/${sourcetype}")         }.findall {             it.exists()         }     }.flatten() } 

this seem working, except @ runtime, application crash because can not find r class of each libx module, 1 of distribute module. there way force gradle include r class of each module.

i know file each module generated in $module/build/generated/source/r/$whitelabel/$buildtype/$package/$module/r.java, don't know how include , prevent duplicated classes (each module can depends on other one).


Comments

  1. 1xbet korean online sportsbook【Malaysia】1xbet korean
    1xbet korean online septcasino sportsbook【Malaysia】1xbet korean online sportsbook【Malaysia】1xbet 카지노 korean online sportsbook【Malaysia】1xbet 1xbet korean online casino【Malaysia】1xbet online

    ReplyDelete

Post a Comment

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -