1

I have a project that is divided in two: a base code module and an app specific code module.

I'm trying to use GCMIntentService but having this error when the app starts running:

03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint 

E/AndroidRuntime: FATAL EXCEPTION: main
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime: Process: br.com.brainweb.brainfeed.milkpoint, PID: 19281
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime: java.lang.RuntimeException: Unable to instantiate service br.com.brainweb.brainfeed.milkpoint.GCMIntentService: java.lang.ClassNotFoundException: Didn't find class "br.com.brainweb.brainfeed.milkpoint.GCMIntentService" on path: DexPathList[[zip file "/data/app/br.com.brainweb.brainfeed.milkpoint-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2746)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread.access$1800(ActivityThread.java:148)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5310)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  Caused by: java.lang.ClassNotFoundException: Didn't find class "br.com.brainweb.brainfeed.milkpoint.GCMIntentService" on path: DexPathList[[zip file "/data/app/br.com.brainweb.brainfeed.milkpoint-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2743)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread.access$1800(ActivityThread.java:148) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5310) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696) 
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:    Suppressed: java.lang.ClassNotFoundException: br.com.brainweb.brainfeed.milkpoint.GCMIntentService
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.Class.classForName(Native Method)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:            ... 11 more
03-08 11:23:47.454 19281-19281/br.com.brainweb.brainfeed.milkpoint E/AndroidRuntime:  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

For the description of the error, the class can't be found. I've read that there must be a GCMIntentService class in the same package as the app.

So here is my app's manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.brainweb.brainfeed.milkpoint"
    android:versionCode="5"
    android:versionName="2.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <permission
        android:name="br.com.brainweb.brainfeed.milkpoint.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="br.com.brainweb.brainfeed.milkpoint.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:name="br.com.brainweb.brainfeed.Aplicacao"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="br.com.brainweb.brainfeed.milkpoint" />
            </intent-filter>
        </receiver>

        <service android:name=".GCMIntentService" />

        <activity
            android:name="br.com.brainweb.brainfeed.SplashScreen"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="br.com.brainweb.brainfeed.MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity
            android:name="br.com.brainweb.brainfeed.ItemViewActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar" />
        <activity
            android:name="br.com.brainweb.brainfeed.InfoActivity"
            android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

        <service android:name="org.OpenUDID.OpenUDID_service" >
            <intent-filter>
                <action android:name="org.OpenUDID.GETUDID" />
            </intent-filter>
        </service>
    </application>

</manifest>

There actually is a GCMIntentService class in the package, and when I put a breakpoint in getDefaultIntentServiceClassName method of GCMBroadcastReceiver class, the path string to the class seems correct. Still I get this error.

I have already tried lots of solutions here at Stack Overflow, but still none of them seemed to fix it.

Gustavo Amgarten
  • 396
  • 4
  • 20
  • Hey @Gustavo, possible duplicate question kindly refer to this [link](http://stackoverflow.com/questions/35843278/link-of-class-lcom-google-android-gms-gcm-gcmreceiver-failed) – Mr.Rebot Mar 09 '16 at 05:23

1 Answers1

0

After a lot of time into it, I finally found a solution.

This is how part of my build.gradle was:

android {
    compileSdkVersion 18
    buildToolsVersion "21.1.2"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src\\main\\java','src\\test\\java'] // Line 1
            resources.srcDirs = ['src\\main\\java','src\\test\\java'] // Line 2
            aidl.srcDirs = ['src\\main\\java','src\\test\\java']
            renderscript.srcDirs = ['src\\main\\java','src\\test\\java']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }
}

My GCMIntentService package was inside src/main/java. I deleted the folders main/java and put the package inside src.

Then I changed Line 1 and Line 2 as shown above, like this:

java.srcDirs = ['src'] // Line 1
resources.srcDirs = ['src'] // Line 2

And it started working.

Gustavo Amgarten
  • 396
  • 4
  • 20