欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

用于cocos2d-x引擎(ndk)中为android项目生成编译文件列表

程序员文章站 2022-06-04 12:23:04
 复制代码 代码如下:package com.leeass.generate; import java.io.file;import java.io.filef...

 

复制代码 代码如下:

package com.leeass.generate;

import java.io.file;
import java.io.filefilter;
import java.io.filenotfoundexception;

/**
 * 用于cocos2d-x引擎中android项目编译文件列表生成
 * @author leeassamite
 *
 */
public class generateandroidmakefile {
 /** 分隔符 */
 private static final string line_break = system.getproperty("line.separator", "/n");
 /** classes文件夹 */
 private file classesdir = null;
 /** classes文件夹路径 */
 private string classespath = "";
 /** classes文件夹相对路径 */
 private string classesrelativepath = "";
 /** 编译文件过滤器 */
 private buildfilefilter buildfilefilter = null;

 /**
  * 创建generateandroidmakefile
  * @param classesabsolutepath classes文件夹绝对路径
  * @param classesrelativepath classes文件夹在编译文件中的相对路径
  * @throws exception
  */
 public generateandroidmakefile(string classesabsolutepath,string classesrelativepath) throws exception{
  if(classesrelativepath == null){
   throw new exception("classes文件夹相对路径错误,不能为null!");
  }
  if(classesabsolutepath == null || "".equals(classesabsolutepath)){
   throw new exception("classes文件夹路径输入错误,不能为空!");
  }
  classesdir = new file(classesabsolutepath);
  if((!classesdir.exists()) || (!classesdir.canread()) || (!classesdir.isdirectory())){
   throw new filenotfoundexception("classes文件夹不可读:"+classesdir.getabsolutepath());
  }
  this.classespath = classesabsolutepath;
  this.classespath = classesabsolutepath.replaceall("\\\\", "/");
  this.classesrelativepath = classesrelativepath;
  buildfilefilter = new buildfilefilter();
 }

 /**
  * 输出编译文件列表
  */
 public void outputbuildfileslist(){
  stringbuilder buildfilessb = new stringbuilder();
  outputbuildfilelist(classesdir,buildfilessb);
  system.out.println(buildfilessb.tostring());
 }
 private void outputbuildfilelist(file buildfile,stringbuilder buildfilessb){
  if(buildfile.isdirectory()){
   file[] files =buildfile.listfiles(buildfilefilter);
   for (file file : files) {
    outputbuildfilelist(file,buildfilessb);
   }
  }else{
   string buildfilestr = translatebuildfilepath(buildfile.getabsolutepath()) + " \\";
   buildfilessb.append(buildfilestr).append(line_break);
  }
 }
 /**
  * 转换编译文件路径
  * @param filepath
  * @return
  */
 private string translatebuildfilepath(string filepath){
  return filepath.replaceall("\\\\", "/").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);
  gam.outputbuildfileslist();
 }

 
 /**
  * 编译文件过滤器
  * @author leeass
  *
  */
 class buildfilefilter implements filefilter{
  @override
  public boolean accept(file pathname) {
   string name = pathname.getname().tolowercase();
   return (!pathname.ishidden()) && (pathname.isdirectory() || name.endswith(".c") || name.endswith(".cpp"));
  }
 }

}



用于cocos2d-x引擎(ndk)中为android项目生成编译文件列表