accessing to classes of app from dex file by classloader

后端 未结 3 626
南笙
南笙 2021-02-06 16:13

I have a app that recieve a dex file from server then save it on sdcard and load it for

doing some functions.I am loading a my app\'s class from my dex file as followi

3条回答
  •  迷失自我
    2021-02-06 16:56

    See if you're following these steps.

    1. Do you have the library file as an APK or a JAR containing (Classes.dex) file on the SD Card?
    2. Copy the APK file into a temporary folder into your application director /data/data/your.app.name/tmp. This is important as for security reasons Android doesn't let you load something off the SD card.
    3. Use DexClassLoader as described here -> How to load a Java class dynamically on android/dalvik?
    4. Use this classloader instance for loading any dynamic class files.

    If you have more than 1 JAR files then merge them into a single DEX file/APK.

    To convert your Java JAR file or classes into DEX you need to use the Android SDK's dx.bat. Here's a sample ANT script to do. This can also be done via Command line too with similar arguments.

    
        
        
        
        
    
    

提交回复
热议问题