无法实例化GcmBroadcastReceiver

 双子宝贝鱼 发布于 2023-02-13 14:15

根据Google手册https://developer.android.com/google/gcm/client.html#app,我尝试使用GCM服务创建测试应用

但是当我收到消息时 - 我有这个错误:

无法实例化接收机com.example.testpushnotification.GcmBroadcastReceiver:抛出java.lang.ClassNotFoundException:没有找到路径类 "com.example.testpushnotification.GcmBroadcastReceiver":DexPathList [zip文件"/data/app/com.example. testpushnotification-2.apk"],nativeLibraryDirectories = [/数据/ APP-LIB/com.example.testpushnotification-2,/销售商/ lib下,/系统/ lib中]]

我正在寻找所有相同的问题,但他们没有解决方案或解决方案没有帮助或他们被弃用.

我的清单:









  
 













     

    
        
            

            
        
    
    
        
            
            
            
        
    
    

以及com.example.testpushnotification包中GcmBroadcastReceiver的源代码:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Explicitly specify that GcmIntentService will handle the intent.
        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());
        // Start the service, keeping the device awake while it is launching.
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }

为什么Dex路径包含不同于我的包?

请问,如何解决?

固定已更改

(案例判断)

1 个回答
  • 试试这个:

    转到项目/属性/ Java构建路径/订单和导出 - 确保在Android Dependencies和支持库前面有一个检查,如果您使用它.标记所有复选框.单击应用并清理项目.

    像这样添加:

       <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="com.test.android" />
            </intent-filter>
        </receiver>
    

    它应该是:com.google.android.gcm.GCMBroadcastReceiver而不是.GCMBroadcastReceiver

    这对我有用.希望这有帮助.

    2023-02-13 14:18 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有