1

I'm building an Application which starts a service that uses internal android .jar file located at

/system/framework

The problem is whenever i try to access a class from this .jar file, i get a classDefNotFound exception.

Note: I'm able to compile the project with the stub'd version of the .jar file, but i don't know how to include the internal library in the Application (service) classpath so that i get rid of this exception.

(I'm not using eclipse)

Community
  • 1
  • 1
Ahmad
  • 1,157
  • 8
  • 16
  • Which IDE are you using ? – IanB Aug 07 '13 at 14:03
  • 1
    Intellij, but i don't think this matters or related to the ide anyway, because the library is located at the emulator itself and the classpath of the service is what should be updated ( I guess ) – Ahmad Aug 07 '13 at 14:05

2 Answers2

1

Add to AndroidManifest.xml

<uses-library android:name="com.android.library" />

From Android documentation: http://developer.android.com/guide/topics/manifest/uses-library-element.html

This element tells the system to include the library's code in the class loader for the package.

msh
  • 2,700
  • 1
  • 17
  • 23
  • I used the word "If" to form a valid generic statement. Since I did not downvote your answer, the weight of public opinion would appear to be against you at the moment, but I stand corrected if I am wrong. Isn't it the case that we we are now being discouraged from using uses-library in this way ? – IanB Aug 07 '13 at 16:54
1

I solved the problem as follows:

The files in /system/framework are .jar and .odex the .jar are empty files, the code exists in the .odex files.

I converted the .odex files that i need to .dex files using smali (you'll first need to convert the .odex to .smali files and then to .dex files)

Then i converted the dex files to jar files using the dex2jar

After that i included the generated jar files in the application's apk in order to be able to use them.

I'm writing this to help anyone needed to do that (that's the conclusion of some days of work! )

Community
  • 1
  • 1
Ahmad
  • 1,157
  • 8
  • 16