Created
March 18, 2014 16:21
-
-
Save junaidk/9623534 to your computer and use it in GitHub Desktop.
automatically creates android.mk file for cocos2dx project with all `classes` in classes dir. Run it in proj.android/jni director. Tested for cocos2dx versions 2.x.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.BufferedWriter; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
public class androidmk { | |
/** | |
* @param args | |
*/ | |
String before = "LOCAL_PATH := $(call my-dir) \n\ninclude $(CLEAR_VARS) \n\nLOCAL_MODULE := cocos2dcpp_shared" + | |
"\n\nLOCAL_MODULE_FILENAME := libcocos2dcpp\n\n"; | |
String classes = "LOCAL_SRC_FILES := hellocpp/main.cpp \\\n"; | |
String after = "\n\n\nLOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes\n\n"+ | |
"LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static\n"+ | |
"LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static\n"+ | |
"LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static\n"+ | |
"LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static\n"+ | |
"LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static\n\n"+ | |
"include $(BUILD_SHARED_LIBRARY)\n\n"+ | |
"$(call import-module,cocos2dx)\n"+ | |
"$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)\n"+ | |
"$(call import-module,CocosDenshion/android)\n"+ | |
"$(call import-module,extensions)\n"+ | |
"$(call import-module,external/Box2D)\n"+ | |
"$(call import-module,external/chipmunk)\n"; | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
// rename the Android.mk file to Android_BAK.mk | |
File oldfile =new File(System.getProperty("user.dir")+"/Android.mk"); | |
File newfile =new File(System.getProperty("user.dir")+"/Android_BAK.mk"); | |
try{ | |
if(oldfile.renameTo(newfile)){ | |
System.out.println("Rename succesful"); | |
}else{ | |
System.out.println("Rename failed"); | |
} | |
}catch (Exception et) { | |
et.printStackTrace(); | |
} | |
System.out.println("Current dir : "+System.getProperty("user.dir")); | |
androidmk runner = new androidmk(); | |
String path; | |
Path currentRelativePath = Paths.get(System.getProperty("user.dir")); | |
currentRelativePath = currentRelativePath.getParent().getParent(); | |
String s = currentRelativePath.toAbsolutePath().toString(); | |
path = s +"\\Classes"; | |
System.out.println("Path to Classes : " + path); | |
// making new Android.mk file | |
String classConcat = runner.readFilesFromDir(path,runner.classes); | |
try { | |
String content = ""; | |
content = runner.before + classConcat + runner.after; | |
File file = new File(System.getProperty("user.dir")+"/Android.mk"); | |
// if file doesnt exists, then create it | |
if (!file.exists()) { | |
file.createNewFile(); | |
} | |
FileWriter fw = new FileWriter(file.getAbsoluteFile()); | |
BufferedWriter bw = new BufferedWriter(fw); | |
bw.write(content); | |
bw.close(); | |
System.out.println("Done"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
public String readFilesFromDir(String path, String classesStart){ | |
File folder = new File(path); | |
File[] listOfFiles = folder.listFiles(); | |
String returnStr=""; | |
for (int i = 0; i < listOfFiles.length; i++) { | |
if (listOfFiles[i].isFile()) { | |
String fileName = listOfFiles[i].getName(); | |
if (fileName.split("\\.")[1].equals("cpp")){ | |
System.out.println("File " + listOfFiles[i].getName()); | |
returnStr += "\t\t\t../../Classes/" + listOfFiles[i].getName() + " \\\n"; | |
} | |
} else if (listOfFiles[i].isDirectory()) { | |
System.out.println("Directory " + listOfFiles[i].getName()); | |
} | |
} | |
return classesStart + returnStr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment