apk file path

apk file path
0.0 0


this some way of setting apk file path at runtime


public class TestsDemo extends Cocos2dxActivity{

    static final String packageName = "org.cocos2dx.tests";

    protected void onCreate(Bundle savedInstanceState){

        String apkFilePath = "";
        ApplicationInfo appInfo = null;
        PackageManager packMgmr = getApplication().getPackageManager();
        try {
            appInfo = packMgmr.getApplicationInfo(packageName, 0);
        } catch (NameNotFoundException e) {
            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);

        // add this link at the renderer class
        Cocos2dxRenderer.nativeSetPaths(apkFilePath, storagePath);

        mGLView = new Cocos2dxGLSurfaceView(this);


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) {
            env->ReleaseStringUTFChars(apkPath, str);

        str = env->GetStringUTFChars(storagePath, &isCopy);
        if (isCopy) {
            // save storagePath CCFileUtils::??
            env->ReleaseStringUTFChars(storagePath, str);


When an application is installed from app store, it is installed in /data/app-private. As I know getInstalledApplications() can not find installed applications in app-private. Can getApplicationInfo(packageName, 0) find it?


it can find the path even without special permissions.
i’ve used the method above in three games in the android market already.

i only got the method above from a contribution anddev.org.

by the way, looks like ndk-r5 has some api that can access the files directly from apk.
sound & input also now accessible from native ndk.

File.mkdirs < would need special permissions in the manifest WRITETOSTORAGE - or something


Thank you.
I will add it to the org.cocos2dx.lib, and use it in the sample.