1

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.

Anshuman Pattnaik
  • 883
  • 3
  • 16
  • 37
  • Possible duplicate of https://stackoverflow.com/questions/36863456/gradle-task-to-create-a-zip-archive-of-a-directory – AlexTa Aug 31 '17 at 16:32
  • Yes, i tried this but it didn't work, please help me out – Anshuman Pattnaik Aug 31 '17 at 16:34
  • Possible duplicate of [Gradle task to create a zip archive of a directory](https://stackoverflow.com/questions/36863456/gradle-task-to-create-a-zip-archive-of-a-directory) – AlexTa Aug 31 '17 at 16:34
  • Yes man, i tried this but didn't work, can you please suggest me some solution. – Anshuman Pattnaik Aug 31 '17 at 16:38
  • The solution of the above-mentioned question worked for me. But maybe you need to actually trigger your task myZip and not only do a Gradle refresh? Cause I needed to trigger my zip task manually. – Thor_Bux Mar 26 '18 at 21:52

1 Answers1

1

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")
        }
    }
}

... ...
Datow King
  • 161
  • 5
  • 11
  • Saved my day. Thanks for sharing! – dudi Dec 27 '19 at 07:28
  • archiveName "symbols.zip" and destinationDir file("$buildDir/outputs/sym") are deprecated and should be replaced with archiveFileName = "symbols.zip" destinationDirectory = file("$buildDir/outputs/sym") – dudi Dec 27 '19 at 07:32