1

我正在尝试使用 gradle 压缩一个 android 源,但我的 gradle 任务没有做任何事情。完成 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'
 }

这是我的 gradle 脚本,请建议我一些解决方案。

4

1 回答 1

1

当我想在将 JNI 库发布到私有 Maven 提要之前用符号压缩它们时,我遇到了同样的问题。由于我不熟悉 Gradle,我花了一些时间才弄清楚这些步骤。基本上,我通过在构建管道中添加一个额外的步骤来运行 myZip 任务来解决它:

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

这是我的 build.gradle 的一部分供参考:

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

... ...
于 2019-05-18T23:29:07.030 回答