androidjardx

Keep folders while converting jar to dex


I want to convert my jar to dex: dx --dex --output=file.dex file.jar. In file.jar exists folder cnf/ which contains configuration files needed for my classes. But there is no folder cnf/ in resulting dex-file.

How to keep all files and folders in dex-file while converting?


Solution

  • You can put cnf/ in APK file. APK is a ZIP archive. After unpacking on device cnf/ folder would be in classpath so it should work the same as inside JAR.

    1. After a build remove MANIFEST.MF and certificates from META-INF folder inside APK;

      zip -d file.apk "META-INF/*"
      
    2. Add your resources (cnf/) to APK;

      aapt add -v file.apk cnf/*
      
    3. Re-sign APK. Here's an example using the default debug key:

      jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/.android/debug.keystore file.apk androiddebugkey