我怎样才能让Android删除旧的本地库? [英] How can I make android delete old native libraries?

查看:203
本文介绍了我怎样才能让Android删除旧的本地库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的应用程序中删除了一些本地库,因为我不使用他们了,但在我安装APK在我的手机,我可以看到本机库仍然存在。 正如我所看到的,Android的不正确拷贝/更新本机库刚刚通过替换的文件在我的库/目录,但显然它不会删除它们时,他们不是在APK了。 我怎么知道该库仍然存在?那么首先的应用程序的大小保持不变,我删除了一些真正的大图书馆,第二,如果我离开了System.load(...)语句的应用程序仍然能够加载库。

这是我发现了这个问题的唯一解决方案是卸载该应用程序并进行全新安装,但是这不是用于更新从谷歌播放应用程序用户的明显的解决方案,并且是这个问题影响严重我的应用程序的功能

我检查了,显然我可以用我自己删除文件服务创建过程中,说,但我不想惹安装这种方式。

你知道,如果有一种方法来告诉机器人,它需要删除所有的本地库,并再次将其复制?

谢谢, 迈克

我刚刚发现,GB正确更新库,它删除了,现在缺失,因为它应该,但也ICS JB也不做,那两个保留旧.so文件,即使他们不是在APK了

我试图从/数据/数据​​手动删除.so文件/ mypackage的/ lib目录,但它不会让我。

任何想法?

解决方案

好了,所以我放弃了在Android上做到这一点,我不得不做我自己

。我花了一些技巧从这里开始:的http://www.moodstocks.com/2012/03/20/ice-cream-sandwich-why-native-$c$c-support-sucks/.

下面是我所做的:

  1. 擦拭三次zip文件与文件夹库/ armeabi,库/ armeabi-V7A和库/ 86的内容,将它们命名为libs_armeabi.zip,libs_armeabi_v7a.zip和libs_x86.zip respecively。

  2. 将zip文件到RES /原始文件夹。

  3. 删除文件下的三个库文件夹和带有触摸(在-nix系统)重新创建它们,请记住,ICS和JB不删除lib文件夹中的旧文件,所以才删除文件会导致应用程序,以保持那些是相当大的文件。

  4. 编程验证处理器架构,这两种方法:

     公共静态布尔isArmv7(){
        尝试 {
            返回Build.VERSION.SDK_INT> = 4和;&安培; 。Build.class.getField(CPU_ABI)获得(空)的ToString()startsWith(armeabi-V7)。
        }赶上(的Throwable E){}
    
        返回false;
    }
    
    公共静态布尔isX86(){
        尝试 {
            返回Build.VERSION.SDK_INT> = 4和;&安培; 。Build.class.getField(CPU_ABI)获得(空)的ToString()startsWith(86)。
        }赶上(的Throwable E){}
    
        返回false;
    }
     

  5. 根据解压的三个文件的处理器架构编程,以任何你想要的文件夹,我用/数据/数据​​/ mypackage中/ app_libs(使用 context.getDir(库Context.MODE_PRIVATE); 返回路径)

也许会有这里涉及到更多的逻辑,像提取libs_armeabi.zip文件,然后从中提取任何libs_armeabi_v7a.zip或libs_x86.zip或没有人的文件,并覆盖同名文件(我M只是游荡在这里,因为我还没有真正尝试过),幸运的是我,我的库上的三个文件已经改名,并独家在每个压缩文件,所以我只需要提取三个文件。

  1. 替换的System.loadLibrary方法调用System.load支持使用它的完整路径加载库,并添加完整路径,每个库。

此方法带有额外的好处:

  • 由于库压缩的APK大小将减少,使得在谷歌Play商店的应用程序更小。

  • 存储的原始资源的android里面的库不会自动复制它们,让无论你想你将它们复制并使用完整路径加载它们。

  • 您可以决定将库复制到SD卡,如果你愿意,我不会建议,但现在你能够做到这一点,例如,当手机没有足够的空间。

希望这有助于!

I'm trying to delete some native libraries from my application because I don't use them anymore, but after I install the apk in my phone I can see that the native libraries are still there. As I've seen, android does copy/update native libraries correctly just by replacing the file in my libs/ directory, but apparently it doesn't delete them when they're not in the apk anymore. How do I know the libraries are still there? Well first of all the application's size remains the same and I'm deleting some really big libraries, and second, if I leave the System.load(...) statement the app is still able to load the library.

The only solution that I've found for this has been to uninstall the app and make a fresh install, but that's not an obvious solution for a user updating the app from google play, and yes this problem affects severely my app functionality.

I've checked and apparently I can delete the files by my self, say during a service creation, but I don't want to mess with the installation this way.

Do you know if there's a way to tell Android that it needs to delete all the native libraries and copy them again?

Thanks, Mike

[EDIT]

I've just found that GB updates the libraries correctly, it deletes the now-missing as it should, but neither ICS nor JB do, those two leave the old .so files even when they're not in the apk anymore.

I tried deleting the .so files manually from /data/data/mypackage/lib but it won't let me.

Any ideas?

解决方案

Ok, so I gave up on android to do this and I had to do it myself. I took some tips from here: http://www.moodstocks.com/2012/03/20/ice-cream-sandwich-why-native-code-support-sucks/.

Here's what I did:

  1. Make three zip files with the contents of the folders libs/armeabi, libs/armeabi-v7a and libs/x86 and named them libs_armeabi.zip, libs_armeabi_v7a.zip and libs_x86.zip respecively.

  2. Move the zip files to the res/raw folder.

  3. Delete the files under the three libs folders and re-create them with touch (in a -nix system), remember that ICS and JB don't delete the old files in the lib folder, so just deleting the files would cause the app to keep those files which are quite large.

  4. Verify the processor architecture programmatically with these two methods:

    public static boolean isArmv7() {
        try {
            return Build.VERSION.SDK_INT >= 4 && Build.class.getField("CPU_ABI").get(null).toString().startsWith("armeabi-v7");
        } catch (Throwable e) {}
    
        return false;
    }
    
    public static boolean isX86() {
        try {
            return Build.VERSION.SDK_INT >= 4 && Build.class.getField("CPU_ABI").get(null).toString().startsWith("x86");
        } catch (Throwable e) {}
    
        return false;
    }
    

  5. Depending on the processor architecture unzip one of the three files programmatically to any folder you want, I'm using /data/data/myPackage/app_libs (using context.getDir("libs",Context.MODE_PRIVATE); returns that path).

Probably there would be more logic involved here, something like extracting the libs_armeabi.zip file, and then extract the files from either libs_armeabi_v7a.zip or libs_x86.zip or none of them, overwriting the files that have the same name (I'm just wandering here because I haven't actually tried that), fortunately for me my libs on the three files were already renamed and are exclusive on each zip file, so I just need to extract one of the three files.

  1. Replace the System.loadLibrary method calls to System.load which supports loading the libraries using its full path, and add the full path for each library.

This method comes with added benefits:

  • As the libraries are zipped the apk size will be reduced, making the application in the google play store smaller.

  • Being the libraries stored inside the raw resources android won't copy them automatically, allowing you to copy them wherever you want and load them using a full path.

  • You can decide to copy the libraries to the sd card if you want, I wouldn't recommend that but now you're able to do it, for example when the phone doesn't have enough space.

Hope this helps!

这篇关于我怎样才能让Android删除旧的本地库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆