this some way of setting apk file path at runtime
`TestsDemo.java
public class TestsDemo extends Cocos2dxActivity{ static final String packageName = "org.cocos2dx.tests"; protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); String apkFilePath = ""; ApplicationInfo appInfo = null; PackageManager packMgmr = getApplication().getPackageManager(); try { appInfo = packMgmr.getApplicationInfo(packageName, 0); } catch (NameNotFoundException e) { e.printStackTrace(); throw new RuntimeException("Unable to locate assets, aborting..."); } apkFilePath = appInfo.sourceDir; Log.w("apk path", apkFilePath); String storagePath = ""; storagePath = Environment.getExternalStorageDirectory().getAbsolutePath(); storagePath = storagePath.concat(String.format("/%s", packageName)); File f = new File(storagePath); f.mkdirs(); // add this link at the renderer class Cocos2dxRenderer.nativeSetPaths(apkFilePath, storagePath); mGLView = new Cocos2dxGLSurfaceView(this); setContentView(mGLView); }
`jni/test.cpp
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeSetPaths(JNIEnv* env, jobject thiz, jstring apkPath, jstring storagePath)
{
const char* str;
jboolean isCopy;
str = env->GetStringUTFChars(apkPath, &isCopy);
if (isCopy) {
CCFileUtils::setResourcePath(str);
env->ReleaseStringUTFChars(apkPath, str);
}
str = env->GetStringUTFChars(storagePath, &isCopy);
if (isCopy) {
// save storagePath CCFileUtils::??
env->ReleaseStringUTFChars(storagePath, str);
}
}