How to Zip a folder using Android Gradle?

1.5k views Asked by At

I am trying to zip an android source using gradle but my gradle task not doing anything. After completing the gradle sync, nothing happening, my source is not zipping.

I followed this but didn't work.

My Gradle :

apply plugin: 'com.android.application'


 task myZip(type: Zip) {
     from 'src/main/assets/'
     include '*/*'
     archiveName 'test.zip'
     destinationDir(file('src/main/'))
     println "Zipping Continues... "
}

  android {
     compileSdkVersion 26
     buildToolsVersion "26.0.1"
     defaultConfig {
     applicationId "test.sample.com.myapplication"
     minSdkVersion 15
     targetSdkVersion 26
     versionCode 1
     versionName "1.0"
     testInstrumentationRunner 
     "android.support.test.runner.AndroidJUnitRunner"
   }
   buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
   }
}



dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
       exclude group: 'com.android.support', module: 'support-annotations'
   })
   implementation 'com.android.support:appcompat-v7:26.0.2'
   testImplementation 'junit:junit:4.12'
   implementation 'com.android.support.constraint:constraint-layout:1.0.2'
 }

This is my gradle scripts and please suggest me some solution.

1

There are 1 answers

2
Datow King On

I hit the same issue when I wanted to zip the JNI libs with symbols before publishing them to a private maven feed. It took me some time to figure out the steps as I am not familiar with Gradle. Basically, I solved it by adding an extra step to run the myZip task in the build pipeline:

./gradlew build
./gradlew myZip # extra step to run the myZip task 
./gradlew publish

Here is part of my build.gradle as for reference:

apply plugin: 'maven-publish'

task myZip(type: Zip) {
    archiveName "symbols.zip"
    from "$buildDir/intermediates/transforms/mergeJniLibs"
    destinationDir file("$buildDir/outputs/sym")

    doFirst {
        println "Run myZip task to create symbols.zip"
    }
}

publishing {
    publications {
        symbolsPublication(MavenPublication) {
            ... ...
            artifact file("$buildDir/outputs/sym/symbols.zip")
        }
    }
}

... ...