Rename a directory while copying using Gradle

I am using gradle to create an android application. I copy several files and folders to the resource folder. I ran into a problem that some files may have a file name that is too long, as well as folders (aapt cannot handle file names longer than 100 characters).

Therefore, I rename the files during the copy operation as follows:

copy { from('A') into('B') rename ('too-long-filename', 'shorter-filename') rename ('too-long-directoryname', 'shorter-directoryname') } 

However, this works fine for files, but does not work for directories. Is there a special command to achieve renaming while copying using gradle?

The error says:

Error code: 1 Output: /home/curiosity/AndroidStudioProjects/App/build/..if directory names are too long .. /: error: invalid directory name, could not be added.

+6
source share
1 answer

You can try visiting FileTree, but you need to save directories, you cannot change them while going through. And if you just want to shorten the name, perhaps you can use the groovy long [0 ..- 10] notation long name

Sort of:

 def dirs = [] fileTree("./longdirectoryname").visit { FileVisitDetails details -> if (!details.isDirectory()) { // rename } else { dirs.add(details.file) } } dirs.each { // rename directories here } 
0
source

Source: https://habr.com/ru/post/986076/


All Articles