Hi Prateek Srivastava ,

I found your code does not work current on gradle 2.1 
with com.android.tools.build:gradle:0.14.0 ,  "configurations.compile.collect" 
is not found in compile scope ,
how could I fix it ,please?

在 2014年7月23日星期三UTC+8上午3时03分38秒,Prateek Srivastava写道:
>
> I'm trying to package a library (that depends on an AAR) as a jar.
>
> I create a Jar task that has the javaCompile task's source, and I collect 
> all the dependencies. For any dependencies that are an AAR, I extract the 
> AAR, keeping only the sources and classes.jar. I then extract classes.jar 
> into it's parent folder (where the AAR source is), and this directory is 
> added as a source for the jar task. However, the packaged jar still doesn't 
> contain the sources from the AAR.
>
> Does anyone have a better way to tackle this?
>
> android.libraryVariants.all { variant ->
>>   // Only attach a jar for non-debug build types.
>>   if (!variant.buildType.isDebuggable()) {
>>     def name = variant.buildType.name
>>     def packageJar = project.tasks.create "jar${name.capitalize()}", Jar
>>     packageJar.dependsOn variant.javaCompile
>>     // Include Java classes
>>     packageJar.from variant.javaCompile.destinationDir
>>     packageJar.from configurations.compile.collect {
>>       if (it.isDirectory()) {
>>         return it
>>       } else if (it.name.endsWith('.aar')) {
>>         def tempDir = "${buildDir}/unpacked/dist/extracted-" + it.name
>>         // Unzip the aar
>>         def extractAar = project.tasks.create 
>> "jarExtract${it.name.capitalize()}", Copy
>>         extractAar.from zipTree(it).matching {
>>           exclude 'R.txt'
>>           exclude 'proguard.txt'
>>           exclude 'AndroidManifest.xml'
>>           exclude 'META-INF/'
>>           exclude 'assets/'
>>           exclude 'res/'
>>           exclude 'aidl/'
>>         }
>>         extractAar.into file(tempDir)
>>         extractAar.execute()
>>         // Extract classes.jar
>>         def extractClassesJar = project.tasks.create 
>> "jarExtractClasses${it.name.capitalize()}",
>>             Copy
>>         extractClassesJar.from zipTree(file(tempDir + 
>> "/classes.jar")).matching {
>>           exclude 'META-INF/'
>>         }
>>         extractClassesJar.into file(tempDir)
>>         extractClassesJar.setDuplicatesStrategy DuplicatesStrategy.EXCLUDE
>>         extractClassesJar.execute()
>>         return fileTree(file(tempDir)).matching {
>>           exclude '**/BuildConfig.java'
>>           exclude 'classes.jar'
>>         }
>>       } else {
>>         return zipTree(it)
>>       }
>>     }
>>     artifacts.add('archives', packageJar);
>>   }
>> }
>
>
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to