3

I've read about a hundred problems of the same category, but none helped. I had a working application, then refactored the package name, and it compiled and ran. A week later I come back to work on it and get the ClassNotFoundException on launch. Worse yet, if I checkout a previous commit from the repo (one before any refactoring, where everything worked) that project raises the same error on launch (except with a different package name).

I've tried everything I can think of and I don't know how to track the problem down. I have done the obvious things: clean the project, delete it entirely and re-add it, run on a fresh device...

I'm not sure what code would be helpful to debug, but here's the declaration in my manifest and the logcat output. If something else might be useful let me know. I'm really lost here.

Crash:

E/AndroidRuntime(  515): FATAL EXCEPTION: main
E/AndroidRuntime(  515): java.lang.RuntimeException: Unable to instantiate service
co.mosic.mosic.CommunicationService: java.lang.ClassNotFoundException: co.mosic.mosic.CommunicationService
E/AndroidRuntime(  515):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2237)
E/AndroidRuntime(  515):    at android.app.ActivityThread.access$1600(ActivityThread.java:123)
E/AndroidRuntime(  515):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
E/AndroidRuntime(  515):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  515):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(  515):    at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(  515):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  515):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(  515):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(  515):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(  515):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  515): Caused by: java.lang.ClassNotFoundException: co.mosic.mosic.CommunicationService
E/AndroidRuntime(  515):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime(  515):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(  515):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(  515):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2234)
E/AndroidRuntime(  515):    ... 10 more

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="co.mosic.mosic"
    android:versionCode="1"
    android:versionName="1.0" >

...

<service 
    android:name=".CommunicationService" >
    <intent-filter>
        <action android:name="co.mosic.mosic.MStcServiceInet" /> 
    </intent-filter>
</service>
jarvisteve
  • 926
  • 8
  • 14
  • It's fixed! I'm really not sure how though. The final thing that fixed it was changing my "lib" folder to "libs", but it was named "lib" previously. I did change my Java compiler recently too, but can't remember the exact timeframe. Maybe it's pickier about the jar's folder name? Really I just spent a few more hours smashing around refactoring, cleaning, rebuilding... – jarvisteve May 13 '12 at 05:19
  • Yes I think `libs` is the right name for `ant` scripts. –  May 15 '12 at 09:49

2 Answers2

4

Due to a recent update of the ADT plugin the library folder had to be changed to "libs" instead of lib. I came across it several times recently.

Verbeia
  • 4,400
  • 2
  • 23
  • 44
BossOss
  • 66
  • 4
0

Of the top of my head, the most common cause for this type of error is missing proguard.flags file.

Proguard will run on your code and obfuscate all names. If you have not specified a -keep flag for your service class, its name will be changed as well, and thus the OS won't be able to find it.

So my guess would be that you forgot to commit the proper proguard configuration file, which would explain why it used to work but doesn't now.

Franci Penov
  • 74,861
  • 18
  • 132
  • 169
  • 1
    Thanks, that was a great idea. It didn't fix the problem though, I tried `-keep public class CommunicationService` and `-keep public class co.mosic.mosic.CommunicationService`. – jarvisteve May 13 '12 at 04:12