SoFunction
Updated on 2025-03-10

Used to generate compiled file list for Android projects in cocos2d-x engine (ndk)

/**
* Used for Android project compiled file list generation in cocos2d-x engine
 * @author leeassamite
 *
 */
public class GenerateAndroidMakefile {
/** Delimiter */
 private static final String LINE_BREAK = ("", "/n");
/** classes folder */
 private File classesDir = null;
/** classes folder path */
 private String classesPath = "";
/** classes folder relative path */
 private String classesRelativePath = "";
/** Compile file filter */
 private BuildFileFilter buildFileFilter = null;

 /**
* Create GenerateAndroidMakefile
* @param classesAbsolutePath classes folder absolute path
* @param classesRelativePath relative path of the classes folder in the compiled file
  * @throws Exception
  */
 public GenerateAndroidMakefile(String classesAbsolutePath,String classesRelativePath) throws Exception{
  if(classesRelativePath == null){
throw new Exception("classes folder relative path error, cannot be NULL!");
  }
  if(classesAbsolutePath == null || "".equals(classesAbsolutePath)){
throw new Exception("classes folder path input error, cannot be empty!");
  }
  classesDir = new File(classesAbsolutePath);
  if((!()) || (!()) || (!())){
throw new FileNotFoundException("classes folder is not readable:"+());
  }
   = classesAbsolutePath;
   = ("\\\\", "/");
   = classesRelativePath;
  buildFileFilter = new BuildFileFilter();
 }

 /**
* Output compiled file list
  */
 public void outputBuildFilesList(){
  StringBuilder buildFilesSb = new StringBuilder();
  outputBuildFileList(classesDir,buildFilesSb);
  (());
 }
 private void outputBuildFileList(File buildfile,StringBuilder buildFilesSb){
  if(()){
   File[] files =(buildFileFilter);
   for (File file : files) {
    outputBuildFileList(file,buildFilesSb);
   }
  }else{
   String buildfileStr = translateBuildFilePath(()) + " \\";
   (buildfileStr).append(LINE_BREAK);
  }
 }
 /**
* Convert the compiled file path
  * @param filepath
  * @return
  */
 private String translateBuildFilePath(String filepath){
  return ("\\\\", "/").replace(classesPath, classesRelativePath);
 }

 /**
  * @param args
  * @throws FileNotFoundException
  */
 public static void main(String[] args) throws Exception {
  String classesPath = "D:\\developer\\cocos2d-x-2.1.4\\projects\\hszg_ol\\Classes";
  String relativePath = "                   ../../Classes";
  GenerateAndroidMakefile gam = new GenerateAndroidMakefile(classesPath,relativePath);
  ();
 }

 
 /**
* Compile file filter
  * @author leeass
  *
  */
 class BuildFileFilter implements FileFilter{
  @Override
  public boolean accept(File pathname) {
   String name = ().toLowerCase();
   return (!()) && (() || (".c") || (".cpp"));
  }
 }