Java.lang.RuntimeException: Unable to instantiate com.google.android.gcm.GCMBroadCastReceiver

I am developing an android application.

I am implementing push notification using GCM.

However, I am unable to receive push notification from my server. The error log is shown below.

java.lang.RuntimeException: Unable to instantiate service
com.google.android.gcm.GCMBroadCastReceiver: java.lang.ClassNotFoundException: 
Didn't find class "com.google.android.gcm.GCMBroadCastReceiver" on path: DexPathList

      

AndroidManifest.xml below.

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

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="net.myapp.permission.RECEIVE" />

    <permission
        android:name="net.myapp.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="net.myapp.permission.C2D_MESSAGE" />

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

    <application
        android:name="net.myapp.sub.AppController"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />

        <activity
            android:name="net.myapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="net.myapp.DetailActivity"
            android:uiOptions="splitActionBarWhenNarrow" >
            <meta-data
                android:name="android.support.UI_OPTIONS"
                android:value="splitActionBarWhenNarrow" />

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="twittercallback" />
            </intent-filter>
        </activity>

        <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="net.myapp" />
            </intent-filter>
        </receiver>

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

    </application>

</manifest>

      

GcmBroadcastReceiver.java below.

package net.myapp;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        ComponentName comp = new ComponentName(context.getPackageName(),
                 GcmIntentService.class.getName());

        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }

}

      

I confirm that I am importing android-support-v4.jar and google-play-services.jar correctly. I tried some solutions from Google Search but can't solve it yet.

Could you please tell me how to solve the above problem?

+3


source to share


1 answer


In the Manifest, you wrote:

android:name="com.google.android.gcm.GCMBroadcastReceiver"

      



But yours GcmBroadcastReceiver.java

is in the packagenet.myapp

Change android:name="com.google.android.gcm.GCMBroadcastReceiver"

toandroid:name="net.myapp.GcmBroadcastReceiver"

+1


source







All Articles