0

I have an Android Studio project which uses NDK and CMake and externalNativeBuild. To reduce packet size I have several flavors for different texture compression formats. There are no code changes, i.e. all the resulting APKs are using exactly the same code.

productFlavors {
        ETC2 {
            manifestPlaceholders = [supportedTexture: "GL_OES_compressed_ETC2_RGB8_texture"]
        }
        DXT {
            manifestPlaceholders = [supportedTexture: "GL_EXT_texture_compression_dxt1"]
        }
        ATC {
            manifestPlaceholders = [supportedTexture: "GL_AMD_compressed_ATC_texture"]
        }
        //...and list goes on...
 }

What this means in practice is that I have a Copy task which checks the current flavor and copies the correct texture pack into the APK. The getCurrentFlavor() function is copied from How to get current flavor in gradle:

task copyTexSD(type: Copy) {
    def currentFlavor = getCurrentFlavor()
    if(currentFlavor == "etc2") {
        from 'bin/tex/ETC2.bin'
    }
    else if(currentFlavor == "dxt") {
        from 'bin/tex/DXT.bin'
    }
    else if(currentFlavor == "atc") {
        from 'bin/tex/ATC.bin'
    }
    //...
    into 'src/main/assets/tex'
}

To build averything I use the following batch command:

call gradlew clean 
call gradlew assembleETC2Release 
call gradlew assembleDXTRelease
call gradlew assembleATCRelease

This works otherwise well, but for some reason the texture packets which are copied to previous APKs are also included in the subsequent APKs like this:

  • app-ETC2-release.apk contains only ETC2.bin file
  • app-DXT-release.apk contains DXT.bin and ETC2.bin
  • app-ATC-release.apk contains ATC.bin, DXT.bin and ETC2.bin

Why the build process includes assets from previous Gradle task? How can I make the build process to have only one texture file per APK?

DavidPostill
  • 7,734
  • 9
  • 41
  • 60
Scam
  • 552
  • 5
  • 21

1 Answers1

0

Somehow I had a wrong assumption that each gradle task would be independent. Of course all the file(s) that have been copied in the assets folder in previous tasks are still there if they are not explicitly deleted.

So, there seems to be two possibilities to get this to work:

1) Modify the batch file to delete data from the texture folder before calling next gradle task.

OR

2) Create delete task in gradle file which runs before copy task. Examples can be found here: Gradle - Delete files with certain extension .

Scam
  • 552
  • 5
  • 21