When writing the Gradle plug-in, you want to generate the class in the build directory, but after executing task, you cannot use it like the BuildConfig class. how do you solve it?

  android, question

According to the requirements, write a Gradle plug-in to generate files in the build directory, but the path to generate is as follows

The java class generated under the build directory, this file is no way to use ….

图片描述

BuildConfig class file, which can be used directly in code,How do I need to configure it to look like the BuildConfig class??

图片描述

I used this method, but so far it has no effect. …

//~ custom gradlebugin
 def outputDir = project.file(new File(project.buildDir, "generated/source/CConfig"))
 variant.addJavaSourceFoldersToModel(outputDir)

Thank you very much ~

Ingradle pluginYou can useASMTo generate the classes you need, of course, you need to know something about bytecode. There is another way, which I mentioned in your last question, is to use it.APT, this way is similar toJakeWhartonbutterknifeThe method in. I hope it will help you.