栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

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

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

 复制代码 代码如下:
package com.leeass.generate;

import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;


public class GenerateAndroidMakefile {
 
 private static final String LINE_BREAK = System.getProperty("line.separator", "/n");
 
 private File classesDir = null;
 
 private String classesPath = "";
 
 private String classesRelativePath = "";
 
 private BuildFileFilter buildFileFilter = null;

 
 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);
  }
 }
 
 private String translateBuildFilePath(String filepath){
  return filepath.replaceAll("\\", "/").replace(classesPath, classesRelativePath);
 }

 
 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();
 }

 
 
 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"));
  }
 }

}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/164616.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号