Add Suffix relative to buildTypes or platforms for native builds

Thanks for the question Astraya. What you are asking should be simple to do and we will work on improving this scenario. That been said here is a solution for the time been.

First lets start by identifying where your solution fall short. The property baseName doesn’t exist on NativeLibraryBinarySpec. Because of groovy delegation strategy, the baseName you are actually accessing is the one from the NativeComponentSpec (base class of NativeLibrarySpec). Since the configuration has already happy by the time your binary.all closure execute the code has no effect.

At the present time, the solution is:

apply plugin: 'cpp' 
 
File appendDebugSuffix(File binaryFile) { 
  int extensionSeparatorIndex = binaryFile.path.lastIndexOf('.') 
  return new File(binaryFile.path.substring(0, extensionSeparatorIndex) + "_d" + binaryFile.path.substring(extensionSeparatorIndex)) 
} 
 
model { 
  buildTypes { 
    Debug 
  } 
  components { 
    Core(NativeLibrarySpec) { 
      binaries.withType(NativeLibraryBinarySpec) { 
        if(buildType == buildTypes.Debug) { 
          if (it instanceof SharedLibraryBinarySpec) { 
            sharedLibraryFile = appendDebugSuffix(sharedLibraryFile) 
            sharedLibraryLinkFile = appendDebugSuffix(sharedLibraryLinkFile) 
          } else if (it instanceof StaticLibraryBinarySpec) { 
            staticLibraryFile = appendDebugSuffix(staticLibraryFile) 
          } else { 
            throw new GradleException("Unknown native library binary") 
          } 
        } 
      } 
    } 
  } 
} 

Basically, you need to modify directly the path for the ouput files of each binary you wish to modify. Unfortunately, each binary have various naming scheme for these output files. We use appendDebugSuffix function to localize the code logic. You can also use Apache commons-io FilenameUtils class if you want to cut down on custom logic.

Don’t hesitate to ask more question!