用于cocos2d-x引擎(ndk)中為android項目生成編譯文件列表
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;
/**
* 創(chuàng)建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);
}
}
/**
* 轉(zhuǎn)換編譯文件路徑
* @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"));
}
}
}
相關(guān)文章
android中關(guān)于call撥號功能的實現(xiàn)方法
這篇文章主要介紹了android中關(guān)于call撥號功能實現(xiàn)的記錄,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05
Android中Listview下拉刷新和上拉加載更多的多種實現(xiàn)方案
本文大概通過三種方案給大家介紹了Android中Listview下拉刷新和上拉加載更多知識,非常不錯,具有參考借鑒價值,需要的朋友參考下2016-12-12
Android 實現(xiàn)夜間模式的快速簡單方法實例詳解
這篇文章主要介紹了Android 實現(xiàn)夜間模式的快速簡單方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
Android 動態(tài)改變SeekBar進度條顏色與滑塊顏色的實例代碼
在上次android開發(fā)的項目中遇到個這樣的需求,要動態(tài)改變seekbar進度條顏色與滑塊顏色的需求,實現(xiàn)代碼也算比較簡單,對實現(xiàn)過程感興趣的朋友可以通過本文學(xué)習(xí)下2016-11-11
Android?studio實現(xiàn)動態(tài)背景頁面
這篇文章主要為大家詳細介紹了Android?studio實現(xiàn)動態(tài)背景頁面,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04
Android學(xué)習(xí)之Broadcast的簡單使用
這篇文章主要為大家詳細介紹了Android學(xué)習(xí)之Broadcast的簡單使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08

